我在 Eclipse 中创建了带有壁垒 ws 安全性的 axs 2 Web 服务(这是我遵循的 教程 TUTORIAL PAGE - 18-21
我通过添加此代码和参与 RAMPART MODULE 在 service.xml 中应用了该策略
<wsp:Policy wsu:Id="UTOverTransport"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:SignedSupportingTokens
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:passwordCallbackClass>axis2wstest.PWCBHandler</ramp:passwordCallbackClass>
</ramp:RampartConfig>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
然后我创建 Web 服务客户端 - 这是代码
public static void main(String[] args) throws RemoteException {
ConfigurationContext ctx;
ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Users/Tanya/workspace/testlnclient/WebContent/WEB-INF", null);
TestlnStub stub = new TestlnStub(ctx);
Testws cl = new Testws();
cl.setX(5);
ServiceClient client = stub._getServiceClient();
client.engageModule("rampart");
//client.addHeader(omSecurityElement);
org.apache.axis2.client.Options o = client.getOptions();
o.setPassword("pass");
o.setUserName("test");
TestwsResponse resp = stub.testws(cl);
System.out.println("Response" + resp.get_return());
// TODO Auto-generated method stub
}
}
但它给了我一个例外
exception in thread "main" org.apache.axis2.AxisFault: java.lang.NullPointerException
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
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 axis2wstest.TestlnStub.testws(TestlnStub.java:191)
at axis2wstest.testlnclient.main(testlnclient.java:35)