2016-07-04 5 views
0

私が使用してRESTのWebサービスを消費しています()URL:このURLにのApache CXF - などのjaxrsクライアントスプリングの設定(プロキシを注入)

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

WSは、ユーザーsecuredcodeを返します。

目標:

私は私の春のWebアプリケーションに、このレストWSを統合したいです。だから私のJaxRSクライアントserviceclassとアドレスは、コンテキストxmlにあるはずですか?

見つけてください下に私の仮定:あなたは春のファイルは、あなたが使用することもでき、この

<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 interface RestClient{ 

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

のようなプロキシクラスを必要とする

<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> 
+0

デザインを再検討してください。クエリパラメータとしてユーザー名とパスワードを送信するのは良い考えではありません。 –

答えて

4

サーバ側のインタフェース

public class RestClientImpl implements RestClient{ 
    public String getUserSecureCode(String username , String password){ 
     //doSomething... 
     return userSecureCode 
    } 
} 
関連する問題