我希望在将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");
}
}
答案 0 :(得分:0)
Metro文档Client Side Schema Validation介绍了如何执行此操作:
需要使用SchemaValidationFeature创建代理才能启用 客户端验证。传出SOAP请求和传入 SOAP响应将被验证。
例4.9。使用模式验证启用代理
import com.sun.xml.ws.developer.SchemaValidationFeature; ... SchemaValidationFeature feature = new SchemaValidationFeature(); HelloPort port = new HelloService.getHelloPort(feature); // All invocations on this port are validated