Я создаю интеграционные тесты для JAX-RS/Jersey Webservice, развернутого на Tomcat 8 с использованием arquillian.
Я пытаюсь сделать запрос 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
Я мог бы использовать некоторую эвристику, так как я все еще изучаю API-интерфейс arquillian и Jersey client:) Спасибо вам