Hi

I have created a Rest service using CXF 3.0.0 milestone1 and I am trying to
get the body of the HTTP response in an Out Interceptor in phase SEND and
put it in a String variable without having the logging feature enabled in
the xml configuration file.

Here is my interceptor code:

public void handleMessage(Message message) throws Fault {
    BAprintHouse.setFunction("MyLoginOutInterceptor.handleMessage()");

    OutputStream os = message.getContent(OutputStream.class);
    StringBuilder responsePayload = new StringBuilder();
    CachedOutputStream cos = (CachedOutputStream) os;
    Exchange ex = message.getExchange();
    try {
        cos.writeCacheTo(responsePayload);
    } catch (IOException e) {
        BAprintHouse.log("ERROR", "IO Error:" + e.getMessage());
    }
}

With the code above I successfully put the response body into the
"responsePayload" variable. 

The problem is that when i remove the 

<jaxrs:features>
    <cxf:logging/>
</jaxrs:features>

from my xml file then I get the exception below

java.lang.ClassCastException:
org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream
cannot be cast to org.apache.cxf.io.CachedOutputStream
    at
com.test.interceptors.MyLoginOutInterceptor.handleMessage(MyLoginOutInterceptor.java:35)
    at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
    at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
    at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
    at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
    at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
    at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
    at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
    at
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:168)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:722)

The exception occurs in the line CachedOutputStream cos =
(CachedOutputStream) os;

Is there any way to get the response body from the message and that it will
work with or without the <cxf:logging/> in place?

Thanks



--
View this message in context: 
http://cxf.547215.n5.nabble.com/How-to-get-http-response-body-in-an-Out-Interceptor-without-the-logging-feature-enabled-tp5742153.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to