How can I access HTTP headers in Spring-ws endpoint?
My code looks like this:
public class MyEndpoint extends AbstractMarshallingPayloadEndpoint {
You can access to HTTP headers in Spring SOAP Endpoint by injecting HttpServletRequest.
For example, you need to get Autorization header (you use Basic authentication).
SOAP request:
POST http://localhost:8025/ws HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Basic YWRtaW46YWRtaW4=
Content-Length: 287
Host: localhost:8025
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
@Endpoint java class
@Endpoint
@Slf4j
public class TokenEndpoint {
public static final String NAMESPACE_URI = "http://abcdef.com/integration/adapter/services/Token";
private static final String AUTH_HEADER = "Authorization";
private final HttpServletRequest servletRequest;
private final TokenService tokenService;
public TokenEndpoint(HttpServletRequest servletRequest, TokenService tokenService) {
this.servletRequest = servletRequest;
this.tokenService = tokenService;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "GetTokenRequest")
@ResponsePayload
public GetTokenResponse getToken(@RequestPayload GetTokenRequest request) {
String auth = servletRequest.getHeader(AUTH_HEADER);
log.debug("Authorization header is {}", auth);
return tokenService.getToken(request);
}
}