Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXRS client can't find message body writer

I have a jaxrs client configured like this:

<jaxrs:client id="opaRestProxy" name="opaRestProxy"
        address="${endpoint}" serviceClass="com.test.RestProxy"
        inheritHeaders="true" threadSafe="true">
        <jaxrs:headers>
            <entry key="Accept" value="application/json" />
            <entry key="Content-Type" value="application/json" />
        </jaxrs:headers>
    </jaxrs:client>

But when I send a request I get the following exception:

Caused by: org.apache.cxf.interceptor.Fault: .No message body writer has been found for class : class com.test.RequestObject, ContentType : application/json.
    at org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:646)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:527)
    ... 47 more

My RestProxy class looks like this:

@Component
public interface RestProxy {

  @POST
  @Path("/getSomething")
  String getSomething(RequestObject RequestObject);
}
like image 939
wvp Avatar asked Mar 19 '23 02:03

wvp


1 Answers

If you are using Jackson JSON library you need to add these xml tags to your application context.

<jaxrs:providers>
<bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</jaxrs:providers>

If you are using any other library add that bean to the providers tag. Hope that helps!

like image 173
saibharath Avatar answered Mar 28 '23 22:03

saibharath