I am trying to invoke my RESTful service using JAXRSClientFactory - and I'm stuck with supplying configuration for request/response mappings types (I need to serialize List)
The code looks like this:
JAXRSClientFactory.create("http://localhost:8080/", MyCoolService.class, "/path/to/client/config.xml");
the config.xml looks like:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
">
<jaxrs:client id="testClient" createdFromAPI="true">
<jaxrs:providers>
<bean class="my.provider.Class"/>
</jaxrs:providers>
</jaxrs:client>
</beans>
now when debugging client code, I can see that within org.apache.cxf.jaxrs.provider.ProviderFactory there is the call
MessageBodyWriter<T> mw = chooseMessageWriter(messageWriters,
bodyType,
parameterType,
parameterAnnotations,
mediaType,
m);
however messageWriters doesn't contain my provider. What is wrong with my code and how to provide MessageBodyWriter correctly? Thanks in advance!
Basically the problem was related to createdFromAPI="true"
So I got rid of the XML file and used specialized version of JAXRSClientFactory, which accepts list of message body providers as method parameter
If there is the need to provide basic authentication - then
ClientConfiguration config = WebClient.getConfig(proxy);
HTTPConduit conduit = (HTTPConduit) config.getConduit();
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName(USERNAME);
authorizationPolicy.setPassword(PASSWORD);
conduit.setAuthorization(authorizationPolicy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With