You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2008/11/04 10:45:39 UTC

Re: httpclient timeout: https vs. http

On Fri, 2008-10-31 at 10:39 -0700, Ben Smith wrote:
> Hi Oleg,
> 
> I used your EasySSLProtocolSocketFactory and tried the following code. Timeout still wouldn't work. Can you please help?
> 

Ben

I just double-checked. EasySSLProtocolSocketFactory handles connect
timeouts correctly. Make sure you have the latest version of the socket
factory or make sure the code you have makes use of Java 1.4 detached
socket API

Oleg


> Thanks,
> Ben
> 
> EasySSLProtocolSocketFactory factory = new EasySSLProtocolSocketFactory();
> 		HttpClient client = new HttpClient();
> 		client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> 		
> 		Protocol easyhttps = new Protocol("https", factory, 443);
> 		client.getHostConfiguration().setHost("rtdsl-uat.princetonecom.com", 443, easyhttps);
> 		GetMethod httpget = new GetMethod("/pngRTDS/scanline/xml");
> 		try {
> 			client.executeMethod(httpget);
> 			System.out.println(httpget.getStatusLine());
> 		} finally {
> 			httpget.releaseConnection();
> 		}
> 
> 
> 
> 
> 
> --- On Fri, 10/31/08, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > From: Oleg Kalnichevski <ol...@apache.org>
> > Subject: Re: httpclient timeout: https vs. http
> > To: httpclient-users@hc.apache.org
> > Date: Friday, October 31, 2008, 8:23 AM
> > On Thu, 2008-10-30 at 15:54 -0700, Ben Smith wrote:
> > > Hi All,
> > > 
> > > I ran a code from one of your post as below by Oleg
> > with two different urls.
> > > url 1: http://www.au.yahoo.com/
> > > url 2:
> > https://rtdsl-uat.princetonecom.com/pngRTDS/scanline/xml
> > > 
> > > url 1 gave the same result as your post, while url 2
> > always succeeded and output the following even I set timeout
> > to 100 milliseconds. How can I set timeout for this https
> > url? Please help.
> > > 
> > > Thanks,
> > > Ben
> > 
> > Ben,
> > 
> > This is a known limitation of HttpClient 3.x due to Java
> > 1.2.2
> > compatibility requirement. You can solve the problem by
> > proving an
> > implementation of SecureProtocolSocketFactory that can can
> > handle
> > connect timeouts using Java 1.4 API
> > 
> > Oleg
> > 
> > > ---------------------------------------------------
> > > Code (by Oleg):
> > > 
> > > HttpClient client = new HttpClient();
> > >
> > client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> > > GetMethod httpget = new GetMethod(url);
> > > try {
> > >   client.executeMethod(httpget);
> > >   System.out.println(httpget.getStatusLine());
> > >  
> > System.out.println(httpget.getResponseBodyAsString());
> > > } finally {
> > >   httpget.releaseConnection();
> > > }
> > > 
> > > ---------------------------------------------------
> > > ......elapsed 0 seconds
> > > ......elapsed 5 seconds
> > > HTTP/1.1 200 OK
> > > 
> > > <?xml version="1.0" ?>
> > > <RESPONSE version="1.0">
> > >    ....
> > > </RESPONSE>
> > > 
> > > 
> > >       
> > > 
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail:
> > httpclient-users-help@hc.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail:
> > httpclient-users-help@hc.apache.org
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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


Re: httpclient timeout: https vs. http

Posted by Mohamed AbuZur <am...@gmail.com>.
I Have this code in my application:


HttpClient client = new HttpClient();

        client.getParams().setConnectionManagerTimeout(timeOut);
        client.getParams().setSoTimeout(timeOut);

client.getHttpConnectionManager().getParams().setConnectionTimeout(timeOut);





On Tue, Nov 18, 2008 at 5:30 PM, Christine <ch...@christine.nl> wrote:

> On Wed, 2008-11-05 at 14:00 +0100, Oleg Kalnichevski wrote:
> > ssion.
> >
> > You may also want to consider upgrading to HttpClient 4.0
>
> How do I set a timeout on a connectionmanager in HttpClient 4.0? Does it
> have a default timeout?
>
> Christine
>
>
>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> --
> dagdag is just a two character rotation of byebye
> www.christine.nl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: httpclient timeout: https vs. http

Posted by Christine <ch...@christine.nl>.
On Tue, 2008-11-18 at 17:30 +0100, Christine wrote:

> How do I set a timeout on a connectionmanager in HttpClient 4.0? Does it
> have a default timeout?

Err, right. I found it. I use
params.setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
 
Christine - confused because her cat is very sick...

> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


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


Re: httpclient timeout: https vs. http

