Thanks guys,

Sergey, can you provide any link or document for the last option(prototype
one) you suggested?

Also if I want to send multiple XML files in response, what will be the good
solution? at present, I am getting HttpServletResponse object stream in my
service implementation and feed all files streams one by one.

I also tried returning File object from service which works well if there is
only single file to send in response.

Regards,
Parimal

On Mon, Nov 30, 2009 at 3:43 PM, Sergey Beryozkin <[email protected]>wrote:

> Hi
>
> Thanks, this is one option, so registering an out interceptor at one of
> the stages which follows MARSHAL (POST_MARSHAL or MARSHAL_ENDING) should
> work.
>
> However, just returning an InputStream should result in it being closed
> after it's been copied to the output stream. BinaryDataProvider closes
> InputStream after the copy has been completed.
>
> Another option is to register a prototype-scope resource class and have
> a @PreDestroy method on this class...
>
> Cheers, Sergey
>
>
>
> -----Original Message-----
> From: vickatvuuch [mailto:[email protected]]
> Sent: 30 November 2009 18:22
> To: [email protected]
> Subject: Re: how to close inputStream before returning response
>
>
> You can take a look at one of the out interceptors that handle the
> response.
> I would start somewhere around JAXRSOutInterceptor and go from there.
>
>
> Parimal Dhinoja wrote:
> >
> > Hi All,
> >
> > Following is my service method where I am reading file and feed it
> into
> > Response object.  Even if I try to close my file streams in finally
> block,
> > I
> > didn't receive any file back in response. if I remove stream closing
> > statements from finally block, I am getting my file in response body
> when
> > checked in browser. Can someone please let me know how I can close my
> > streams or does it will close automatically after Response object is
> > returned?
> >
> >
> > @GET
> >     @Path("/message1")
> >     public Response getMessage1(@QueryParam("propertyName")
> >     String propertyName)
> >     {
> >         String param = propertyName;
> >         String filePath = "I://abc.xml";
> >
> >         FileInputStream fis = null;
> >         BufferedInputStream bis = null;
> >         ResponseBuilder rs = null;
> >         Response response = null;
> >         try
> >         {
> >             fis = new FileInputStream(new File(filePath));
> >             bis = new BufferedInputStream(fis);
> >             rs = Response.status(200).entity(bis);
> >             response = rs.build();
> >             // bis.close();
> >             // fis.close();
> >         }
> >         catch (Exception e)
> >         {
> >             LOGGER.info(e.getMessage());
> >         }
> >         finally
> >         {
> >             try
> >             {
> >                 if (bis != null)
> >                 {
> >                     bis.close();
> >                     LOGGER.info("===>bis is closed");
> >                 }
> >                 if (fis != null)
> >                 {
> >                     fis.close();
> >                 }
> >             }
> >             catch (Exception e)
> >             {
> >                 LOGGER.info("Exception occured while closing
> streams");
> >             }
> >         }
> >         // return Response.status(200).entity(bis).build();
> >         return response;
> >
> >     }
> >
> > --
> > Regards,
> > Parimal
> > "Nothing is stationary,Change is a part of Life"
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/how-to-close-inputStream-before-returning-response
> -tp26578495p26579444.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>


-- 
Regards,
Parimal
"Nothing is stationary,Change is a part of Life"

Reply via email to