如何使用Apache CXF JAX-RS客户端WebService



他们在这里说,有三种方法可以在apachecxf-中构建rest客户端

我的问题是:

1) 我遵循第一种方法-注入代理,我遗漏了什么吗?

2) 如何使用apachecxf-spring配置来使用jax-rs-webservice(安全签名证书)?

Web服务url:

 http://localhost:8080/services/userSvc/getUserInfo?param1=value1&param2=value2"

UserInfoSvc.java:

   // What code should be written here

application-context.xml:

  <jaxrs:client id="restClient"
     address="http://localhost:8080/services/userSvc/getUserInfo"
     serviceClass="com.example.client.UserInfoSvc"
     inheritHeaders="true">
     <jaxrs:headers>
         <entry key="Accept" value="text/json"/>
     </jaxrs:headers>

您可以使用http管道在application-context.xml 中为客户端指定证书

<http:conduit name="*.http-conduit">
    <http:tlsClientParameters>
        <sec:keyManagers keyPassword="${ssl.keystorepassword}">
            <sec:keyStore type="JKS" password="${ssl.keystorepassword}"
                file="${ssl.keystorefile}" />
        </sec:keyManagers>
        <sec:cipherSuitesFilter>
            <sec:include>.*_EXPORT_.*</sec:include>
            <sec:include>.*_EXPORT1024_.*</sec:include>
            <sec:include>.*_WITH_DES_.*</sec:include>
            <sec:include>.*_WITH_AES_.*</sec:include>
            <sec:include>.*_WITH_NULL_.*</sec:include>
            <sec:exclude>.*_DH_anon_.*</sec:exclude>
        </sec:cipherSuitesFilter>
    </http:tlsClientParameters>
    <http:authorization>
    </http:authorization>
    <http:client AutoRedirect="true" Connection="Keep-Alive" />
</http:conduit>

注意:在我的情况下,http管道应用于所有服务,因为我使用name="*.http-conduit",您可以自定义为使用sepcifc服务或代理。有关详细信息,请参阅此处

http和sec的命名空间是

xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security"

最新更新