javax.ws.rs.ProcessingException: Already connected

  1. 0

    Misleading exception is raised once the Jersey client is called once the host with a non-existing, broken or unavailable url is passed in as a parameter for target method. There is no chance to establish connection to such the host but the client is reporting java.lang.IllegalStateException: Already connected instead of rather anticipated UnknownHostException or ConnectException. Example: class DigestRequest { } class DigestResponse { } public class DigestNoLimitClient { public static void main(String[] args) throws Exception { String host = "http://blabla.bla"; Client client = ClientBuilder.newClient(); Entity<DigestRequest> request = Entity.json(new DigestRequest()); Response response = client.target(host).request().post(request); DigestResponse responseObject = response.readEntity(DigestResponse.class); System.out.println(responseObject); } } Result: Exception in thread "main" javax.ws.rs.ProcessingException: Already connected at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:228) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424) at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424) at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:333) at net.adamsmolnik.client.DigestNoLimitClient.main(DigestNoLimitClient.java:43) 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:348) at org.glassfish.jersey.client.HttpUrlConnector.access$100(HttpUrlConnector.java:87) at org.glassfish.jersey.client.HttpUrlConnector$3.getOutputStream(HttpUrlConnector.java:311) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194) at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262) at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:811) at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:546) at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315) at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227) at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246) Compare the behavior of code listed above with that showed below: String host = "http://blabla.bla"; HttpURLConnection con = (HttpURLConnection)new URL(host).openConnection(); con.setDoOutput(true); con.getOutputStream().write(1); You get the exception as expected: Exception in thread "main" java.net.UnknownHostException: blabla.bla at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589)

    Java.net JIRA | 2 years ago | adams74
    java.lang.IllegalStateException: Already connected
  2. 0

    Misleading exception is raised once the Jersey client is called once the host with a non-existing, broken or unavailable url is passed in as a parameter for target method. There is no chance to establish connection to such the host but the client is reporting java.lang.IllegalStateException: Already connected instead of rather anticipated UnknownHostException or ConnectException. Example: class DigestRequest { } class DigestResponse { } public class DigestNoLimitClient { public static void main(String[] args) throws Exception { String host = "http://blabla.bla"; Client client = ClientBuilder.newClient(); Entity<DigestRequest> request = Entity.json(new DigestRequest()); Response response = client.target(host).request().post(request); DigestResponse responseObject = response.readEntity(DigestResponse.class); System.out.println(responseObject); } } Result: Exception in thread "main" javax.ws.rs.ProcessingException: Already connected at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667) at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:228) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424) at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424) at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:333) at net.adamsmolnik.client.DigestNoLimitClient.main(DigestNoLimitClient.java:43) 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:348) at org.glassfish.jersey.client.HttpUrlConnector.access$100(HttpUrlConnector.java:87) at org.glassfish.jersey.client.HttpUrlConnector$3.getOutputStream(HttpUrlConnector.java:311) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194) at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262) at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:811) at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:546) at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315) at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227) at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246) Compare the behavior of code listed above with that showed below: String host = "http://blabla.bla"; HttpURLConnection con = (HttpURLConnection)new URL(host).openConnection(); con.setDoOutput(true); con.getOutputStream().write(1); You get the exception as expected: Exception in thread "main" java.net.UnknownHostException: blabla.bla at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589)

    Java.net JIRA | 2 years ago | adams74
    java.lang.IllegalStateException: Already connected
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Exception in thread "main" java.lang.IllegalStateException: Already connected

    Stack Overflow | 2 years ago | user3195247
    java.lang.IllegalStateException: Already connected

    6 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Already connected

      at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty()
    2. Java RT
      HttpURLConnection.setRequestProperty
      1. sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
      1 frame
    3. jersey-core-client
      HttpUrlConnector$4.getOutputStream
      1. org.glassfish.jersey.client.internal.HttpUrlConnector.setOutboundHeaders(HttpUrlConnector.java:421)
      2. org.glassfish.jersey.client.internal.HttpUrlConnector.access$100(HttpUrlConnector.java:96)
      3. org.glassfish.jersey.client.internal.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:384)
      3 frames
    4. Jersey Core
      OutboundMessageContext.commitStream
      1. org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
      2. org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
      3. org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262)
      4. org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:816)
      4 frames
    5. jersey-core-client
      JerseyInvocation$1.call
      1. org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:545)
      2. org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:388)
      3. org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
      4. org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
      5. org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
      6. org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
      6 frames
    6. Jersey Core
      RequestScope.runInScope
      1. org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      2. org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      3. org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      4. org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
      4 frames
    7. jersey-core-client
      JerseyInvocation$Builder.put
      1. org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
      2. org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
      3. org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:326)
      3 frames
    8. eu.arrowhead.common
      Utility.sendRequest
      1. eu.arrowhead.common.Utility.sendRequest(Utility.java:32)
      1 frame
    9. eu.arrowhead.core
      GatekeeperResource.GSDPoll
      1. eu.arrowhead.core.gatekeeper.GatekeeperResource.GSDPoll(GatekeeperResource.java:146)
      1 frame
    10. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      4. java.lang.reflect.Method.invoke(Unknown Source)
      4 frames
    11. jersey-core-server
      ServerRuntime$2.run
      1. org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
      2. org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
      3. org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
      4. org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
      5. org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
      6. org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
      7. org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
      8. org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
      9. org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
      9 frames
    12. Jersey Core
      RequestScope.runInScope
      1. org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
      2. org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
      3. org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      4. org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      5. org.glassfish.jersey.internal.Errors.process(Errors.java:267)
      6. org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
      6 frames
    13. jersey-core-server
      ApplicationHandler.handle
      1. org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
      2. org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
      2 frames
    14. jersey-container-grizzly2-http
      GrizzlyHttpContainer.service
      1. org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384)
      1 frame
    15. Grizzly Server
      HttpHandler$1.run
      1. org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224)
      1 frame
    16. Grizzly
      AbstractThreadPool$Worker.run
      1. org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
      2. org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
      2 frames
    17. Java RT
      Thread.run
      1. java.lang.Thread.run(Unknown Source)
      1 frame