hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From RRangara...@inautix.com
Subject Help required - in setting the Socket Timeout - setSoTimeOut - HttpClient - commons
Date Tue, 28 Sep 2004 11:05:44 GMT





Hi Everyone

Iam Raghavan R, using the jakarta - commons - HttpClient utility viz,
commons-httpclient-2.0-rc3.jar, commons-logging.jar,
commons-logging-api.jar.

In our project we have class which uses - HttpClient to create secure
connection.

The question is 'Iam getting connection:timed out' exception all along
(if i dont use the bolded code to setSoTimeOut () param using
HttpConnection, HttpConnectionManager objects).

If i use (code below), I get 'java.lang.IllegalStateException: a default
host must be set to create a host URL.
The output i got for SOP - is null for HOST.

I dont know how can over come the Connection timed out exception or
IllegalStateException (here to set the HOST part).

One of the property file is used to load the actual URL in a different
method - and that works fine - iam able to see the SOP of URL iam
connecting to.

Another important thing is, the same code works in one of the other
machines. Both have the same setup and property files and property values.

If anyone, does know how to set - SOTimeOut using setSOTimeOut () - please
do give that.

The Code is given below for your info:

=================================  CODE  START
String response = null;
try
{
//PutMethod post = new PutMethod(url);

PostMethod post = new PostMethod(url);
post.setRequestBody((input));

// Per default, the request content needs to be buffered
// in order to determine its length.
// Request body buffering can be avoided when
// = content length is explicitly specified
// = chunk-encoding is used

if (input.length() < Integer.MAX_VALUE)
{
post.setRequestContentLength((int)input.length());
}
else
{
post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
}

// Specify content type and encoding
// If content encoding is not explicitly specified
// ISO-8859-1 is assumed

//System.out.println("commented the content type text/xml");

post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
// Get HTTP client

HttpClient httpclient = new HttpClient();

/* *******************
// This is a part of code that we used for accessing Sungard QA environment
// when Sungard did not ahve a valid certificate in QA.
// <GL> 09/26/04
if (trustSungardServer)
{
httpclient.setStrictMode(false);
}
********************** */

// Execute request

long start =      System.currentTimeMillis();
HostConfiguration hostConfiguration = httpclient.getHostConfiguration ();
System.out.println( ">>> Host ===============" + hostConfiguration.getHost
() );
System.out.println( ">>> HostURL ============" +
hostConfiguration.getHostURL () );
System.out.println(">>> PORT ==============" + hostConfiguration.getPort()
);
System.out.println(">>> PROTOCOL ==========" +
hostConfiguration.getProtocol() ) ;

HttpConnectionManager httpConnectionManager =
httpclient.getHttpConnectionManager() ;
HttpConnection httpConnection=
httpConnectionManager.getConnection(hostConfiguration);

httpConnection.setSoTimeout(50000);


int result = httpclient.executeMethod(post);

long end    =     System.currentTimeMillis();
System.out.println("total time is " + (end-start) + "millis");
System.out.println("total time is " + ((end-start)/1000) + "secs");


// Display response
System.out.println("Response body: ");
response = post.getResponseBodyAsString();
Header [] responseHeaders = post.getResponseHeaders();
=================================================================== END
CODE


Thanks & Regards,
Raghavan  Rangarajan

Location: 11C123
PSTN: +91 44 2254 6000 Extn:2703
Office e-mail-id: rrangarajan@inautix.com
iNautix Technologies India Private Limited


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Mime
View raw message