“已连接”异常尝试使用泽西客户端 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:)谢谢