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. 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(ResponseFacade.java:183) >>> > at >>> > >>> >>> javax.servlet.ServletResponseWrapper.getOutputStream(ServletResponseWrapper.java:102) >>> > at >>> > >>> >>> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:482) >>> > at >>> > >>> >>> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:546) >>> > at >>> > >>> >>> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:61) >>> > at >>> > >>> >>> com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(UTF8OutputStreamWriter.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-called-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"
