尝试使用Jersey Client API执行POST请求的“已连接”异常 [英] 'Already Connected' exception trying to do POST request using Jersey Client API

查看:676
本文介绍了尝试使用Jersey Client API执行POST请求的“已连接”异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating integration tests for a JAX-RS/Jersey Webservice deployed on Tomcat 8 using arquillian.

我正在尝试执行类似的POST请求:

I am trying to do a POST request like that:

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));

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

When I do that I get this exception:

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 :)
谢谢

I could use some heuristic since I am still learning arquillian and Jersey client API :) Thank you

推荐答案

可能是 java.lang.IllegalStateException :已连接仅屏蔽 SSLHandshakeException 。请查看#3000 (以前称为 JERSEY-2728 错误)。

It may be that java.lang.IllegalStateException: Already connected only masks the SSLHandshakeException. Please take a look at the issue #3000 (previously known as JERSEY-2728 bug).

这篇关于尝试使用Jersey Client API执行POST请求的“已连接”异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