Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:21:14+00:00 2026-05-22T18:21:14+00:00

I am trying to implement request retries after response isn’t received. I was reading

  • 0

I am trying to implement request retries after response isn’t received.
I was reading about it in the Httpclient tutorial. the HttpRequestRetryHandler gets invoked only once and then it throw exception . what do I do wrong here?

updated
I added one if condition in the exception handling for SocketTimeoutException.
but what to do from there? how can I retry?

private void setRetry(int executionCount)
{
    myRetryHandler = new HttpRequestRetryHandler() {

        public boolean retryRequest(IOException exception,int executionCount,HttpContext context) {

            if (executionCount >= 4) {
                // Do not retry if over max retry count
                System.out.println("retry count");
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                System.out.println("NoHttpResponseException exception");// Retry if the server dropped connection on us
                return true;
            }
            if (exception instanceof SSLHandshakeException) {
                // Do not retry on SSL handshake exception
                System.out.println("SSLHandshakeException exception");
                return false;
            }
            if (exception instanceof java.net.SocketTimeoutException) {
              // Do not retry on SSL handshake exception
              System.out.println("java.net.SocketTimeoutException exception");
              return false;
            }
            HttpRequest request = (HttpRequest) context.getAttribute( ExecutionContext.HTTP_REQUEST);
            boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); 
            if (idempotent) {
                System.out.println("idempotent exception");
                // Retry if the request is considered idempotent 
                return true;
            }
            return false;
        }
    };
}
public  String postHttpReqest(int retries,
                              int socketTimeoutMillis,
                              int isSSL,
                              String target,
                              String url,
                              String base_url,
                              int port,
                              LinkedHashMap<String, String> lHashMapParams) throws Exception 
{


    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 50000);
    HttpConnectionParams.setSoTimeout(httpParams, socketTimeoutMillis);         
    defaulthttpclient = new DefaultHttpClient(httpParams);

    setRetry(retries);  // here i set the handler 
    defaulthttpclient.setHttpRequestRetryHandler(myRetryHandler);

    String line = "";

    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    for (String key : lHashMapParams.keySet()) {
        String val = lHashMapParams.get(key);
        params.add(new BasicNameValuePair(key,val));

    }

    UrlEncodedFormEntity query = new UrlEncodedFormEntity(params); 
    HttpPost httppost = new HttpPost(url+":"+Integer.toString(port)+"//"+base_url);
    httppost.setEntity(query);
    HttpResponse response_ = defaulthttpclient.execute(httppost);
    HttpEntity entity = response_.getEntity();

    if (entity != null) {
        line = EntityUtils.toString(entity);
        System.out.println(line);

    }

    return line;
}

In the server, I set break point so it will hold the connection and will not return response.
The error I am getting in the Httpclient :

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
    at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:260)
    at org.apache.http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:115)
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:633)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:454)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.fts.lb.connector.ut.HttpClientImpl.postHttpReqest(HttpClientImpl.java:183)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:21:15+00:00Added an answer on May 22, 2026 at 6:21 pm

    Googlein a little bit I found this bug in the HttpClient 4.1 client (only on Windows).

    For my problem I already use the latest 4.1.1, but maybe I have to implement the retryHandler.

    I hope it will be helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a request to an unreliable server. The request is
Am trying to implement a generic way for reading sections from a config file.
I am trying to implement a simple request to Wikipedia's API using AJAX (XMLHttpRequest).
I am trying to implement a session-per-request pattern in an ASP.NET MVC 2 Preview
I'm trying to implement a Polymorphic Queue. Here is my trial: QQueue <Request *>
I am trying to implement a dispatcher actor that either process the request or
I'm trying to implement a way to trigger a request for map overlay data
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
I am trying to implement string unescaping with Python regex and backreferences, and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.