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"