hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pcable <PCa...@drhorton.com>
Subject Issue with HttpMethodRetryHandler
Date Thu, 30 Apr 2009 20:32:30 GMT

I have the code working to actually bring back the data that I need. 
However, in the process of actually getting it working, I noticed that if
the authentication had any issues (like acct locked out, or unauthorized)
the program would go into an infinite loop of trying to authenticate.  So, I
am trying to fix that before I take this code to production.

The code is as follows:

main(){
	        try { 
	            HttpClient client = new HttpClient(); 
			    List authPrefs = new ArrayList(1);
			    authPrefs.add(AuthPolicy.DIGEST);
			    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);	
			    client.getParams().setParameter(
				       CredentialsProvider.PROVIDER, new ConsoleAuthPrompter());
		   
		        PostMethod gm = new
PostMethod("http://~~servername~~/Maps/MapsStaging/PlatPDFHandler.ashx?pid=3&isbw=0");

			    gm.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
myretryhandler);
		        int status = client.executeMethod(gm); 
		        System.out.println("Response Status: "+ status); 
		        //String result = gm.getResponseBodyAsString(); 
		        //System.out.println(result); 
		        InputStream iStream = gm.getResponseBodyAsStream();
				DataOutputStream oStream = new DataOutputStream(System.out);
		        //FileInputStream iStream = new
FileInputStream(fullFilenameAndPath.toString());
		        byte[] buffer = new byte[1024];
		        int bytesRead = iStream.read(buffer);
		        while(bytesRead > -1)
		        {
		             oStream.write(buffer, 0, bytesRead);      
		             bytesRead = iStream.read(buffer);
		             //System.out.println("bytesRead="+bytesRead);
		        }
		        oStream.flush();
		        oStream.close();
		        //System.out.println("after stream = "+iStream.read());
		        iStream.close();
		        gm.releaseConnection();
	        } catch (IOException e) { 
	        	e.printStackTrace(); 
	        } 

}

		HttpMethodRetryHandler myretryhandler = new HttpMethodRetryHandler() {
		    public boolean retryMethod(
		        final HttpMethod method, 
		        final IOException exception, 
		        int executionCount) {
		        if (executionCount >= 5) {
		            // Do not retry if over max retry count
		            return false;
		        }
		        if (exception instanceof NoHttpResponseException) {
		            // Retry if the server dropped connection on us
		            return true;
		        }
		        if (!method.isRequestSent()) {
		            // Retry if the request has not been sent fully or
		            // if it's OK to retry methods that have been sent
		            return true;
		        }
		        // otherwise do not retry
		        return false;
		    }
		};



I have added the HttpMethodRetryHandler as indicated on the HttpClient main
page, however it doesn't seem to be helping in any way.

Any help with this last remaining issue, would be GREATLY appreciated.
Thanks,
PCable
-- 
View this message in context: http://www.nabble.com/Issue-with-HttpMethodRetryHandler-tp23322612p23322612.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message