【问题标题】:Apache cxf - jaxrs client spring configuration ( Injecting proxies )Apache cxf - jaxrs 客户端 spring 配置(注入代理)
【发布时间】:2016-07-04 06:59:25
【问题描述】:

我正在使用(示例)网址使用 REST 网络服务,例如:

http://www.restsampleservice.com/api?username=tom&password=jerry

此 url 处的 ws 返回用户安全代码。

目标:

我想将此 Rest ws 集成到我的 Spring Web 应用程序中。那么我的 JaxRS 客户端服务类和地址应该如何在上下文 xml 中?

请在下面找到我的假设:

<jaxrs:client id="restClient"
       address=" http://www.restsampleservice.com/api?username=tom&password=jerry"
       serviceClass=?
       inheritHeaders="true">
       <jaxrs:headers>
           <entry key="Accept" value="text/plain"/>
       </jaxrs:headers>
</jaxrs:client>  

【问题讨论】:

  • 尝试重新考虑您的设计。将用户名和密码作为查询参数发送不是一个好主意。

标签: java web-services spring-mvc jax-rs cxf


【解决方案1】:

你需要一个这样的代理类

public interface RestClient{

    @GET
    @Path("/")
    public String getUserSecureCode( @QueryParam("username") String username ,@QueryParam("password") String password)
}

spring文件长这样

<jaxrs:client id="restClient"
   address="http://www.restsampleservice.com/api"
   serviceClass="test.RestClient"
   inheritHeaders="true">
   <jaxrs:headers>
       <entry key="Accept" value="text/plain"/>
   </jaxrs:headers>
</jaxrs:client> 

你也可以使用服务器端的接口

public class RestClientImpl implements RestClient{
    public String getUserSecureCode( String username , String password){
        //doSomething...
        return userSecureCode
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 2011-03-12
    相关资源
    最近更新 更多