Hi Rice, The error said that you try to use Jetty Response in Writer mode (getWriter()), although it was originally opened in stream mode (getOutputStream()). Generally I am not sure that setting headers and content directly in Response is a good idea - this makes your code fragile and dependent on internal CXF implementation.
Why don't release your resources in JX-RS Filter (http://cxf.apache.org/docs/jax-rs-filters.html) or Interceptor (http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Interceptors)? Regards, Andrei. > -----Original Message----- > From: Rice Yeh [mailto:[email protected]] > Sent: Samstag, 14. Mai 2016 09:48 > To: [email protected] > Subject: Error handling in out interceptor in jaxrs > > Hi, > I write a outward interceptor and put it after JAXRSOutInterceptor to clean > up some resouces. When cleaning up the resources, there might be some > exceptions happening. Then I directly set the HttpServletResponse's headers > and content to send back an appropriate response. This works even there is > a IllegalStateException thrown when later cxf's jaxrs implementation try flush > http headers to the HttpServletResponse like below. Any more appropriate > way to achieve my goal without this exception? > > 2016-05-13T16:58:36.514 [qtp1980982961-89] WARN > o.a.cxf.phase.PhaseInterceptorChain - Interceptor for { > http://rs.security.xs/}Resource has thrown exception, unwinding now > > java.lang.IllegalStateException: WRITER > > at org.eclipse.jetty.server.Response.getOutputStream(Response.java:906) > ~[na:na] > > at > org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abstra > ctHTTPDestination.java:585) > [cxf-rt-transports-http-2.7.11.jar:2.7.11] > > at > org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStre > am.close(AbstractHTTPDestination.java:743) > ~[cxf-rt-transports-http-2.7.11.jar:2.7.11]
