Hi Sergey, just to let you know that restoring the InputStream it works. Thanks Gaetano
On 22 July 2013 23:00, Gaetano Ciotola <[email protected]> wrote: > Hi Sergey, > thanks for your suggestion. I'll try and I'll let you know. > Anyway the method that I "posted" in my previous email was just an example > to keep the things easy. The filter has not just for logging purposes > What I really need to do in the filter is to calculate the MD5 of the > payload. > > Thanks and Regards > Gaetano > > > On 22 July 2013 21:41, Sergey Beryozkin <[email protected]> wrote: > >> Hi - Looks like you've consumed InputStream without restoring it - please >> do that and it should work, why don't you use CXF LoggingFeature ? >> >> Cheers, Sergey >> >> On 22/07/13 19:27, Gaetano Ciotola wrote: >> >>> Hello, >>> I have developed a simple web service using CXF JAX-RS. >>> I need to access to the plain json payload from the request >>> I have done some research and I decided to us JAX-RS Filter. >>> The filter's logic is really simple: retrieve the payload and write a >>> log. >>> >>> public class TestHandler implements RequestHandler >>> { >>> private static final Category logger = >>> Category.getInstance(**TestHandler.class); >>> @Override >>> public Response handleRequest(Message msg, ClassResourceInfo clsResInfo) >>> { >>> InputStream is = msg.getContent(InputStream.**class); >>> StringWriter writer = new StringWriter(); >>> try { >>> IOUtils.copy(is, writer, "utf-8"); >>> } catch (IOException e) { >>> e.printStackTrace(); >>> } >>> IOUtils.closeQuietly(is); >>> String body = writer.toString(); >>> logger.info(body); >>> >>> return null; >>> } >>> } >>> >>> The problem is that somehow the request get corrupted (i.e. the body get >>> removed) and when the Jettison start to process it, the following >>> exception get thrown: >>> >>> [7/22/13 18:41:36:305 BST] 00000024 WebApplicatio W >>> javax.ws.rs.**BadRequestException: javax.xml.stream.** >>> XMLStreamException: >>> Missing value. at character 27 of {"PaymentAuthorisationReq":} >>> at >>> org.apache.cxf.jaxrs.provider.**AbstractJAXBProvider.** >>> handleExceptionEnd(**AbstractJAXBProvider.java:671) >>> at >>> org.apache.cxf.jaxrs.provider.**AbstractJAXBProvider.** >>> handleXMLStreamException(**AbstractJAXBProvider.java:688) >>> at >>> org.apache.cxf.jaxrs.provider.**json.JSONProvider.readFrom(** >>> JSONProvider.java:248) >>> at >>> org.apache.cxf.jaxrs.utils.**JAXRSUtils.**readFromMessageBodyReader(** >>> JAXRSUtils.java:1288) >>> at >>> org.apache.cxf.jaxrs.utils.**JAXRSUtils.**readFromMessageBody(** >>> JAXRSUtils.java:1236) >>> at >>> org.apache.cxf.jaxrs.utils.**JAXRSUtils.processParameter(** >>> JAXRSUtils.java:787) >>> at >>> org.apache.cxf.jaxrs.utils.**JAXRSUtils.processParameters(** >>> JAXRSUtils.java:747) >>> at >>> org.apache.cxf.jaxrs.**interceptor.**JAXRSInInterceptor.** >>> processRequest(**JAXRSInInterceptor.java:240) >>> at >>> org.apache.cxf.jaxrs.**interceptor.**JAXRSInInterceptor.**handleMessage( >>> **JAXRSInInterceptor.java:100) >>> 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.** >>> doPost(AbstractHTTPServlet.**java:163) >>> at javax.servlet.http.**HttpServlet.service(**HttpServlet.java:738) >>> at >>> org.apache.cxf.transport.**servlet.AbstractHTTPServlet.** >>> service(AbstractHTTPServlet.**java:219) >>> at >>> com.ibm.ws.webcontainer.**servlet.ServletWrapper.** >>> service(ServletWrapper.java:**1657) >>> at >>> com.ibm.ws.webcontainer.**servlet.ServletWrapper.** >>> handleRequest(ServletWrapper.**java:939) >>> at >>> com.ibm.ws.webcontainer.**servlet.ServletWrapper.** >>> handleRequest(ServletWrapper.**java:502) >>> at >>> com.ibm.ws.webcontainer.**servlet.ServletWrapperImpl.**handleRequest(** >>> ServletWrapperImpl.java:179) >>> at com.ibm.ws.webcontainer.**webapp.WebApp.handleRequest(** >>> WebApp.java:3826) >>> at com.ibm.ws.webcontainer.**webapp.WebGroup.handleRequest(** >>> WebGroup.java:276) >>> at com.ibm.ws.webcontainer.**WebContainer.handleRequest(** >>> WebContainer.java:931) >>> at >>> com.ibm.ws.webcontainer.**WSWebContainer.handleRequest(** >>> WSWebContainer.java:1583) >>> at >>> com.ibm.ws.webcontainer.**channel.WCChannelLink.ready(** >>> WCChannelLink.java:186) >>> at >>> com.ibm.ws.http.channel.**inbound.impl.HttpInboundLink.** >>> handleDiscrimination(**HttpInboundLink.java:445) >>> at >>> com.ibm.ws.http.channel.**inbound.impl.HttpInboundLink.** >>> handleNewRequest(**HttpInboundLink.java:504) >>> at >>> com.ibm.ws.http.channel.**inbound.impl.HttpInboundLink.**processRequest( >>> **HttpInboundLink.java:301) >>> at >>> com.ibm.ws.http.channel.**inbound.impl.HttpInboundLink.** >>> ready(HttpInboundLink.java:**275) >>> at >>> com.ibm.ws.tcp.channel.impl.**NewConnectionInitialReadCallba** >>> ck.sendToDiscriminators(**NewConnectionInitialReadCallba**ck.java:214) >>> at >>> com.ibm.ws.tcp.channel.impl.**NewConnectionInitialReadCallba** >>> ck.complete(**NewConnectionInitialReadCallba**ck.java:113) >>> at >>> com.ibm.ws.tcp.channel.impl.**AioReadCompletionListener.** >>> futureCompleted(**AioReadCompletionListener.**java:165) >>> at >>> com.ibm.io.async.**AbstractAsyncFuture.**invokeCallback(** >>> AbstractAsyncFuture.java:217) >>> at >>> com.ibm.io.async.**AsyncChannelFuture.**fireCompletionActions(** >>> AsyncChannelFuture.java:161) >>> at com.ibm.io.async.AsyncFuture.**completed(AsyncFuture.java:**138) >>> at com.ibm.io.async.**ResultHandler.complete(**ResultHandler.java:204) >>> at >>> com.ibm.io.async.**ResultHandler.**runEventProcessingLoop(** >>> ResultHandler.java:775) >>> at com.ibm.io.async.**ResultHandler$2.run(**ResultHandler.java:905) >>> at com.ibm.ws.util.ThreadPool$**Worker.run(ThreadPool.java:**1563) >>> Caused by: javax.xml.stream.**XMLStreamException: Missing value. at >>> character >>> 27 of {"PaymentAuthorisationReq":} >>> at >>> org.codehaus.jettison.mapped.**MappedXMLInputFactory.** >>> createXMLStreamReader(**MappedXMLInputFactory.java:51) >>> at >>> org.codehaus.jettison.**AbstractXMLInputFactory.**createXMLStreamReader( >>> **AbstractXMLInputFactory.java:**116) >>> at >>> org.codehaus.jettison.**AbstractXMLInputFactory.**createXMLStreamReader( >>> **AbstractXMLInputFactory.java:**103) >>> at >>> org.apache.cxf.jaxrs.provider.**json.utils.JSONUtils.** >>> createStreamReader(JSONUtils.**java:157) >>> at >>> org.apache.cxf.jaxrs.provider.**json.JSONProvider.** >>> createReader(JSONProvider.**java:273) >>> at >>> org.apache.cxf.jaxrs.provider.**json.JSONProvider.** >>> createReader(JSONProvider.**java:263) >>> at >>> org.apache.cxf.jaxrs.provider.**json.JSONProvider.readFrom(** >>> JSONProvider.java:221) >>> ... 40 more >>> Caused by: org.codehaus.jettison.json.**JSONException: Missing value. at >>> character 27 of {"PaymentAuthorisationReq":} >>> at org.codehaus.jettison.json.**JSONTokener.syntaxError(** >>> JSONTokener.java:463) >>> at org.codehaus.jettison.json.**JSONTokener.nextValue(** >>> JSONTokener.java:356) >>> at org.codehaus.jettison.json.**JSONObject.<init>(JSONObject.**java:199) >>> at >>> org.codehaus.jettison.mapped.**MappedXMLInputFactory.**createJSONObject( >>> **MappedXMLInputFactory.java:59) >>> at >>> org.codehaus.jettison.mapped.**MappedXMLInputFactory.** >>> createXMLStreamReader(**MappedXMLInputFactory.java:44) >>> ... 46 more >>> >>> During my investigation I have added a second filter (that is exactly the >>> copy of the existing one) and debugging, I can see that when the request >>> get caught by the second filter, the body is empty....As said it seems >>> that the logic in the first filter "consumes the request's body" >>> >>> Note - if in the filter I just do retrieve the InputStreem all works >>> fine >>> public Response handleRequest(Message msg, ClassResourceInfo clsResInfo) >>> { >>> InputStream is = msg.getContent(InputStream.**class); >>> return null; >>> } >>> Possibly is something really simple that I'm missing >>> >>> Any help would be really appreciated >>> >>> Thanks and Regards >>> Gaetano >>> >>> >> >> -- >> Sergey Beryozkin >> >> Talend Community Coders >> http://coders.talend.com/ >> >> Blog: http://sberyozkin.blogspot.com >> > > > > >
