You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Roland Weber <RO...@de.ibm.com> on 2004/06/03 12:46:40 UTC
Re: HttpConnection and HttpState reuse problem
Hello Himanshu,
you can create your own HttpState object and pass it
to each method invocation. That should solve your first
problem.
Why don't you leave the connection re-use to the
connection manager? For an application, it shouldn't
matter at all whether it is the same or a different
connection. If it is an absolute requirement, you can
still implement your own connection manager.
cheers,
Roland
Himanshu Thube <hi...@kenati.com>
03.06.2004 18:24
Please respond to "Commons HttpClient Project"
To: commons-httpclient-dev@jakarta.apache.org
cc:
Subject: HttpConnection and HttpState reuse problem
Hi
In my class I need two connections to same host and different URL's. For
connecting first time, I want to get the HttpState and HttpConnection.
Later just execute the method using the same HttpConnection and HttpState.
However from API I found, to get the state I need to execute the method
with HttpClient for the first time as only HttpClient is able to return
the HttpState. For the later executions of GetMethod I am not able to
reuse the HttpConnection used for first execution as HttpClient doesn't
provide me a handle to the HttpConnection which it used for first
execution.
My existing code is as follows :
*For first invocation *:
httpsclient = new HttpClient();
int statusCode = -1;
String [] response=new String[2];
httpsget = new GetMethod(uri.toString());
statusCode = httpsclient.executeMethod(httpsget);
state=httpsclient.getState();
*For Later invocations : (now I have the HttpsState but no handle to
HttpConnection used :( so have to create a new HttpConnection)*
if(con==null) {
try {
con=new HttpConnection(uri.getHost(), uri.getPort(),
getProtocol());
} catch (URIException e1) {
e1.printStackTrace();
}
}
try {
httpsget.recycle();
httpsget.setPath(connectUrl);
httpsget.execute(state, con);
} catch (IOException e) {
e.printStackTrace();
}
---------------------------------------------------------------------
To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org