最简单的方法是从 SOAP 标头中提取用户名和密码,方法是将其指定为 JAX-WS 方法的参数:
@WebMethod
public String performAction( @WebParam(name="credentials", header=true)
Credentials credentials,
@WebParam( name="...")....
您还可以创建一个 SOAPHandler:
public class AuthenticationHandler implements SOAPHandler<SOAPMessageContext>
{
//Implement appropriate methods here
}
这是在 standard-jaxws-endpoint-config.xml 中注册的:
<jaxws-config xmlns="urn:jboss:jaxws-config:2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="urn:jboss:jaxws-config:2.0 jaxws-config_2_0.xsd">
<endpoint-config>
<config-name>WebService Endpoint</config-name>
<pre-handler-chains>
<javaee:handler-chain>
<javaee:protocol-bindings>##SOAP11_HTTP</javaee:protocol-bindings>
<javaee:handler>
<javaee:handler-name>AuthHandler</javaee:handler-name>
<javaee:handler-class>com.example.AuthenticationHandler</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</pre-handler-chains>
</endpoint-config>
</jaxws-config>