Мне нужна небольшая помощь с использованием apache axis2 и модуля Rampart, я пытаюсь использовать клиент, но я застрял с ошибкой
Исключение в потоке «main» java.lang.RuntimeException: Undefined «Пространство имен политики безопасности не может быть нулевым». свойство ресурса в org.apache.rampart.RampartException.getMessage(RampartException.java:81) в org.apache.rampart.RampartException.(RampartException.java:41) в org.apache.rampart.RampartException.(RampartException.java:57) ) в org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:387) в org.apache.rampart.RampartMessageData.(RampartMessageData.java:261) в org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61) ) в org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65) в org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340) в org.apache.axis2.engine.Phase. invoke(Phase.java:313) в org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262) в org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:427) в org.apache .axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406) в org.apache.axis2.description.OutInAxisOperationCl ient.executeImpl(OutInAxisOperation.java:229) в org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) в axis2.services.SimpleServiceStub.sumar(SimpleServiceStub.java:189) в axis2client.Application1.( Application1.java:96) в axis2client.Application1.main(Application1.java:192) Процесс завершился с кодом выхода 1.
Это исходный код моего клиента веб-сервиса:
public Application1() throws Exception {
SimpleServiceStub stub;
try {
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:\\AESPANA\\Axis2Test\\Axis2Client\\src\\axis2conf\\SimpleServiceConf",null);
stub = new SimpleServiceStub(ctx,"http://172.17.24.147:8995/Axis2Service/services/SimpleService?wsdl");
ServiceClient client=stub._getServiceClient();
client.engageModule("rampart");
RampartConfig rampartConfig=getRampartConfig();
out_sec_policy.addAssertion(rampartConfig);
client.getOptions().setProperty(RampartMessageData.KEY_RAMPART_OUT_POLICY, out_sec_policy);
stub._setServiceClient(client);
System.out.println("Llamando Cliente");
SimpleServiceStub.Sumar sum1=new SimpleServiceStub.Sumar();
sum1.setA(2);
sum1.setB(3);
System.out.println("Ejecutandolo Cliente");
SimpleServiceStub.SumarResponse response1=stub.sumar(sum1);
System.out.println(response1);
} catch (AxisFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
private Policy loadPolicy(String name) throws XMLStreamException {
InputStream resource;
try {
resource = new FileInputStream(name);
StAXOMBuilder builder = new StAXOMBuilder(resource);
return PolicyEngine.getPolicy(builder.getDocumentElement());
} catch (FileNotFoundException e) {
// TODO
}
return null;
}
private RampartConfig getRampartConfig(){
RampartConfig rampartConfig = new RampartConfig();
rampartConfig.setPwCbClass("axis2client.SimpleServicePWCBHandle");
CryptoConfig sigCrypto = new CryptoConfig();
sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
Properties props = new Properties();
props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
props.setProperty("org.apache.ws.security.crypto.merlin.file","C:\\AESPANA\\Axis2Test\\Axis2Client\\src\\axis2conf\\SimpleServiceConf\\keys\\client.jks");
props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", "apache");
sigCrypto.setProp(props);
rampartConfig.setSigCryptoConfig(sigCrypto);
rampartConfig.setEncrCryptoConfig(sigCrypto);
Policy policy = new Policy();
return rampartConfig;
}
public static void main(String[] args) throws Exception {
new Application1();
}}
Это файл policy.xml для клиента.
<wsp:Policy wsu:Id="PoliticaOperacion"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802">
<wsp:ExactlyOne>
<wsp:All>
<sp:AsymmetricBinding>
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:RecipientToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:TripleDesRsa15/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:AsymmetricBinding>
<sp:Wss10>
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
</wsp:Policy>
</sp:Wss10>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
Services.xml это.
<serviceGroup>
<service name="SimpleService"
targetNamespace="http://ws.apache.org/axis2/samples/book/"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802">
<module ref="rampart"/>
<description>SimpleService</description>
<schema schemaNamespace="http://ws.apache.org/axis2/samples/book/xsd/"/>
<parameter name="ServiceClass" locked="false">axis2service.SimpleService</parameter>
<operation name="sumar">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
<parameter name="InflowSecurity">
<action>
<passwordCallbackClass>axis2service.SimpleServiceHandler</passwordCallbackClass>
<signaturePropFile>service.properties</signaturePropFile>
<signatureKeyIdentifier>DirectReference</signatureKeyIdentifier>
</action>
</parameter>
<wsp:PolicyAttachment xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:AppliesTo>
<policy-subject identifier="binding:soap11/operation:sumar/in"/>
<policy-subject identifier="binding:soap12/operation:sumar/in"/>
</wsp:AppliesTo>
<wsp:Policy wsu:Id="PoliticaOperacion">
<wsp:ExactlyOne>
<wsp:All>
<sp:AsymmetricBinding>
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:RecipientToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:TripleDesRsa15/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:AsymmetricBinding>
<sp:Wss10>
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
</wsp:Policy>
</sp:Wss10>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</wsp:PolicyAttachment>
</service>
</serviceGroup>
Это файл WSDL
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns="http://ws.apache.org/axis2/samples/book/xsd/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://ws.apache.org/axis2/samples/book/" targetNamespace="http://ws.apache.org/axis2/samples/book/">
- <wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="PoliticaOperacion">
- <wsp:ExactlyOne>
- <wsp:All>
- <sp:AsymmetricBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802">
- <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
- <sp:InitiatorToken>
- <wsp:Policy>
- <sp:X509Token>
- <wsp:Policy>
<sp:WssX509V3Token10 />
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
- <sp:RecipientToken>
- <wsp:Policy>
- <sp:X509Token>
- <wsp:Policy>
<sp:WssX509V3Token10 />
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:RecipientToken>
- <sp:AlgorithmSuite>
- <wsp:Policy>
<sp:TripleDesRsa15 />
</wsp:Policy>
</sp:AlgorithmSuite>
- <sp:Layout>
- <wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp />
<sp:OnlySignEntireHeadersAndBody />
</wsp:Policy>
</sp:AsymmetricBinding>
- <sp:Wss10 xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802">
- <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<sp:MustSupportRefKeyIdentifier />
</wsp:Policy>
</sp:Wss10>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:documentation>SimpleService</wsdl:documentation>
- <wsdl:types>
- <xs:schema targetNamespace="http://ws.apache.org/axis2/samples/book/xsd/" attributeFormDefault="qualified" elementFormDefault="qualified">
- <xs:element name="sumar">
- <xs:complexType>
- <xs:sequence>
<xs:element name="a" minOccurs="0" type="xs:int" />
<xs:element name="b" minOccurs="0" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="sumarResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element name="return" minOccurs="0" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
- <wsdl:message name="sumarRequest">
<wsdl:part name="parameters" element="ns:sumar" />
</wsdl:message>
- <wsdl:message name="sumarResponse">
<wsdl:part name="parameters" element="ns:sumarResponse" />
</wsdl:message>
- <wsdl:portType name="SimpleServicePortType">
- <wsdl:operation name="sumar">
<wsdl:input message="tns:sumarRequest" wsaw:Action="urn:sumar" />
<wsdl:output message="tns:sumarResponse" wsaw:Action="urn:sumarResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="SimpleServiceSoap11Binding" type="tns:SimpleServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="sumar">
<soap:operation soapAction="urn:sumar" style="document" />
- <wsdl:input>
<wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="#PoliticaOperacion" />
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="SimpleServiceSoap12Binding" type="tns:SimpleServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="sumar">
<soap12:operation soapAction="urn:sumar" style="document" />
- <wsdl:input>
<wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="#PoliticaOperacion" />
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="SimpleServiceHttpBinding" type="tns:SimpleServicePortType">
<http:binding verb="POST" />
- <wsdl:operation name="sumar">
<http:operation location="sumar" />
- <wsdl:input>
<mime:content type="application/xml" part="parameters" />
</wsdl:input>
- <wsdl:output>
<mime:content type="application/xml" part="parameters" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="SimpleService">
- <wsdl:port name="SimpleServiceHttpSoap11Endpoint" binding="tns:SimpleServiceSoap11Binding">
<soap:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="SimpleServiceHttpSoap12Endpoint" binding="tns:SimpleServiceSoap12Binding">
<soap12:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="SimpleServiceHttpEndpoint" binding="tns:SimpleServiceHttpBinding">
<http:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Мой класс обслуживания это
public class SimpleService {
public int sumar(int a, int b){
return a+b;
}
}
Может кто-нибудь помочь мне, пожалуйста, я не знаю, как это решить. есть идеи, друзья?