hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: FileDownload using HttpClient
Date Tue, 20 Jan 2009 19:30:37 GMT
arnab_ghosh wrote:
> Hi,
> 
> I am using HttpClient for generating a FileDownLoad. 
> Let me give a small explanation of the scenario.
> 
> I have Webservice which returns me a file as an InputStream. I am using
> Stripes as the Web Framework.
> Here goes the code:
> 
>        .....Other code
>        try {
>              HttpClient httpClient = new HttpClient();
>              GetMethod getMethod = new GetMethod(assetURL);
>              bufferedInputstream = new
> BufferedInputStream(getMethod.getResponseBodyAsStream());
>       } catch (Exception e) {
>       } finally {
>              getMethod.releaseConnection();
>       }
>       StreamingResolution streamingResolution = new
> StreamingResolution(contentType, bufferedInputstream);
>     
>     // set the fileName in the StreamingResolution.This in turn sets the
> appropriate response header.
>     streamingResolution.setFilename(fileName + "." + extension)
> 
>     // return the FileInputStream wrapped in the resolution
>     return streamingResolution;
> 
> The problem I am facing is, If i close the connection in the finally block,
> it throws IOException: Tring to read from an already closed Stream.
> 
> So can you tell me when will be the correct time to close the connection?
> 

That is what HTTP connection manager is for.

Oleg

What is the correct way for FileDownload via HTTPClient?
> 
> Can you help?


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