Posted by Christine <ch...@christine.nl>.
On Wed, 2008-11-05 at 14:00 +0100, Oleg Kalnichevski wrote:
> ssion.
> 
> You may also want to consider upgrading to HttpClient 4.0

How do I set a timeout on a connectionmanager in HttpClient 4.0? Does it
have a default timeout?

Christine



> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


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


Re: httpclient timeout: https vs. http

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-11-04 at 09:15 -0800, Ben Smith wrote:
> Hi Oleg,
> 
> I got the code of your EasySSLProtocolSocketFactory from the link of
> http://hc.apache.org/httpclient-3.x/sslguide.html. And I used Java 5. Did these ensured the two things you mentionsed - "the latest version" and "Java 1.4 detached socket API" ? 
> 
> Can you please help check whether my code has any problem? I ran it and both connection and read timeout did not work. There must be something wrong.
> 
> Thanks for your reply.
> Ben
> 

I see nothing wrong with your code. Connect timeout _should_ work. If
you are absolutely sure it does not, send me a wire / context log of the
session.

You may also want to consider upgrading to HttpClient 4.0

Oleg


> >>>>>>>Code I used to test<<<<<<<
> String host ="rtdsl-uat.princetonecom.com";
> String dest = "/pngRTDS/scanline/xml";
> 
> /*------------*/
> EasySSLProtocolSocketFactory factory = new EasySSLProtocolSocketFactory();
> Protocol sslProtocol = new Protocol("https", factory, 443);
> HostConfiguration hostConf = new HostConfiguration();
> hostConf.setHost(host, 443, sslProtocol);
> 
> // Will pick up sslProtocol from hostConf
> PostMethod postmethod = new PostMethod(dest);
> HttpClient client = new HttpClient();
> /*--------------*/
> 
> hostConf.getParams().setParameter("http.socket.timeout", 200);
> 
> client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> client.getHttpConnectionManager().getParams().setSoTimeout(100);
> 
> reportDuration(start);
> try {
> 	int statusCode = client.executeMethod(hostConf, postmethod);
> 	reportDuration(start);
> 	System.out.println("statusCode = " + statusCode);
> 	if (statusCode != HttpStatus.SC_OK) {
> 		System.err.println("HTTPS Post failed [" + url + ", "
> 				+ postmethod.getStatusText() + "]");
> 		throw new IOException("HTTPS Post failed [" + url + ", "
> 				+ postmethod.getStatusText() + "]");
> 	}
> 
> 	String responseBody = postmethod.getResponseBodyAsString();
> 	System.out.println("Recieved response from server...\n" + responseBody);
> } catch(IOException ioe) {
> 	System.out.println("sslPostMsg2(): exception caught>>> " + ioe.getMessage());
> 	System.out.println("sslPostMsg2(): " + ioe.getCause());
> 	throw ioe;
> } finally {
> 	postmethod.releaseConnection();
> }
> 
> 
> 
> --- On Tue, 11/4/08, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > From: Oleg Kalnichevski <ol...@apache.org>
> > Subject: Re: httpclient timeout: https vs. http
> > To: "HttpClient User Discussion" <ht...@hc.apache.org>
> > Date: Tuesday, November 4, 2008, 3:45 AM
> > On Fri, 2008-10-31 at 10:39 -0700, Ben Smith wrote:
> > > Hi Oleg,
> > > 
> > > I used your EasySSLProtocolSocketFactory and tried the
> > following code. Timeout still wouldn't work. Can you
> > please help?
> > > 
> > 
> > Ben
> > 
> > I just double-checked. EasySSLProtocolSocketFactory handles
> > connect
> > timeouts correctly. Make sure you have the latest version
> > of the socket
> > factory or make sure the code you have makes use of Java
> > 1.4 detached
> > socket API
> > 
> > Oleg
> > 
> > 
> > > Thanks,
> > > Ben
> > > 
> > > EasySSLProtocolSocketFactory factory = new
> > EasySSLProtocolSocketFactory();
> > > 		HttpClient client = new HttpClient();
> > >
> > 		client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> > > 		
> > > 		Protocol easyhttps = new Protocol("https",
> > factory, 443);
> > >
> > 		client.getHostConfiguration().setHost("rtdsl-uat.princetonecom.com",
> > 443, easyhttps);
> > > 		GetMethod httpget = new
> > GetMethod("/pngRTDS/scanline/xml");
> > > 		try {
> > > 			client.executeMethod(httpget);
> > > 			System.out.println(httpget.getStatusLine());
> > > 		} finally {
> > > 			httpget.releaseConnection();
> > > 		}
> > > 
> > > 
> > > 
> > > 
> > > 
> > > --- On Fri, 10/31/08, Oleg Kalnichevski
> > <ol...@apache.org> wrote:
> > > 
> > > > From: Oleg Kalnichevski <ol...@apache.org>
> > > > Subject: Re: httpclient timeout: https vs. http
> > > > To: httpclient-users@hc.apache.org
> > > > Date: Friday, October 31, 2008, 8:23 AM
> > > > On Thu, 2008-10-30 at 15:54 -0700, Ben Smith
> > wrote:
> > > > > Hi All,
> > > > > 
> > > > > I ran a code from one of your post as below
> > by Oleg
> > > > with two different urls.
> > > > > url 1: http://www.au.yahoo.com/
> > > > > url 2:
> > > >
> > https://rtdsl-uat.princetonecom.com/pngRTDS/scanline/xml
> > > > > 
> > > > > url 1 gave the same result as your post,
> > while url 2
> > > > always succeeded and output the following even I
> > set timeout
> > > > to 100 milliseconds. How can I set timeout for
> > this https
> > > > url? Please help.
> > > > > 
> > > > > Thanks,
> > > > > Ben
> > > > 
> > > > Ben,
> > > > 
> > > > This is a known limitation of HttpClient 3.x due
> > to Java
> > > > 1.2.2
> > > > compatibility requirement. You can solve the
> > problem by
> > > > proving an
> > > > implementation of SecureProtocolSocketFactory
> > that can can
> > > > handle
> > > > connect timeouts using Java 1.4 API
> > > > 
> > > > Oleg
> > > > 
> > > > >
> > ---------------------------------------------------
> > > > > Code (by Oleg):
> > > > > 
> > > > > HttpClient client = new HttpClient();
> > > > >
> > > >
> > client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> > > > > GetMethod httpget = new GetMethod(url);
> > > > > try {
> > > > >   client.executeMethod(httpget);
> > > > >  
> > System.out.println(httpget.getStatusLine());
> > > > >  
> > > >
> > System.out.println(httpget.getResponseBodyAsString());
> > > > > } finally {
> > > > >   httpget.releaseConnection();
> > > > > }
> > > > > 
> > > > >
> > ---------------------------------------------------
> > > > > ......elapsed 0 seconds
> > > > > ......elapsed 5 seconds
> > > > > HTTP/1.1 200 OK
> > > > > 
> > > > > <?xml version="1.0" ?>
> > > > > <RESPONSE version="1.0">
> > > > >    ....
> > > > > </RESPONSE>
> > > > > 
> > > > > 
> > > > >       
> > > > > 
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > httpclient-users-unsubscribe@hc.apache.org
> > > > > For additional commands, e-mail:
> > > > httpclient-users-help@hc.apache.org
> > > > > 
> > > > 
> > > > 
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > > httpclient-users-unsubscribe@hc.apache.org
> > > > For additional commands, e-mail:
> > > > httpclient-users-help@hc.apache.org
> > > 
> > > 
> > >       
> > > 
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail:
> > httpclient-users-help@hc.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail:
> > httpclient-users-help@hc.apache.org
> 
> 
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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


