我正在尝试使用JAXRSClientFactory调用我的RESTful服务-我陷入了为请求/响应映射类型提供配置的问题(我需要序列化List)

代码如下:

JAXRSClientFactory.create("http://localhost:8080/", MyCoolService.class, "/path/to/client/config.xml");

config.xml看起来像:
<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>

现在,在调试客户端代码时,我可以看到在org.apache.cxf.jaxrs.provider.ProviderFactory中存在调用
    MessageBodyWriter<T> mw = chooseMessageWriter(messageWriters,
                                                  bodyType,
                                                  parameterType,
                                                  parameterAnnotations,
                                                  mediaType,
                                                  m);

但是 messageWriters 不包含我的提供者。我的代码有什么问题,以及如何正确提供MessageBodyWriter?提前致谢!

最佳答案

基本上,问题与 createdFromAPI =“true” 有关

因此,我摆脱了XML文件,使用了JAXRSClientFactory的专用版本,该版本接受消息主体提供程序的列表作为方法参数。

如果需要提供基本身份验证-那么

    ClientConfiguration config = WebClient.getConfig(proxy);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
    authorizationPolicy.setUserName(USERNAME);
    authorizationPolicy.setPassword(PASSWORD);
    conduit.setAuthorization(authorizationPolicy);

10-08 10:51