您可以通过注入HttpServletRequest来访问 Spring SOAP Endpoint 中的 HTTP 标头。
例如,您需要获取Autorization标头(您使用基本身份验证)。
SOAP 请求:
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)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tok="http://abcdef.com/integration/adapter/services/Token">
<soapenv:Header/>
<soapenv:Body>
<tok:GetTokenRequest>
</tok:GetTokenRequest>
</soapenv:Body>
</soapenv:Envelope>
@Endpoint Java 类
@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);
}
}