“Already connected” Exception when running jersey application inside docker container

*爱你&永不变心* 提交于 2021-01-28 04:07:20

问题


I am trying to dockerize a jersey application which acts both as a REST server and client. The application seems to behave differently when running inside a docker container.

I am able to perform a request to a non-dockerized service (A). The problem occurs when I try to perform a request on another non-dockerized REST server (B), using, in both cases, JAX-RS client API:

// common code - for contacting both A & B services
private static final Client client = ClientBuilder.newClient().register(JacksonFeature.class);  

// inside the method called for each request
WebTarget target = client.target(location);
// for each query param : target = target.queryParam(..);
logger.info("This is logged successfully");
Response resp = target.request(MediaType.APPLICATION_JSON_TYPE).method(method, Entity.json(payloadBean));
logger.info("This is NOT logged for B service");

At this point I am getting a javax.ws.rs.ProcessingException: Already connected ... Caused by: java.lang.IllegalStateException: Already connected

I use a single Dockerfile where I set up oracle-java-8 and (Tomcat or Jetty), in the exact same way I did on the host before docker where everything works fine!

There is no SSL involved for sure.

Running my app on the same VM with B service produces the same behavior.

Service A is jersey, while B is django, but that shouldn't be relative to the problem since they are both REST services.

Any idea on how I could debug this situation?


回答1:


I am sorry for the spam, as it turned out it was a very stupid mistake:

service A location was an IP address
service B location was an uknown dns name to the container

Thus passing --add-host B_fqdn:B_internal_IP to docker run solved the issue



来源:https://stackoverflow.com/questions/36622484/already-connected-exception-when-running-jersey-application-inside-docker-cont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!