HI
I think the problem is that you have

@Produces( { "application/json", "application/xml" })

but what you return is XML (as a String). The method has an Object
return type so in the end it looks like a PrimitiveProvider ends up
writing it - not sure why NPE is thrown in IOUtils - possibly because
Object confuses the provider. Can you update the method to return
String ? I'll add a test to make sure returning Object does not
'upset' PrimitiveProvider...

Cheers, Sergey

On Mon, Apr 25, 2011 at 7:37 PM, jaybytez <jayby...@yahoo.com> wrote:
> I have a simple layer that proxies a WCM and the Service Endpoints.  Since it
> is easier to deal with JSON, I was going to provide a thin layer where the
> WCM could utilize JSON to submit requests to JAX-RS and internally I would
> invoke SOAP/HTTP service calls.  So CXF(JAX-RS) for receiving requests and
> CXF(JAX-WS) for making the requests.
>
> It all appears to work as I am seeing the service message go out, and I see
> the service message come back in, the data binding is working, and I am able
> to log the object model before JAX-RS returns it.  But when JAX-RS returns
> it...the IOUtils throws an NPE.
>
> Am I missing something in configuring the JAX-RS Response as json?
>
> Thanks...jay
>
> JAX-RS Method
> --------------------------------
>    @GET
>    @Path("/servicecode/{id}")
>    @Produces( { "application/json", "application/xml" })
>    @Consumes("text/plain")
>    public Object getSponsorLookupCodes(@PathParam("id") String serviceCode)
> {
>        System.out.println("serviceCode - " + serviceCode);
>        XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
>        xstream.alias(ServiceCode.class.getSimpleName(), ServiceCode.class);
>        ServiceCode code =
> serviceCodeLookupBusinessService.getServiceCode(serviceCode);
>        System.out.println("code - " + code);
>        System.out.println("json code - " + xstream.toXML(code));
>        return xstream.toXML(code);
>    }
>
> JAX-RS Server Configuration
> --------------------------------
>        <jaxrs:server id="wcmResourceApps" address="/">
>
>                <jaxrs:extensionMappings>
>                <entry key="json" value="application/json"/>
>                <entry key="xml" value="application/xml"/>
>        </jaxrs:extensionMappings>
>                <jaxrs:serviceBeans>
>                        <ref bean="codeLookupBusinessResource"/>
>                </jaxrs:serviceBeans>
>        </jaxrs:server>
>
>
> JAX-WS Successful Send
> --------------------------------
> ID: 3
> Address: https://foo.com/CodeLookupBusinessService
> Encoding: UTF-8
> Content-Type: text/xml
> .......
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";><soap:Body><ns3:getCode
> xmlns:ns2="http://foo.com/model/cas";
> xmlns:ns3="http://foo.com/services/cas";><ns3:Code>12345</ns3:Code></ns3:getCode></soap:Body></soap:Envelope>
> --------------------------------------
> Apr 25, 2011 11:10:32 AM
> org.apache.cxf.interceptor.AbstractLoggingInterceptor log
> INFO: Inbound Message
> ----------------------------
>
>
> JAX-WS Successful Receive
> --------------------------------
> ID: 3
> Response-Code: 200
> Encoding: UTF-8
> Content-Type: text/xml; charset=UTF-8
> .......
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";><soap:Body><ns3:getCodeResponse
> xmlns:ns2="http://foo.com/model/cas";
> xmlns:ns3="http://foo.com/services/cas";><ns2:Code><ns2:EffectiveDate>20050101</ns2:EffectiveDate><ns2:ExpirationDate>99991231</ns2:ExpirationDate><ns2:Id>12345</ns2:Id></ns2:Code></ns3:getCodeResponse></soap:Body></soap:Envelope>
> --------------------------------------
>
> System.out.println Statements
> --------------------------------
> code - com.foo.Code@10b2839f[
>  effectiveDate=20050101
>  expirationDate=99991231
>  fromAgeLimit=<null>
>  id=12345
>  toAgeLimit=<null>
> ]
> json code - {"ServiceCode": {
>  "effectiveDate": "20050101",
>  "expirationDate": "99991231",
>  "id": "12345"
> }}
>
> JAX-RS NullPointerException
> --------------------------------
> java.lang.NullPointerException
>        at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:126)
>        at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:103)
>        at
> org.apache.cxf.io.DelegatingInputStream.cacheInput(DelegatingInputStream.java:54)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:305)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:519)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:531)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:524)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:659)
>        at
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:42)
>        at
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:55)
>        at
> org.apache.cxf.jaxrs.provider.PrimitiveTextProvider.writeTo(PrimitiveTextProvider.java:70)
>        at
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:256)
>        at
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:144)
>        at
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:83)
>        at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
>        at
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
>        at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
>        at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113)
>        at
> org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:97)
>        at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:461)
>        at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
>        at
> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:148)
>        at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
>        at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>        at
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
>        at
> com.day.j2ee.servletengine.ServletRuntimeEnvironment.service(ServletRuntimeEnvironment.java:228)
>        at
> com.day.j2ee.servletengine.RequestDispatcherImpl.doFilter(RequestDispatcherImpl.java:315)
>        at
> com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:334)
>        at
> com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:378)
>        at
> com.day.j2ee.servletengine.ServletHandlerImpl.execute(ServletHandlerImpl.java:313)
>        at
> com.day.j2ee.servletengine.DefaultThreadPool$DequeueThread.run(DefaultThreadPool.java:134)
>        at java.lang.Thread.run(Thread.java:619)
> Apr 25, 2011 11:10:32 AM
> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor
> writeResponseErrorMessage
> WARNING: Error serializing the response, please check the server logs,
> response class : String.
> Apr 25, 2011 11:10:32 AM org.apache.cxf.phase.PhaseInterceptorChain
> doDefaultLogging
> WARNING: Interceptor for
> {http://facade.apps.foo.com/}CodeLookupBusinessResource has thrown
> exception, unwinding now
> java.lang.NullPointerException
>        at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:126)
>        at org.apache.cxf.helpers.IOUtils.copy(IOUtils.java:103)
>        at
> org.apache.cxf.io.DelegatingInputStream.cacheInput(DelegatingInputStream.java:54)
>        at
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:305)
>
> --
> View this message in context: 
> http://cxf.547215.n5.nabble.com/IOUtils-throws-NullPointerException-JAX-RS-Response-tp4338982p4338982.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Reply via email to