Spring -ws Access SoapHeader fields in endpoint method

We are developing the first WebService contract using spring-ws 2.2.0. We are trying to manage authentication using a special tag with a name AuthTokenlocated in SoapHeader. AuthTokenhas the following structure:

<authToken>
    <username>USERNAME</xa:username>
    <password>PASSWORD</xa:password>
</authToken>

We can create a WSDL scheme containing the specified user authentication tag inside SoapHeader. The problem is that when a client makes a call to our server, we cannot untie the AuthToken tag (located in SoapHeader) in our Ws Endpoint implementation.

Using the annotation @RequestPayloadin the signature of the binding method ( handleMethodRequestas indicated in the example below), we can access the unmarshaled payload content (located in SoapBody). We tried to do the same with SoapHeader content without success. In the following code examples, we will show you what we would like to receive:

1
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, @SoapHeader(value = "authToken") AuthToken authToken) { }

2
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, AuthToken authToken) { }

3
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, org.springframework.ws.soap.SoapHeader header) { }

4
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "methodRequest")
@ResponsePayload
public MethodResponse handleMethodRequest(@RequestPayload MethodRequest request, MessageContext messageContext) { }

In case 1, 2 we get the following error:

No adapter for endpoint [MethodResponse EndpointImplementation.handleMethodRequest(MethodRequest, AuthToken) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

In the case of 3, 4, we have no errors, but we cannot process the SoapHeader or MessageContext (in case of 3 and 4, respectively) to achieve our goals, referring to AuthTokenthe username and password sub-element.

, , , , Spring Interceptors . "", AuthToken . , AuthToken handleMethodRequest , , , handleMethodRequest. , handleMethodRequest.

- , ? .

+4
2

@SoapHeader SoapHeaderElement. Spring -WS unmarshalling headers.

+6

handleMethodRequest ThreadLocal. , , handleMethodRequest,

ThreadLocal.set(AuthToken); // in interceptor.
ThreadLocal.get();// in handler and then clear it after use.

, , @SoapHeader(value = "{authToken") }, ?

0

All Articles