我正在尝试使用Rampart创建安全的Web服务服务器和客户端。 Web服务服务器已成功创建。但是当我创建客户端时,我在NoSuchMethodError
中获得了ServiceClient.engageModule("rampart")
。
这是我的客户端代码:
public static void main(String arg[]) throws Exception
{
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("E:\\axis2-1.6.2\\repository", "E:\\axis2-1.6.2\\conf\\axis2.xml");
TestStub stub = new TestStub(ctx,"http://localhost:8080/Axis2WS/services/Test");
ServiceClient sc = stub._getServiceClient();
Options options = sc.getOptions();
options.setUserName("test");
options.setPassword("pass");
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy("policy.xml"));
sc.engageModule("rampart");
Test test = new Test();
test.setA(1);
stub.test(test);
stub.addWS();
}
private static Policy loadPolicy(String xmlPath) throws FileNotFoundException, XMLStreamException{
StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
return PolicyEngine.getPolicy(builder.getDocumentElement());
}
消息错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.axiom.soap.SOAPFaultClassifier.getValueAsQName()Ljavax/xml/namespace/QName;
at org.apache.rampart.util.RampartUtil.isSecurityFaultCode(RampartUtil.java:1929)
at org.apache.rampart.util.RampartUtil.isSecurityFault(RampartUtil.java:1919)
at org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:306)
at org.apache.rampart.RampartEngine.process(RampartEngine.java:73)
at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:168)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.ex.TestStub.test(TestStub.java:204)
at com.ex.service.testWS.main(testWS.java:39)
This是我使用的政策。 谢谢你的帮助。