java – 将自定义请求marshallers提交给JAXRSClientFactory

我正在尝试使用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);
上一篇:java – Apache CXF动态客户端创建


下一篇:c# – prolog异常中不允许的内容