0

I'm using this code to login to an external system :

    LoginResponse response = (LoginResponse) webServiceTemplate.marshalSendAndReceive(myRequest, new WebServiceMessageCallback() {

        public void doWithMessage(WebServiceMessage message) {
                    ((SoapMessage)message).setSoapAction("http://www.system.com//Authentication/Login");
            }
        });

I receive a type of LoginResponse but it is of no value.

LoginResponse type just contains :

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "LoginResponse", namespace = "http://www.system.com/Authentication/")
public class LoginResponse {


}

I require accessing a UserAuth value from the header but this is not contained within the LoginResponse object.

The SOAP response is :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <UserAuth xmlns="http://www.system.com/ws/">
         <Value>234234k234jl2k</Value>
      </UserAuth>
   </soap:Header>
   <soap:Body>
      <LoginResponse xmlns="http://www.system.com/Authentication"/>
   </soap:Body>
</soap:Envelope>

How can I access the header information, in this case the UserAuth value ?

Do I need to use something at a lower level and parse the required value from the soap response ?

Update :

I think I will need to use a custom SOAP request using SAAJ (something similar to SOAP request to WebService with java) and process the response.

My understanding is that although the soap header within the response is optional most clients when using SOAP use the header to send authentication type information ? Perhaps the wsdl or the mechanism of generating the .class files is incorrect and so the response is not filling out all required field(s) , in this case the soap header.

Community
  • 1
  • 1
blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

1

I assume that the information from the UserAuth header that you receive in the response to the login operation needs to be sent as a SOAP header (potentially identical to the received header) in subsequent requests to the service. If that's the case, then you should create a custom ClientInterceptor and register it in your WebServiceTemplate. That interceptor would extract the header from the login response, transform it (if necessary) and add it to subsequent requests.

Note that this interceptor would be stateful. Therefore you need to use a separate WebServiceTemplate instance for each conversation.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28