Hi
Please see comments below,
On 21/01/14 17:01, David wrote:
I think this is more of a Camel question than a CXF question, but let me
know if that's not the case (would it have been bad form to cross-post this
to cxf-user?).

I have questions regarding use of Jackson with CXF, as well as how to get
CXFRS not to wrap the root value of a JSON payload.

I am trying to use Camel and CXF as part of a service orchestration using
JSON over REST. My biggest question is how to configure cxfrs to use
Jackson for all JSON marshal/unmarshal operations.

So far, I've configured a cxf:rsServer and added a cxf:providers element
with a reference to a org.codehaus.jackson.jaxrs.JacksonJsonProvider bean.
I've also added the following to my route, although I haven't found
anywhere to reference it yet:

     <dataFormats>
         <json library="Jackson" id="jack"/>
     </dataFormats>

I'm basically exposing the configured cxf:rsServer service as an external
entry-point:

<cxf:rsServer id="processService" address="http://localhost:8182";
serviceClass="org.my.Service"
loggingFeatureEnabled="true">
<cxf:providers>
<ref component-id="jsonProvider" />
</cxf:providers>
</cxf:rsServer>
<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />

I'm then using a couple cxfrs producer endpoints to invoke external
REST/JSON services implemented using RESTEasy:

         <setHeader headerName="CamelHttpMethod">
             <simple>POST</simple>
         </setHeader>
         <setHeader headerName="CamelHttpPath">
             <simple>/service1/operation1</simple>
         </setHeader>
         <setHeader headerName="Content-Type">
             <simple>application/json</simple>
         </setHeader>
         <to uri="cxfrs:http://localhost:8080?exchangePattern=InOut"/>
         <setHeader headerName="CamelHttpMethod">
             <simple>POST</simple>
         </setHeader>
         <setHeader headerName="CamelHttpPath">
             <simple>/service2/operation2</simple>
         </setHeader>
         <setHeader headerName="Content-Type">
             <simple>application/json</simple>
         </setHeader>
         <to uri="cxfrs:http://localhost:8080?exchangePattern=InOut"/>


The idea is that each of those services will modify the payload, and the
resulting object will be passed back to the caller.

The services themselves are pretty standard. Class annotated with @Path,
along with a single method annotated with @POST, @Consumes and @Produces
(both types are set to MediaType.APPLICATION_JSON). The methods expect and
return a single container class with id and a couple string values.

When I call my service, however, an exception is thrown by the code that's
attempting to call the cxfrs producer endpoint, saying there's no message
body writer for my container class and applicaiton/json. At one point I had
it working (not sure what was different back then) and I was running into
issues where the CXF client code was wrapping the JSON payload (I.e.
{"classname": {"id": 1, ...}}), which the RESTEasy services didn't like. I
got around it by registering a custom ContextResolver for the RESTEasy
services that sets the WRAP_ROOT_VALUE feature on the Jackson object
mapper, and adding a @JsonRootName annotation to my container class, but
would prefer to solve the problem by telling the CXFRS client not to wrap
the root value. From looking at
http://camel.apache.org/schema/blueprint/cxf/camel-cxf-2.9.0.xsd, I see
that both rsServer and rsClient have a "features" element that I think
might allow me to do this, .but I can't find any documentation or examples
for using it.

I hope the above made sense, and thanks in advance for your help.

The client-side wrapper is added by the active JSON provider which is Jackson in this case. So one option is to configure org.codehaus.jackson.jaxrs.JacksonJsonProvider directly in Spring to drop a root element - that should be possible. Can you try it ?

By the way, how complex the actual sequence is ? The other alternative can be to use CXF JSONProvider (Jettison-based) - it is quite flexible in the way it can shape the sequence

Sergey



Reply via email to