hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Speirs <wspe...@apache.org>
Subject Re: Httpclient 4 inside a JSP TAG
Date Thu, 05 Jan 2012 15:00:43 GMT
Could you setup a session listener and call create/shutdown there?

Bill-

On Thu, Jan 5, 2012 at 8:31 AM, Amon <argenstijn@hotmail.com> wrote:
>
> Hi all,
>
> I have a question concerning the use of HTTPClient 4 inside a JSP Tag
>
> It's about the creation of the DefaultHttpClient object and how to shutdown the ConnectionManager()
inside a tag.
>
> Currently i am creating a DefaultHttpClient object and shutting it down for each request
to the JSP TAG.
>
> Below a code example:
>
>
> public class Example Tag extends TagSupport {
>
> .....
>
>    @Override
>    public int doStartTag() throws JspException {
>
>         DefaultHttpClient httpclient = new DefaultHttpClient();
>        try{
>
>            // Http-request
>            HttpGet httpget = new HttpGet(uri);
>
>            // Execute HTTP request
>            LOGGER.debug("executing request: " + httpget.getURI());
>            HttpResponse response = httpclient.execute(httpget);
>            LOGGER.debug("Response status: "+response.getStatusLine());
>
>            if( response.getStatusLine().getStatusCode() == 200) {
>                //Get hold of the response entity
>                HttpEntity entity = response.getEntity();
>                if (entity != null) {
>                   //write the result to the output...
>                }else {
>                    throw new JspException ("blabla");
>                }
>            }else {
>                 //Do not feel like reading the response body.
>                httpget.abort();
>                throw new JspException ("blabla"+ response.getStatusLine());
>
>            }
>        }catch(IOException ex){
>            throw new JspException ("blabla",ex);
>        }finally {
>            //When HttpClient instance is no longer needed,
>            //shut down the connection manager to ensure
>            //immediate deallocation of all system resources
>            httpclient.getConnectionManager().shutdown();
>        }
>    }
>
> }
>
>
> My question:
> 1. Is it bad (performace wise,etc) to create for each request a new DefaultHttpClient();
object? (and to shut it down!)
>
> It's pretty easy to create one DefaultHttpClient(); for the JSP TAG. But there no way
to shut it down properly if the JSP TAG is not used anymore.
> (The only way the TAG will be not be used anymore is when the Application is down).
>
> 2. It's necessary to call  httpclient.getConnectionManager().shutdown();  inside a
tag?
>
>
>
>
>

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


Mime
View raw message