Thank you Sergey,

another option also worked perfectly. only difference between the 2 options
are :

with my approach(using HttpResponse), browser shows complete XML file (with
nodes also). where as by using Response object as you mentioned below, it
only shows content(values) of XML file I am feeding. but both the options
 sent entire XML file in response body perfectly if you check response
content in browser using a tool like firebug.

Thanks again.

Regards,
Parimal

On Wed, Nov 18, 2009 at 3:27 PM, Sergey Beryozkin <[email protected]>wrote:

> Hi
>
> This is one possible option, another one is to return a Response :
>
> return Response.status(200).entity(theInputStream).build()
>
> cheers, Sergey
>
> -----Original Message-----
> From: Parimal Dhinoja [mailto:[email protected]]
> Sent: 18 November 2009 19:46
> To: [email protected]
> Subject: Re: Exception : getWriter() has already been called for this
> response
>
> Thanks Sergey,
>
> I have given a try with JAX-RS and I am able to return my XML file. I
> have
> created a resource class where I defined a method. This method get
> HttpResponse object from MessageContext, read XML file from file system
> and
> then feeding  it to HttpResponse outputstream. Please let me know if it
> is
> ok.
>
> Also How can I use JAX-RS response object to accomplish the same task?
>
> Regards,
> Parimal
>
> On Wed, Nov 18, 2009 at 7:50 AM, Sergey Beryozkin
> <[email protected]>wrote:
>
> > Hi
> >
> >
> >  Thank you so much Sergey for prompt reply and the links.
> >>
> >> I agree that JAX-RS might be more appropriate solution to my problem.
> >>
> >> But I still has a query about Response object. As you see, I need to
> read
> >> the phisical XML files that are stored on file system and based on
> user
> >> query parameter, I need to read one of those files and feed into
> Response
> >> stream.
> >>
> >> As per my understanding, jax-rs return xml response of the pojo class
> you
> >> have defined.
> >>
> >
> > Not necessarily - you can return an input stream pointing to your xml
> file.
> > If you return a jaxrs Response from your method then you can also set
> the
> > required content type to be associated with a given input stream..
> >
> > Also, I'm not sure about the other question you posted in the
> follow-up
> > message. Apparently you;re using a deprected CXF HTTP binding - I can
> not
> > help there, I was not even involved in that project. Please consider
> using
> > either JAXWS support for doing HTTP services or migrate to JAXRS
> >
> > thanks, Sergey
> >
> >
> >
> >> so Please let me know, what I have implemented to return my physical
> xml
> >> file, is correct and whether it will work. I have to get HttpResponse
> from
> >> MessageContext and feed my xml file into response's body.
> >>
> >> As I said, I am new to CXF and may be there are better solutions to
> the
> >> problem I have which I am not aware of. It would be great if you
> suggest
> >> specific to my problem on hand.
> >>
> >> Again, I really appreciate you help.
> >>
> >> Regards,
> >> Parimal
> >>
> >>
> >>
> >> On Tue, Nov 17, 2009 at 4:16 PM, Sergey Beryozkin
> <[email protected]
> >> >wrote:
> >>
> >>  Hi
> >>>
> >>>
> >>> Thank you Sergey,
> >>>
> >>>>
> >>>> Yes it seems working. now I haven't got any exception. but I am not
> >>>> verifying it. Actually following is my code in impl. I am sending
> xml
> >>>> file
> >>>> in Httpresponse stream. and I do not know if anything will add to
> >>>> response
> >>>> or overwrite by further interceptor process. I am using this
> service
> >>>> from
> >>>> browser. Please let me know what I am doing is right way of doing
> it. I
> >>>> am
> >>>> beginner to CXF REST.
> >>>>
> >>>>
> >>> this is a JAXWS code but you can do REST with it if you'd like to.
> You'd
> >>> probably want to use Provider<Source> though, see
> >>>
> >>>
> >>>
> >>>
> http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/
> samples/restful_dispatch/
> >>>
> >>> alternatively, please consider using JAXRS
> >>>
> >>> http://cxf.apache.org/docs/jax-rs.html
> >>>
> >>> hope it helps, Sergey
> >>>
> >>>
> >>>
> >>>  @WebService(endpointInterface =
> >>>> "com.traveltripper.stargazer.service.impl.HelloWorld")
> >>>> public class HelloWorldImpl implements HelloWorld
> >>>> {
> >>>>
> >>>>  private static final Log log =
> LogFactory.getLog(HelloWorldImpl.class);
> >>>>
> >>>>  @Resource
> >>>>  private WebServiceContext context;
> >>>>
> >>>>  public void getHi()
> >>>>  {
> >>>>     try
> >>>>      {
> >>>>          MessageContext ctx = context.getMessageContext();
> >>>>          HttpServletRequest request =   (HttpServletRequest)
> >>>> ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
> >>>>          HttpServletResponse response =  (HttpServletResponse)
> >>>> ctx.get(AbstractHTTPDestination.HTTP_RESPONSE);
> >>>>          response.setContentType("text/xml");
> >>>>          String reqParameter =
> request.getParameter("propertyCode");
> >>>>          String filePath = "c://"+ "DEL10965261change.xml";
> >>>>
> >>>>          FileInputStream fis = new FileInputStream(new
> File(filePath));
> >>>>
> >>>>          BufferedInputStream bis = new BufferedInputStream(fis);
> >>>>          ServletOutputStream sos = response.getOutputStream();
> >>>>          byte[] buffer = new byte[5000];
> >>>>          response.setHeader("Content-Length:",
> >>>> String.valueOf(bis.available()));
> >>>>          log.info("Content-length=" + bis.available());
> >>>>          while (true)
> >>>>          {
> >>>>              int bytesRead = bis.read(buffer, 0, buffer.length);
> >>>>              if (bytesRead < 0) break;
> >>>>              sos.write(buffer, 0, bytesRead);
> >>>>          }
> >>>>          fis.close();
> >>>>          sos.flush();
> >>>>          sos.close();
> >>>>
> >>>>      }
> >>>>      catch (Exception e)
> >>>>      {
> >>>>          e.getMessage();
> >>>>      }
> >>>>
> >>>>  }
> >>>> }
> >>>>
> >>>> On Mon, Nov 16, 2009 at 3:40 PM, Sergey Beryozkin <
> >>>> [email protected]
> >>>>
> >>>>  wrote:
> >>>>>
> >>>>>
> >>>>
> >>>>  Hi
> >>>>>
> >>>>> Please try writing to response.getOutputStream() and it should
> work. I
> >>>>> missed overriding
> >>>>> response.getWriter()  in the HttpResponse context implementation.
> >>>>>
> >>>>> let me know please if it works
> >>>>> Sergey
> >>>>>
> >>>>>
> >>>>> Parimal Dhinoja wrote:
> >>>>> >
> >>>>> > Hi,
> >>>>> >
> >>>>> > I have implemented RESTful CXF service with my spring project.
> in
> >>>>> impl
> >>>>> > class, I have used MessageContext to retrieve HttpResponse and I
> am
> >>>>> using
> >>>>> > response.getWriter() to set HttpResponse with my content.
> >>>>> >
> >>>>> > when I call this service from browser, I get the response what I
> have
> >>>>> set
> >>>>> > in
> >>>>> > impl, but on tomcat console, I am getting following exception.
> Please
> >>>>> > help.
> >>>>> > this is the last piece of work I have left to finish my task.
> >>>>> >
> >>>>> > 16-Nov-2009 13:47:31 org.apache.cxf.phase.PhaseInterceptorChain
> >>>>> > doIntercept
> >>>>> > WARNING: Interceptor has thrown exception, unwinding now
> >>>>> > java.lang.IllegalStateException: getWriter() has already been
> called
> >>>>> for
> >>>>> > this response
> >>>>> >  at
> >>>>> >
> >>>>>
> >>>>>
> org.apache.catalina.connector.Response.getOutputStream(Response.java:579
> )
> >>>>> > at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFac
> ade.java:183)
> >>>>> >  at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> javax.servlet.ServletResponseWrapper.getOutputStream(ServletResponseWrap
> per.java:102)
> >>>>> > at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abstr
> actHTTPDestination.java:482)
> >>>>> >  at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStrea
> m.onFirstWrite(AbstractHTTPDestination.java:546)
> >>>>> > at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutpu
> tStream.java:61)
> >>>>> >  at
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(UTF8Out
> putStreamWriter.java:94)
> >>>>> >
> >>>>> > --
> >>>>> > Regards,
> >>>>> > Parimal
> >>>>> > "Nothing is stationary,Change is a part of Life"
> >>>>> >
> >>>>> >
> >>>>>
> >>>>> --
> >>>>> View this message in context:
> >>>>>
> >>>>>
> >>>>>
> http://old.nabble.com/Exception-%3A-getWriter%28%29-has-already-been-cal
> led-for-this-response-tp26378624p26379082.html
> >>>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>> --
> >>>> Regards,
> >>>> Parimal
> >>>> "Nothing is stationary,Change is a part of Life"
> >>>>
> >>>>
> >>>>
> >>
> >> --
> >> Regards,
> >> Parimal
> >> "Nothing is stationary,Change is a part of Life"
> >>
> >>
> >
>
>
> --
> Regards,
> Parimal
> "Nothing is stationary,Change is a part of Life"
>



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

Reply via email to