Search code examples
javaspringweblogic

java.io.IOException: Connection reset by peer' when using AsyncRestTemplate on weblogic server


My Springboot application is deployed on a weblogic server which sits on my vps and when i run the method that intends to invoke an API method of another website i am returned with this error :

java.util.concurrent.ExecutionException: java.io.IOException: Connection reset by peer
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_144]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_144]
    at org.springframework.util.concurrent.FutureAdapter.get(FutureAdapter.java:81) ~[spring-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_144]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: java.io.IOException: Connection reset by peer
    at sun.nio.ch.FileDispatcherImpl.readv0(Native Method) ~[na:1.8.0_144]
    at sun.nio.ch.SocketDispatcher.readv(SocketDispatcher.java:43) ~[na:1.8.0_144]
    at sun.nio.ch.IOUtil.read(IOUtil.java:278) ~[na:1.8.0_144]
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:440) ~[na:1.8.0_144]
    at weblogic.socket.NIOInputStream.readInternal(NIOInputStream.java:168) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at weblogic.socket.NIOInputStream.read(NIOInputStream.java:110) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at weblogic.socket.NIOInputStream.read(NIOInputStream.java:73) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at weblogic.socket.JSSEFilterImpl.readFromNetwork(JSSEFilterImpl.java:508) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at weblogic.socket.JSSEFilterImpl.read(JSSEFilterImpl.java:470) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at weblogic.socket.JSSESocket$JSSEInputStream.read(JSSESocket.java:119) ~[com.oracle.weblogic.server.muxers.jar:12.2.1.3]
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_144]
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[na:1.8.0_144]
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[na:1.8.0_144]
    at weblogic.net.http.MessageHeader.isHTTP(MessageHeader.java:310) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at weblogic.net.http.MessageHeader.parseHeader(MessageHeader.java:232) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at weblogic.net.http.HttpClient.parseHTTP(HttpClient.java:554) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:688) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at weblogic.net.http.SOAPHttpsURLConnection.getInputStream(SOAPHttpsURLConnection.java:42) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at weblogic.net.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1547) ~[com.oracle.weblogic.net.jar:12.2.1.3]
    at org.springframework.http.client.SimpleBufferingAsyncClientHttpRequest$1.call(SimpleBufferingAsyncClientHttpRequest.java:94) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.http.client.SimpleBufferingAsyncClientHttpRequest$1.call(SimpleBufferingAsyncClientHttpRequest.java:77) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    ... 4 common frames omitted

I have noticed that this only happens when i use Springs AsyncRestTemplate to invoke API calls.

ListenableFuture<ResponseEntity<String>> y = asyncRestTemplate.exchange(desiredUrl, HttpMethod.GET, new HttpEntity<>("result"), String.class);//.get().getBody();
       boolean done = false;
        while (done == false)
        {
            if (y.isDone() == true)
            {
            response = y.get().getBody();
                        return response;
            }

        } 

    } catch (InterruptedException | ExecutionException ex) {

        Logger.getLogger(HTTP_Methods.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

Solution

  • The error

    Connection reset by peer
    

    is a response by the remote server (or firewall between them) stating that it will not proceed with completing this request.

    It may well be a firewall denial, an SSL handshake failure, a proxy problem or even an HTTP failed request.