0

I suddenly started to get a connection reset exception with an api that I have been communicating with for 4 years. The server provider is telling me that he didn't change anything and I didn't either. Whats weird is that I get a success response when I call the same api on postman. I have even tried python to call it but I get the same error.

http client to call the api

HttpClient client = new HttpClient();


    client.getHttpConnectionManager().
    getParams().setConnectionTimeout(5000);
    client.getHttpConnectionManager().
    getParams().setSoTimeout(60000);

    GetMethod method = new GetMethod(smsUrl);

    method.setQueryString(new NameValuePair[] { 
            new NameValuePair("username", user), 
            new NameValuePair("password", pass), 
            new NameValuePair("action", "sendsms"), 
            new NameValuePair("from", "Sender"),
            new NameValuePair("to", toMobile), 
            new NameValuePair("text", textBody)
    });

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine());
            String responseBody = method.getResponseBodyAsString();
            System.out.println(new String(responseBody));

        }



    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();

    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());

        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }  

Error stacktrace

Fatal transport error: Connection reset
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at    sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:709)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:827)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1975)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)

1 Answer 1

2

I have also faced similar problem. But solved when upgrading client JDK from 7 to 8. Ref link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.