如何在 Metro/WebLogic 11g 中启用 JAX-WS 客户端验证

How to enable JAX-WS client side validation in Metro / WebLogic 11g

我想在将 SOAP 消息发送到端点之前启用客户端验证。

如何在 WebLogic 10.3.6 / Metro 提供商的客户端应用程序 运行 中启用它,最好使用 JAX-WS API?

Metro 版本为 JAX-WS RI 2.1.6 in JDK 6

这是我的 JAX-WS 客户端的示例代码:

@WebService
public class Client {

    @WebServiceRef(wsdlLocation = "RemoteService.wsdl")
    private RemoteService_Service service;

    public void call() throws Exception {

        RemoteService port = service.getRemoteServicePort();

        // configures authentication
        auth(port);

        // builds request
        Request request = new Request();
        request.setValue(null); // this field is mandatory in server

        // client must validate and raise an exception
        port.someOperation(request);

    }

    protected void auth(RemoteService port) {
        Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
        requestContext.put(BindingProvider.USERNAME_PROPERTY, "changeit");
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, "changeit");
    }
}

Metro 文档Client Side Schema Validation 描述了如何操作:

Proxy needs to be created with SchemaValidationFeature to enable client side validation. Both the outgoing SOAP request and incoming SOAP response will be validated.

Example 4.9. Enabling Proxy with Schema Validation

import com.sun.xml.ws.developer.SchemaValidationFeature;
...

SchemaValidationFeature feature = new SchemaValidationFeature();
HelloPort port = new HelloService.getHelloPort(feature);
// All invocations on this port are validated