Re: httpclient timeout: https vs. http

Posted by Ben Smith <be...@yahoo.com>.
Hi Oleg,

I got the code of your EasySSLProtocolSocketFactory from the link of
http://hc.apache.org/httpclient-3.x/sslguide.html. And I used Java 5. Did these ensured the two things you mentionsed - "the latest version" and "Java 1.4 detached socket API" ? 

Can you please help check whether my code has any problem? I ran it and both connection and read timeout did not work. There must be something wrong.

Thanks for your reply.
Ben

>>>>>>>Code I used to test<<<<<<<
String host ="rtdsl-uat.princetonecom.com";
String dest = "/pngRTDS/scanline/xml";

/*------------*/
EasySSLProtocolSocketFactory factory = new EasySSLProtocolSocketFactory();
Protocol sslProtocol = new Protocol("https", factory, 443);
HostConfiguration hostConf = new HostConfiguration();
hostConf.setHost(host, 443, sslProtocol);

// Will pick up sslProtocol from hostConf
PostMethod postmethod = new PostMethod(dest);
HttpClient client = new HttpClient();
/*--------------*/

hostConf.getParams().setParameter("http.socket.timeout", 200);

client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
client.getHttpConnectionManager().getParams().setSoTimeout(100);

reportDuration(start);
try {
	int statusCode = client.executeMethod(hostConf, postmethod);
	reportDuration(start);
	System.out.println("statusCode = " + statusCode);
	if (statusCode != HttpStatus.SC_OK) {
		System.err.println("HTTPS Post failed [" + url + ", "
				+ postmethod.getStatusText() + "]");
		throw new IOException("HTTPS Post failed [" + url + ", "
				+ postmethod.getStatusText() + "]");
	}

	String responseBody = postmethod.getResponseBodyAsString();
	System.out.println("Recieved response from server...\n" + responseBody);
} catch(IOException ioe) {
	System.out.println("sslPostMsg2(): exception caught>>> " + ioe.getMessage());
	System.out.println("sslPostMsg2(): " + ioe.getCause());
	throw ioe;
} finally {
	postmethod.releaseConnection();
}



