hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject HttpConnection and HttpState reuse problem
Date Thu, 03 Jun 2004 12:40:10 GMT
Hi Himanshu,

HttpClient intentionally does not give direct access to the connections 
used to execute methods.  All connection management is handled by the 
HttpConnectionManagers and the HttpClient.  As Roland mentioned, if you 
need custom connection management you should consider implementing an 
HttpConnectionManager.  My guess is that the two included connection 
managers (SimpleHttpConnectionManager and 
MultiThreadedHttpConnectionManager) should suffice for your needs.

Mike

On Jun 3, 2004, at 12:24 PM, Himanshu Thube wrote:

> 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
>


---------------------------------------------------------------------
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