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.