gpt4 book ai didi

java - 尝试使用 Jersey Client API 执行 POST 请求时出现“已连接”异常

转载 作者:太空狗 更新时间:2023-10-29 22:38:13 26 4
gpt4 key购买 nike

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

我正在尝试执行这样的 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 :)谢谢

最佳答案

可能是 java.lang.IllegalStateException: Already connected 只屏蔽了 SSLHandshakeException。请看issue #3000 (以前称为 JERSEY-2728 错误)。

关于java - 尝试使用 Jersey Client API 执行 POST 请求时出现“已连接”异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28951667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com