title: Axis2 and Rampart Module Client
body: <p>I need a litle help using apache axis2 and rampart module, i am trying to use a cliente but i am stuck with the error</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property
        at org.apache.rampart.RampartException.getMessage(RampartException.java:81)
        at org.apache.rampart.RampartException.(RampartException.java:41)
        at org.apache.rampart.RampartException.(RampartException.java:57)
        at org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:387)
        at org.apache.rampart.RampartMessageData.(RampartMessageData.java:261)
        at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
        at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
        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.send(AxisEngine.java:427)
        at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
        at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
        at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
        at axis2.services.SimpleServiceStub.sumar(SimpleServiceStub.java:189)
        at axis2client.Application1.(Application1.java:96)
        at axis2client.Application1.main(Application1.java:192)
    Process exited with exit code 1.</p>
  </blockquote>
  
  <p>This is the source code of my web sevice client:</p>
  
  <pre><code>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();
  }}
  </code></pre>
  
  <p>This is the policy.xml file for the client.</p>
  
  <pre><code>&lt;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"&gt;
      &lt;wsp:ExactlyOne&gt;
          &lt;wsp:All&gt;
              &lt;sp:AsymmetricBinding&gt;
                  &lt;wsp:Policy&gt;
                      &lt;sp:InitiatorToken&gt;
                          &lt;wsp:Policy&gt;
                              &lt;sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"&gt;
                                  &lt;wsp:Policy&gt;
                                      &lt;sp:WssX509V3Token10/&gt;
                                  &lt;/wsp:Policy&gt;
                              &lt;/sp:X509Token&gt;
                          &lt;/wsp:Policy&gt;
                      &lt;/sp:InitiatorToken&gt;
                      &lt;sp:RecipientToken&gt;
                          &lt;wsp:Policy&gt;
                              &lt;sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never"&gt;
                                  &lt;wsp:Policy&gt;
                                      &lt;sp:WssX509V3Token10/&gt;
                                  &lt;/wsp:Policy&gt;
                              &lt;/sp:X509Token&gt;
                          &lt;/wsp:Policy&gt;
                      &lt;/sp:RecipientToken&gt;
                      &lt;sp:AlgorithmSuite&gt;
                          &lt;wsp:Policy&gt;
                              &lt;sp:TripleDesRsa15/&gt;
                          &lt;/wsp:Policy&gt;
                      &lt;/sp:AlgorithmSuite&gt;
                      &lt;sp:Layout&gt;
                          &lt;wsp:Policy&gt;
                              &lt;sp:Strict/&gt;
                          &lt;/wsp:Policy&gt;
                      &lt;/sp:Layout&gt;
                      &lt;sp:IncludeTimestamp/&gt;
                      &lt;sp:OnlySignEntireHeadersAndBody/&gt;
                  &lt;/wsp:Policy&gt;
              &lt;/sp:AsymmetricBinding&gt;
              &lt;sp:Wss10&gt;
                  &lt;wsp:Policy&gt;
                      &lt;sp:MustSupportRefKeyIdentifier/&gt;
                  &lt;/wsp:Policy&gt;
              &lt;/sp:Wss10&gt;
          &lt;/wsp:All&gt;
      &lt;/wsp:ExactlyOne&gt;
  &lt;/wsp:Policy&gt;
  </code></pre>
  
  <p>The services.xml is this.</p>
  
  <pre><code>&lt;serviceGroup&gt;
      &lt;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"&gt;
          &lt;module ref="rampart"/&gt;
          &lt;description&gt;SimpleService&lt;/description&gt;
          &lt;schema schemaNamespace="http://ws.apache.org/axis2/samples/book/xsd/"/&gt;
          &lt;parameter name="ServiceClass" locked="false"&gt;axis2service.SimpleService&lt;/parameter&gt;
          &lt;operation name="sumar"&gt;
              &lt;messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/&gt;
          &lt;/operation&gt;
          &lt;parameter name="InflowSecurity"&gt;
              &lt;action&gt;
                  &lt;passwordCallbackClass&gt;axis2service.SimpleServiceHandler&lt;/passwordCallbackClass&gt;
                  &lt;signaturePropFile&gt;service.properties&lt;/signaturePropFile&gt;
                  &lt;signatureKeyIdentifier&gt;DirectReference&lt;/signatureKeyIdentifier&gt;
              &lt;/action&gt;
          &lt;/parameter&gt;
          &lt;wsp:PolicyAttachment xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"&gt;
              &lt;wsp:AppliesTo&gt;
                  &lt;policy-subject identifier="binding:soap11/operation:sumar/in"/&gt;
                  &lt;policy-subject identifier="binding:soap12/operation:sumar/in"/&gt;
              &lt;/wsp:AppliesTo&gt;
              &lt;wsp:Policy wsu:Id="PoliticaOperacion"&gt;
                  &lt;wsp:ExactlyOne&gt;
                      &lt;wsp:All&gt;
                          &lt;sp:AsymmetricBinding&gt;
                              &lt;wsp:Policy&gt;
                                  &lt;sp:InitiatorToken&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"&gt;
                                              &lt;wsp:Policy&gt;
                                                  &lt;sp:WssX509V3Token10/&gt;
                                              &lt;/wsp:Policy&gt;
                                          &lt;/sp:X509Token&gt;
                                      &lt;/wsp:Policy&gt;
                                  &lt;/sp:InitiatorToken&gt;
                                  &lt;sp:RecipientToken&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never"&gt;
                                              &lt;wsp:Policy&gt;
                                                  &lt;sp:WssX509V3Token10/&gt;
                                              &lt;/wsp:Policy&gt;
                                          &lt;/sp:X509Token&gt;
                                      &lt;/wsp:Policy&gt;
                                  &lt;/sp:RecipientToken&gt;
                                  &lt;sp:AlgorithmSuite&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:TripleDesRsa15/&gt;
                                      &lt;/wsp:Policy&gt;
                                  &lt;/sp:AlgorithmSuite&gt;
                                  &lt;sp:Layout&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:Strict/&gt;
                                      &lt;/wsp:Policy&gt;
                                  &lt;/sp:Layout&gt;
                                  &lt;sp:IncludeTimestamp/&gt;
                                  &lt;sp:OnlySignEntireHeadersAndBody/&gt;
                              &lt;/wsp:Policy&gt;
                          &lt;/sp:AsymmetricBinding&gt;
                          &lt;sp:Wss10&gt;
                              &lt;wsp:Policy&gt;
                                  &lt;sp:MustSupportRefKeyIdentifier/&gt;
                              &lt;/wsp:Policy&gt;
                          &lt;/sp:Wss10&gt;
                      &lt;/wsp:All&gt;
                  &lt;/wsp:ExactlyOne&gt;
              &lt;/wsp:Policy&gt;
          &lt;/wsp:PolicyAttachment&gt;
      &lt;/service&gt;
  &lt;/serviceGroup&gt;
  </code></pre>
  
  <p>This is the WSDL file</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  - &lt;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/"&gt;
  - &lt;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"&gt;
  - &lt;wsp:ExactlyOne&gt;
  - &lt;wsp:All&gt;
  - &lt;sp:AsymmetricBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802"&gt;
  - &lt;wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"&gt;
  - &lt;sp:InitiatorToken&gt;
  - &lt;wsp:Policy&gt;
  - &lt;sp:X509Token&gt;
  - &lt;wsp:Policy&gt;
    &lt;sp:WssX509V3Token10 /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:X509Token&gt;
    &lt;/wsp:Policy&gt;
    &lt;/sp:InitiatorToken&gt;
  - &lt;sp:RecipientToken&gt;
  - &lt;wsp:Policy&gt;
  - &lt;sp:X509Token&gt;
  - &lt;wsp:Policy&gt;
    &lt;sp:WssX509V3Token10 /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:X509Token&gt;
    &lt;/wsp:Policy&gt;
    &lt;/sp:RecipientToken&gt;
  - &lt;sp:AlgorithmSuite&gt;
  - &lt;wsp:Policy&gt;
    &lt;sp:TripleDesRsa15 /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:AlgorithmSuite&gt;
  - &lt;sp:Layout&gt;
  - &lt;wsp:Policy&gt;
    &lt;sp:Strict /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:Layout&gt;
    &lt;sp:IncludeTimestamp /&gt; 
    &lt;sp:OnlySignEntireHeadersAndBody /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:AsymmetricBinding&gt;
  - &lt;sp:Wss10 xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802"&gt;
  - &lt;wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"&gt;
    &lt;sp:MustSupportRefKeyIdentifier /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/sp:Wss10&gt;
    &lt;/wsp:All&gt;
    &lt;/wsp:ExactlyOne&gt;
    &lt;/wsp:Policy&gt;
    &lt;wsdl:documentation&gt;SimpleService&lt;/wsdl:documentation&gt; 
  - &lt;wsdl:types&gt;
  - &lt;xs:schema targetNamespace="http://ws.apache.org/axis2/samples/book/xsd/" attributeFormDefault="qualified" elementFormDefault="qualified"&gt;
  - &lt;xs:element name="sumar"&gt;
  - &lt;xs:complexType&gt;
  - &lt;xs:sequence&gt;
    &lt;xs:element name="a" minOccurs="0" type="xs:int" /&gt; 
    &lt;xs:element name="b" minOccurs="0" type="xs:int" /&gt; 
    &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  - &lt;xs:element name="sumarResponse"&gt;
  - &lt;xs:complexType&gt;
  - &lt;xs:sequence&gt;
    &lt;xs:element name="return" minOccurs="0" type="xs:int" /&gt; 
    &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
    &lt;/xs:schema&gt;
    &lt;/wsdl:types&gt;
  - &lt;wsdl:message name="sumarRequest"&gt;
    &lt;wsdl:part name="parameters" element="ns:sumar" /&gt; 
    &lt;/wsdl:message&gt;
  - &lt;wsdl:message name="sumarResponse"&gt;
    &lt;wsdl:part name="parameters" element="ns:sumarResponse" /&gt; 
    &lt;/wsdl:message&gt;
  - &lt;wsdl:portType name="SimpleServicePortType"&gt;
  - &lt;wsdl:operation name="sumar"&gt;
    &lt;wsdl:input message="tns:sumarRequest" wsaw:Action="urn:sumar" /&gt; 
    &lt;wsdl:output message="tns:sumarResponse" wsaw:Action="urn:sumarResponse" /&gt; 
    &lt;/wsdl:operation&gt;
    &lt;/wsdl:portType&gt;
  - &lt;wsdl:binding name="SimpleServiceSoap11Binding" type="tns:SimpleServicePortType"&gt;
    &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /&gt; 
  - &lt;wsdl:operation name="sumar"&gt;
    &lt;soap:operation soapAction="urn:sumar" style="document" /&gt; 
  - &lt;wsdl:input&gt;
    &lt;wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="#PoliticaOperacion" /&gt; 
    &lt;soap:body use="literal" /&gt; 
    &lt;/wsdl:input&gt;
  - &lt;wsdl:output&gt;
    &lt;soap:body use="literal" /&gt; 
    &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
  - &lt;wsdl:binding name="SimpleServiceSoap12Binding" type="tns:SimpleServicePortType"&gt;
    &lt;soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /&gt; 
  - &lt;wsdl:operation name="sumar"&gt;
    &lt;soap12:operation soapAction="urn:sumar" style="document" /&gt; 
  - &lt;wsdl:input&gt;
    &lt;wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="#PoliticaOperacion" /&gt; 
    &lt;soap12:body use="literal" /&gt; 
    &lt;/wsdl:input&gt;
  - &lt;wsdl:output&gt;
    &lt;soap12:body use="literal" /&gt; 
    &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
  - &lt;wsdl:binding name="SimpleServiceHttpBinding" type="tns:SimpleServicePortType"&gt;
    &lt;http:binding verb="POST" /&gt; 
  - &lt;wsdl:operation name="sumar"&gt;
    &lt;http:operation location="sumar" /&gt; 
  - &lt;wsdl:input&gt;
    &lt;mime:content type="application/xml" part="parameters" /&gt; 
    &lt;/wsdl:input&gt;
  - &lt;wsdl:output&gt;
    &lt;mime:content type="application/xml" part="parameters" /&gt; 
    &lt;/wsdl:output&gt;
    &lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
  - &lt;wsdl:service name="SimpleService"&gt;
  - &lt;wsdl:port name="SimpleServiceHttpSoap11Endpoint" binding="tns:SimpleServiceSoap11Binding"&gt;
    &lt;soap:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpSoap11Endpoint/" /&gt; 
    &lt;/wsdl:port&gt;
  - &lt;wsdl:port name="SimpleServiceHttpSoap12Endpoint" binding="tns:SimpleServiceSoap12Binding"&gt;
    &lt;soap12:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpSoap12Endpoint/" /&gt; 
    &lt;/wsdl:port&gt;
  - &lt;wsdl:port name="SimpleServiceHttpEndpoint" binding="tns:SimpleServiceHttpBinding"&gt;
    &lt;http:address location="http://http://172.17.24.150:8995/Axis2Service/services/SimpleService.SimpleServiceHttpEndpoint/" /&gt; 
    &lt;/wsdl:port&gt;
    &lt;/wsdl:service&gt;
    &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>My Service Class is this </p>
  
  <pre><code>public class SimpleService {
  
      public int sumar(int a, int b){
          return a+b;
      }
  }
  </code></pre>
  
  <p>Can anyone help me please, I dont know how to solved it. any idea friens?</p>