2016-04-05 6 views
-1

Spring-WSで書かれたSOAP Webサービスクライアントがあります。ログオン要求に応答して、私が接続するWebサービスは、トークンを含むHTTPレスポンスヘッダーにセッションクッキーを返します。その後のサービス呼び出しでは、トークンを持つCookieが必要です。レスポンスからセッションクッキーを取得し、それをサービスへの後続のコールでHTTPヘッダーに追加するにはどうすればよいですか?spring-ws soap WebサービスクライアントでhttpセッションCookieを取得しています

私が尋ねることを要約すると、どのようにしてSpring-WSでCookieを抽出して注入しますか?ここで

は、私は、Webサービスを呼び出すために使用していますどのようなコードの抜粋です:

MySessionLogon api = new MySessionLogon(); 
    api.setUsername(username); 
    api.setPassword(password); 

    MySessionLogonResponse response = (MySessionLogonResponse) getWebServiceTemplate() 
      .marshalSendAndReceive(
        "http://myserver/soapservice.asmx", 
        api, 
        new SoapActionCallback("http://www.myserver.com/MySession_Logon")); 

    return response; 

私はインターネットを検索し、私は必要なものに近いように見えるものをたくさん読みましたが、私は使用する必要があるクッキーの価値を得る良い方法を見ていません。どのような助けもありがとうございます、事前に感謝します。

答えて

0

WebServiceMessageExtractorにチェックを入れましたか?

あなたは応答VirtualTrollのため、次の

MySessionLogonResponse response = (MySessionLogonResponse) getWebServiceTemplate() 
      .sendAndReceive(
        "http://myserver/soapservice.asmx", 
        api, 
        new SoapActionCallback("http://www.myserver.com/MySession_Logon"), 
new WebServiceMessageExtractor<ResponseAndHeader>() { 
    public ResponseAndHeader extractData(WebServiceMessage message) throws IOException { 
    TransportContext context = TransportContextHolder.getTransportContext(); 
    HttpComponentsConnection con = (HttpComponentsConnection) context.getConnection(); 
    httpResponse httpResponse = con.getHttpResponse(); 
    //use the method getHeaders from to retrieve the data you want  
    }); 
+0

感謝を行うことができます。ちょうどメモ、marshalSendAndReceiveは、あなたの応答に示されているように4つのパラメータを受け入れていません。 WebServiceTemplateが提供する他のSendAndReceiveメソッドの1つを使用する必要があると思います。 – Woody

+0

私の答えを更新しました。ソリューションを使用して問題を解決できましたか? – VirtualTroll

+0

長い間遅れて申し訳ありませんが、私は別のルートに行くことで私の問題を解決しました。私はhttp://stackoverflow.com/questions/25189129/spring-ws-client-set-cookie-for-authenticationに似たソリューションを、およびを参照してください。私がそのように行かなかったとしても、あなたの意見をもう一度おねがいします。 @VirtualTroll – Woody

関連する問題