im trying to implement request re try's after response doesn't received i
was reading about it in the httpclient tutorial , the
HttpRequestRetryHandler does invoked only once and then it throw exception .
what i do wrong here ?

here is the code im using:
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;
                }
                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 not
return response the error im 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)

Thanks

Reply via email to