Hi Marcus,
I have tested the code. It is working fine.
Thanks a lot.
Regards
Arnab
M.C.S. wrote:
>
> Hi Arnab,
>
> now I guess I realize your problem. I even just read the JavaDoc of
> HttpClient version 4, which says "Closing the input stream will trigger
> connection release". So with this up2date version you won't have any
> problems.
>
> If you really need to close the connection yourself and/or you don't
> want to upgrade, subclassing StreamingResolution should help. Design
> your subclass to hold the HttpClient (or whatever you need to release
> the connection). A very simple approach (untested code):
>
> ************************************************************************
>
> public class HttpClientStreamingResolution extends StreamingResolution {
>
> private GetMethod getMethod;
>
> public HttpClientStreamingResolution(
> String contentType,
> GetMethod getMethod) {
> // calling super constructor
> super(contentType, getMethod.getResponseBodyAsStream());
> this.getMethod = getMethod;
> }
>
> @Override
> protected void stream(HttpServletResponse response) throws Exception {
> super.stream(response);
> getMethod.releaseConnection();
> }
> }
>
> ************************************************************************
>
> Regards
> Marcus
>
>
> arnab_ghosh schrieb:
>> Hi Marcus,
>>
>> Thanks once again for such prompt reply.
>> I understood the the stream will be closed. But this HttpClient creates a
>> connection for fetching the response. It says that the connection should
>> be
>> released, once response is read.
>>
>> I will provide you the code snippet for your help:
>> try {
>> GetMethod getMethod = new GetMethod(assetURL);
>> int statusCode = httpClient.executeMethod(getMethod);
>>
>> log.info("statusCode : {}", statusCode);
>>
>> // Wrap the InputStream in a BufferedInputStream
>> bufferedInputstream = new
>> BufferedInputStream(getMethod.getResponseBodyAsStream());
>>
>> // Get the content type of the file
>> contentType =
>> getMethod.getResponseHeader("content-type").getValue();
>> log.info("The contentType : {}", contentType);
>>
>> // Create a StreamingResolution with inputStream
>> streamingResolution = new StreamingResolution(contentType,
>> bufferedInputstream);
>>
>> } catch (IOException ioEx) {
>> log.error("Error occurred: " + ioEx.getMessage(), ioEx);
>> } finally {
>>
>> getMethod.releaseConnection(); // This line if presently closes
>> the
>> Stream abruptly
>> }
>>
>> // 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;
>>
>> execute method will close the Stream but how will the connection be
>> released?
>>
>>
>>
>> Regards
>> Arnab
>>
>> M.C.S. wrote:
>>
>>> Hi Arnab,
>>>
>>> arnab_ghosh wrote:
>>>
>>>> I have used HttpClient for getting the InputStream from a web service.
>>>> Will
>>>> the StreamingResolution also release the connection?
>>>>
>>>>
>>> after streaming the StreamingResolution will close any InputStream you
>>> pass on to it. It does not matter where you obtained the stream.
>>>
>>> Regards
>>> Marcus
>>>
>>> ------------------------------------------------------------------------------
>>> This SF.net email is sponsored by:
>>> SourcForge Community
>>> SourceForge wants to tell your story.
>>> http://p.sf.net/sfu/sf-spreadtheword
>>> _______________________________________________
>>> Stripes-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>>
>>>
>>>
>>
>>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
--
View this message in context:
http://www.nabble.com/File-Download-in-Stripes-using-HttpClient-tp21558239p21563132.html
Sent from the stripes-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users