On Wed, 2011-04-20 at 06:32 -0700, Donald Fernandes wrote:
> Hi Oleg, 
> 
>  I want the stream to be open since i passing the response i receive to
> another method, which parses the stream to do additional work....hence i
> want it to be open. Later we are explcitly closing the stream...
> 
> Here is my code snippet :: 
> HttpPool : 
> 
>       public void init()
>       {
>               ThreadSafeClientConnManager mgr  = new 
> ThreadSafeClientConnManager();
>               mgr.setDefaultMaxPerRoute(MAX_CONNECTION_PERHOST);
>               mgr.setMaxTotal(HTTP_CONNECTIONPOOL_SIZE);
>               mgr.closeIdleConnections(CONNECTION_IDLE_TIME*1000L, 
> TimeUnit.MINUTES);
>               client = new DefaultHttpClient(mgr);
>               //  
> client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
> DefaultHttpRequestRetryHandler(1,false));
>               
> client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT,new
> Integer(SO_TIMEOUT*60*1000)); 
> 
>       }
> 
> 
> Code which uses this : 
> 
> HttpPost postMethod =
> createPostMethod(PropertyHandler.getStringProperty("URL"));
>               try {
>               HttpEntity requestEntity = new StringEntity(wrdJaxbString);  // 
> This is an
> XML marshlled to String
>               postMethod.setEntity(requestEntity);
>                       HttpResponse status = client.execute(postMethod);       
>                 
>       
>       /* Does not work :(  */
>                       EofSensorWatcher watcher  = new 
> BasicEofSensorWatcher(new
> BasicPooledConnAdapter(httpConnectionPoolMgr.getMgr(), new BasicPoolEntry
>                                       (new 
> DefaultClientConnectionOperator(new SchemeRegistry()), new
> HttpRoute(new HttpHost("hostname")))) , false );
>                       EofSensorInputStream result = new
> EofSensorInputStream(status.getEntity().getContent(), watcher);
>       /* Does not work :(  */
> 
>                       response = status.getEntity().getContent();
>                       } catch (IOException e) {}
>                       finally {
>                       postMethod.abort();             
>                       }
>                       return response;
> 
> This is a REST call, the response is sent to another module for further
> processing of the stream 
> 
> 

I still do not understand.

InputStream instance obtained from the response HttpEntity is
self-contained and is perfectly capable of deallocating all underlying
resources (such as pooled HTTP connection) by itself. Why do you need to
mess with EOF sensors and such? Just pass that input stream to the other
(processing, I assume) module and just make sure it always closes the
stream once it is done processing it. Resource deallocation will happen
automatically when InputStream#close() is executed.

Hope this helps

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to