我正在尝试使用cxf连接到服务器,并且能够通过SOAP ui完成,但在尝试通过我正在编写的java程序进行连接时遇到错误。
String WSU_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
String SOAP_NS = "http://www.w3.org/2003/05/soap-envelope";
String WSS_EXT_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
String uri = "someURI";
String serviceName = "someServiceName";
String urlWSDL = "someUrlWsdl";
QName PORT_NAME = new QName(uri, serviceName);
URL url = new URL(urlWSDL);
AdminService service = new AdminService(url, PORT_NAME);
AdministrationSEI port = service.getAdminServicePort();
Client client = ClientProxy.getClient(port);
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, "Timestamp Signature");
outProps.put(WSHandlerConstants.USER, "someusername");
outProps.put(WSHandlerConstants.SIG_PROP_FILE, "resources/clientKeyStore.properties");
outProps.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, "com.java.UTPasswordCallback");
outProps.put(WSHandlerConstants.SIGNATURE_PARTS,
"{Content}{" + WSU_NS + "}Timestamp;"
+ "{Content}{" + SOAP_NS + "}Body;"
+ "{Content}{" + WSS_EXT_NS + "}BinarySecurityToken;");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
client.getOutInterceptors().add(wssOut);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(30000);
httpClientPolicy.setReceiveTimeout(7200000);
http.setClient(httpClientPolicy);
GetStatusType test = new GetStatusType();
test.setRequestID(requestID);
GetStatusResponseType response = port.getStatus(test);
我做错了什么?我已经看到很多例子,以这种方式将outProps添加到客户端。
我已尝试直接在客户端设置用户名,它让我超过了错误,但没有正确创建soap信封。
谢谢!
答案 0 :(得分:0)
问题是你正在混淆&#34;手册&#34;在CXF中配置WS-Security的方法 - 通过添加WSS4JOutInterceptor和策略驱动方法。后者适用于WSDL中有WS-SecurityPolicy的情况 - 这就是这种情况,因为stacktrace引用了自动添加的PolicyBasedWSS4JOutInterceptor。因此,对于策略方法,您不需要添加任何拦截器,而是添加一些配置安全性运行时所需的JAX-WS属性。有关更多信息,请参见此处:
http://cxf.apache.org/docs/ws-securitypolicy.html
科尔姆。