Hi Roland,
To see Connection TimeOut working I have done following 3 different
implementations:
Implementation 1:
MultiThreadedHttpConnectionManager connManager = new
MultiThreadedHttpConnectionManager();
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(host,port);
HttpConnectionManagerParams connParams = connManager.getParams();
connParams.setConnectionTimeout(1);
HttpClient httpclient = new HttpClient(connManager);
httpclient.setHostConfiguration(hostConfig);
httpclient.getParams().setAuthenticationPreemptive(true);
httpclient.getState().setCredentials(
new AuthScope(host, port, realm,authenticationScheme),
new UsernamePasswordCredentials(userName, password));
methodClass = new PostMethod(command);
byte [] byteInput = xmlContents.getBytes();
ByteArrayInputStream bi = new ByteArrayInputStream(byteInput);
entity = new InputStreamRequestEntity(bi,
InputStreamRequestEntity.CONTENT_LENGTH_AUTO);
((PostMethod)methodClass).setRequestEntity(entity);
methodClass.setRequestHeader(REQUEST_HEADER_CONTENT_TYPE_NAME,
REQUEST_HEADER_CONTENT_TYPE_VALUE);
methodClass.setRequestHeader(REQUEST_HEADER_SOAP_ACTION_NAME,
soapAction);
methodClass.setDoAuthentication( true );
synchronized(this)
{
try
{
this.wait(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
int status = httpclient.executeMethod( methodClass );
response = status +"\n"+methodClass.getResponseBodyAsString();
I couldn't see any impact of connection time out in the implementation
1.
Implementation 2:
Then As per your advice I have implemented connection time out for
Httpclient as below:
MultiThreadedHttpConnectionManager connManager = new
MultiThreadedHttpConnectionManager();
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(host,port);
HttpClient httpclient = new HttpClient(connManager);
httpclient.setHostConfiguration(hostConfig);
HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(1);
clientParams.setConnectionManagerTimeout(1);
httpclient.setParams(clientParams);
httpclient.getParams().setAuthenticationPreemptive(true);
httpclient.getState().setCredentials(
new AuthScope(host, port, realm,authenticationScheme),
new UsernamePasswordCredentials(userName, password));
methodClass = new PostMethod(command);
byte [] byteInput = xmlContents.getBytes();
ByteArrayInputStream bi = new ByteArrayInputStream(byteInput);
entity = new InputStreamRequestEntity(bi,
InputStreamRequestEntity.CONTENT_LENGTH_AUTO);
((PostMethod)methodClass).setRequestEntity(entity);
methodClass.setRequestHeader(REQUEST_HEADER_CONTENT_TYPE_NAME,
REQUEST_HEADER_CONTENT_TYPE_VALUE);
methodClass.setRequestHeader(REQUEST_HEADER_SOAP_ACTION_NAME,
soapAction);
methodClass.setDoAuthentication( true );
synchronized(this)
{
try
{
this.wait(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
int status = httpclient.executeMethod( methodClass );
response = status +"\n"+methodClass.getResponseBodyAsString();
In this implementation also same result.
Implementation 3:
MultiThreadedHttpConnectionManager connManager = new
MultiThreadedHttpConnectionManager();
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(host,port);
HttpClient httpclient = new HttpClient(connManager);
httpclient.setHostConfiguration(hostConfig);
httpclient.getParams().setAuthenticationPreemptive(true);
httpclient.getState().setCredentials(
new AuthScope(host, port, realm,authenticationScheme),
new UsernamePasswordCredentials(userName, password));
methodClass = new PostMethod(url);
byte [] byteInput = xmlContents.getBytes();
ByteArrayInputStream bi = new ByteArrayInputStream(byteInput);
entity = new InputStreamRequestEntity(bi,
InputStreamRequestEntity.CONTENT_LENGTH_AUTO);
((PostMethod)methodClass).setRequestEntity(entity);
methodClass.setRequestHeader(REQUEST_HEADER_CONTENT_TYPE_NAME,
REQUEST_HEADER_CONTENT_TYPE_VALUE);
methodClass.setRequestHeader(REQUEST_HEADER_SOAP_ACTION_NAME,
soapAction);
methodClass.setDoAuthentication( true );
synchronized(this)
{
try
{
this.wait(250);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
HttpConnection httpConnection =
httpclient.getHttpConnectionManager().getConnectionWithTimeout
(httpclient.getHostConfiguration(),10000);
httpConnection.open();
HttpState httpState = httpclient.getState();
int status = methodClass.execute(httpclient.getState(),httpConnection);
response = status +"\n"+methodClass.getResponseBodyAsString();
System.out.println(response);
In this implementation also same result.
So in all these implementation I am unable to see the connection time
out working.
Could you please help me in resolving this issue?
Regards,
Lalit
-----Original Message-----
From: Roland Weber [mailto:[EMAIL PROTECTED]
Sent: Monday, December 11, 2006 5:07 PM
To: HttpClient User Discussion
Subject: RE: How to test Connection timeout
Hello Lalit,
> int status =
methodClass.execute(httpclient.getState(),httpConnection);
You MUST use one of the HttpClient.execute(...) methods.
Authentication will not work any other way.
cheers,
Roland
> -----Original Message-----
> From: Roland Weber [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 11, 2006 3:40 PM
> To: HttpClient User Discussion
> Subject: RE: How to test Connection timeout
>
>
> Hello Lalit,
>
> > When I am using HttpConnection I am getting following error:
> >
> > Error 401--Unauthorized
> >
> > When I am using HttpClient instead of HttpConnection it is working
> fine.
>
> You can NOT use HttpConnection directly. All HTTP logic,
> including authentication, is implemented in HttpMethodBase
> or the method director. You MUST use HttpClient.
>
> cheers,
> Roland
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]