--- On Tue, 11/4/08, Oleg Kalnichevski <ol...@apache.org> wrote:

> From: Oleg Kalnichevski <ol...@apache.org>
> Subject: Re: httpclient timeout: https vs. http
> To: "HttpClient User Discussion" <ht...@hc.apache.org>
> Date: Tuesday, November 4, 2008, 3:45 AM
> On Fri, 2008-10-31 at 10:39 -0700, Ben Smith wrote:
> > Hi Oleg,
> > 
> > I used your EasySSLProtocolSocketFactory and tried the
> following code. Timeout still wouldn't work. Can you
> please help?
> > 
> 
> Ben
> 
> I just double-checked. EasySSLProtocolSocketFactory handles
> connect
> timeouts correctly. Make sure you have the latest version
> of the socket
> factory or make sure the code you have makes use of Java
> 1.4 detached
> socket API
> 
> Oleg
> 
> 
> > Thanks,
> > Ben
> > 
> > EasySSLProtocolSocketFactory factory = new
> EasySSLProtocolSocketFactory();
> > 		HttpClient client = new HttpClient();
> >
> 		client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> > 		
> > 		Protocol easyhttps = new Protocol("https",
> factory, 443);
> >
> 		client.getHostConfiguration().setHost("rtdsl-uat.princetonecom.com",
> 443, easyhttps);
> > 		GetMethod httpget = new
> GetMethod("/pngRTDS/scanline/xml");
> > 		try {
> > 			client.executeMethod(httpget);
> > 			System.out.println(httpget.getStatusLine());
> > 		} finally {
> > 			httpget.releaseConnection();
> > 		}
> > 
> > 
> > 
> > 
> > 
> > --- On Fri, 10/31/08, Oleg Kalnichevski
> <ol...@apache.org> wrote:
> > 
> > > From: Oleg Kalnichevski <ol...@apache.org>
> > > Subject: Re: httpclient timeout: https vs. http
> > > To: httpclient-users@hc.apache.org
> > > Date: Friday, October 31, 2008, 8:23 AM
> > > On Thu, 2008-10-30 at 15:54 -0700, Ben Smith
> wrote:
> > > > Hi All,
> > > > 
> > > > I ran a code from one of your post as below
> by Oleg
> > > with two different urls.
> > > > url 1: http://www.au.yahoo.com/
> > > > url 2:
> > >
> https://rtdsl-uat.princetonecom.com/pngRTDS/scanline/xml
> > > > 
> > > > url 1 gave the same result as your post,
> while url 2
> > > always succeeded and output the following even I
> set timeout
> > > to 100 milliseconds. How can I set timeout for
> this https
> > > url? Please help.
> > > > 
> > > > Thanks,
> > > > Ben
> > > 
> > > Ben,
> > > 
> > > This is a known limitation of HttpClient 3.x due
> to Java
> > > 1.2.2
> > > compatibility requirement. You can solve the
> problem by
> > > proving an
> > > implementation of SecureProtocolSocketFactory
> that can can
> > > handle
> > > connect timeouts using Java 1.4 API
> > > 
> > > Oleg
> > > 
> > > >
> ---------------------------------------------------
> > > > Code (by Oleg):
> > > > 
> > > > HttpClient client = new HttpClient();
> > > >
> > >
> client.getHttpConnectionManager().getParams().setConnectionTimeout(100);
> > > > GetMethod httpget = new GetMethod(url);
> > > > try {
> > > >   client.executeMethod(httpget);
> > > >  
> System.out.println(httpget.getStatusLine());
> > > >  
> > >
> System.out.println(httpget.getResponseBodyAsString());
> > > > } finally {
> > > >   httpget.releaseConnection();
> > > > }
> > > > 
> > > >
> ---------------------------------------------------
> > > > ......elapsed 0 seconds
> > > > ......elapsed 5 seconds
> > > > HTTP/1.1 200 OK
> > > > 
> > > > <?xml version="1.0" ?>
> > > > <RESPONSE version="1.0">
> > > >    ....
> > > > </RESPONSE>
> > > > 
> > > > 
> > > >       
> > > > 
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > httpclient-users-unsubscribe@hc.apache.org
> > > > For additional commands, e-mail:
> > > httpclient-users-help@hc.apache.org
> > > > 
> > > 
> > > 
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail:
> > > httpclient-users-help@hc.apache.org
> > 
> > 
> >       
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail:
> httpclient-users-help@hc.apache.org


      

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