Nicholas
Nicholas

Reputation: 7521

CXF Rest Client not handling my Objects

I'm create a CXF client proxy using JAXRSClientFactory, from an interface of my RESTful web service.

My interface represents CRUD operations, so my create takes in an custom Object and create a DB entry from it. When I pass my object to the create method, I would get this:

org.apache.cxf.jaxrs.client.ClientWebApplicationException: org.apache.cxf.interceptor.Fault: .No message body writer has been found for class : class com.example.Calss, ContentType : application/json.

I resolved this by adding a provider list with JacksonJsonProvider to the JAXRSClientFactory.create method, which resolved marshalling the object.

Then I attempted to perform the Read operation, which returns a Response object who's entity is a custom Object. When I attempt to read, I get this error:

org.apache.cxf.jaxrs.client.ClientWebApplicationException: .Problem with reading the response message, class : class javax.ws.rs.core.Response, ContentType : application/json.

I can resolve this by removing the provider from my JAXRSClientFactory.create, but this causes the Create operation to fail.

I cannot seem to resolve this issue(while using the same client object). Has anyone else encountered this? What am I doing wrong?

Upvotes: 4

Views: 10173

Answers (1)

Nicholas
Nicholas

Reputation: 7521

This issue stems from using Jackson as the JSON mapper. On my interface definition, I'm returning a Response object, which Jackson/CXF doesn't know how to handle, so Jackson doesn't write it.

The solution was this:

JacksonJsonProvider provider = new JacksonJsonProvider();
provider.addUntouchable(Response.class);
providerList.add(provider);         
webService = JAXRSClientFactory.create(url, IWebService.class, providerList);

Upvotes: 5

Related Questions