“已连接”异常尝试使用泽西客户端 API 执行 POST 请求

2022-09-01 18:48:26

我正在使用arquillian为部署在Tomcat 8上的JAX-RS / Jersey Webservice创建集成测试。

我正在尝试做一个这样的POST请求:

E dummy = dummyFactory.manufacturePojo(getSubClassType());
dummy.setId(null);

Client client = ClientBuilder.newClient();
WebTarget target = client.target(BASE_URI).path("bandeira");

Response response = target.request(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, CHAVE_TESTE)
            .header(HttpHeaders.CONTENT_TYPE, "application/json")
            .post(Entity.entity(dummy, MediaType.APPLICATION_JSON));

当我这样做时,我得到这个例外:

Caused by: java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3000)
at org.glassfish.jersey.client.HttpUrlConnector.setOutboundHeaders(HttpUrlConnector.java:364)
at org.glassfish.jersey.client.HttpUrlConnector.access$100(HttpUrlConnector.java:91)
at org.glassfish.jersey.client.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:327)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:201)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:195)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:263)
at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:816)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:546)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:331)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:243)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
... 149 more

我可以使用一些启发式方法,因为我仍在学习arquillian和Jersey客户端API:)谢谢


答案 1

可能只是掩盖了 .请看一下问题 #3000(以前称为 JERSEY-2728 错误)。java.lang.IllegalStateException: Already connectedSSLHandshakeException


答案 2

这可能是由于网络连接问题。自从我的VPN失去连接以来,我遇到了这个问题。在 jackson 序列化邮件正文期间报告了带有 “” 的异常。(我导入了泽西岛和杰克逊-贾克斯-基的源代码进行调试)。在我删除了邮件正文后,出现了新的异常,错误为“”。Already connectedUnknown hostname

登录VPN后,一切正常。

我对泽西岛客户例外感到非常不高兴“,这给我带来了困惑。"Already connected


推荐