title: Axis2 : Unable to engage Rampart module
body: <p>I am getting the following error while trying to implement WS-Security using Rampart in Axis2.</p>
  
  <pre><code>org.apache.axis2.AxisFault: Unable to engage module : rampart
  at org.apache.axis2.client.ServiceClient.engageModule(ServiceClient.java:358)
  </code></pre>
  
  <p>I am using axis in embedded mode (inside my ear). Service is working fine without the security implementation. I have included the policy in services.xml and also in the WSDL. Using Jboss and JDK6 Please find the files below.</p>
  
  <p><strong>Axis2.xml</strong></p>
  
  <pre><code>&lt;wsdl:definitions xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://service" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://service"&gt;
  &lt;wsdl:types&gt;
  &lt;xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service"&gt;
  &lt;xs:element name="echo"&gt;
  &lt;xs:complexType&gt;
  &lt;xs:sequence&gt;
  &lt;xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/&gt;
  &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name="echoResponse"&gt;
  &lt;xs:complexType&gt;
  &lt;xs:sequence&gt;
  &lt;xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/&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="echoRequest"&gt;
  &lt;wsdl:part name="parameters" element="ns:echo"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="echoResponse"&gt;
  &lt;wsdl:part name="parameters" element="ns:echoResponse"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="SimpleServicePortType"&gt;
  &lt;wsdl:operation name="echo"&gt;
  &lt;wsdl:input message="ns:echoRequest" wsaw:Action="urn:echo"&gt;&lt;/wsdl:input&gt;
  &lt;wsdl:output message="ns:echoResponse" wsaw:Action="urn:echoResponse"&gt;&lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="SimpleServiceSoap11Binding" type="ns:SimpleServicePortType"&gt;
  &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="echo"&gt;
  &lt;soap:operation soapAction="urn:echo" style="document"/&gt;
  &lt;wsdl:input&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="ns:SimpleServicePortType"&gt;
  &lt;soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="echo"&gt;
  &lt;soap12:operation soapAction="urn:echo" style="document"/&gt;
  &lt;wsdl:input&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="ns:SimpleServicePortType"&gt;
  &lt;http:binding verb="POST"/&gt;
  &lt;wsdl:operation name="echo"&gt;
  &lt;http:operation location="SimpleService/echo"/&gt;
  &lt;wsdl:input&gt;
  &lt;mime:content part="echo" type="text/xml"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;mime:content part="echo" type="text/xml"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name="SimpleService"&gt;
  &lt;wsdl:port name="SimpleServiceHttpEndpoint" binding="ns:SimpleServiceHttpBinding"&gt;
  &lt;http:address location="http://sbswsvm1426:9091/axis2/services/SimpleService.SimpleServiceHttpEndpoint/"/&gt;
  &lt;/wsdl:port&gt;
  &lt;wsdl:port name="SimpleServiceHttpSoap11Endpoint" binding="ns:SimpleServiceSoap11Binding"&gt;
  &lt;soap:address location="http://sbswsvm1426:9091/axis2/services/SimpleService.SimpleServiceHttpSoap11Endpoint/"/&gt;
  &lt;/wsdl:port&gt;
  &lt;wsdl:port name="SimpleServiceHttpSoap12Endpoint" binding="ns:SimpleServiceSoap12Binding"&gt;
  &lt;soap12:address location="http://sbswsvm1426:9091/axis2/services/SimpleService.SimpleServiceHttpSoap12Endpoint/"/&gt;
  &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  &lt;wsp:Policy 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" wsu:Id="SigOnly"&gt;
  &lt;wsp:ExactlyOne&gt;
  &lt;wsp:All&gt;
  &lt;sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:InitiatorToken&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:RequireThumbprintReference/&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://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"&gt;
  &lt;wsp:Policy&gt;
  &lt;sp:RequireThumbprintReference/&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://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
  &lt;sp:Policy&gt;
  &lt;sp:MustSupportRefKeyIdentifier/&gt;
  &lt;sp:MustSupportRefIssuerSerial/&gt;
  &lt;/sp:Policy&gt;
  &lt;/sp:Wss10&gt;
  &lt;sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
  &lt;sp:Body/&gt;
  &lt;/sp:SignedParts&gt;
  &lt;/wsp:All&gt;
  &lt;/wsp:ExactlyOne&gt;
  &lt;/wsp:Policy&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p><strong>Services.XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- This file was auto-generated from WSDL --&gt;
  &lt;!-- by the Apache Axis2 version: 1.5.6  Built on : Aug 30, 2011 (10:00:16 CEST) --&gt;
  &lt;serviceGroup&gt;
      &lt;service name="SimpleService"&gt;
          &lt;messageReceivers&gt;
              &lt;messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="service.SimpleServiceMessageReceiverInOut"/&gt;
          &lt;/messageReceivers&gt;
          &lt;parameter name="ServiceClass"&gt;service.SimpleServiceSkeleton&lt;/parameter&gt;
          &lt;parameter name="useOriginalwsdl"&gt;true&lt;/parameter&gt;
          &lt;parameter name="modifyUserWSDLPortAddress"&gt;true&lt;/parameter&gt;
          &lt;operation name="echo" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://service"&gt;
              &lt;actionMapping&gt;urn:echo&lt;/actionMapping&gt;
              &lt;outputActionMapping&gt;urn:echoResponse&lt;/outputActionMapping&gt;
          &lt;/operation&gt;
      &lt;module ref="rampart"/&gt;
      &lt;module ref="addressing"/&gt;
  
      &lt;wsp:Policy wsu:Id="SigOnly"
                  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"&gt;
          &lt;wsp:ExactlyOne&gt;
              &lt;wsp:All&gt;
                  &lt;sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
                      &lt;wsp:Policy&gt;
                          &lt;sp:InitiatorToken&gt;
                              &lt;wsp:Policy&gt;
                                  &lt;sp:X509Token
                                          sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:RequireThumbprintReference/&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://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"&gt;
                                      &lt;wsp:Policy&gt;
                                          &lt;sp:RequireThumbprintReference/&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://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
                      &lt;wsp:Policy&gt;
                          &lt;sp:MustSupportRefKeyIdentifier/&gt;
                          &lt;sp:MustSupportRefIssuerSerial/&gt;
                      &lt;/wsp:Policy&gt;
                  &lt;/sp:Wss10&gt;
                  &lt;sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
                      &lt;sp:Body/&gt;
                  &lt;/sp:SignedParts&gt;
  
                  &lt;ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"&gt;
                      &lt;ramp:user&gt;service&lt;/ramp:user&gt;
                      &lt;ramp:encryptionUser&gt;client&lt;/ramp:encryptionUser&gt;
                      &lt;ramp:passwordCallbackClass&gt;service.PWCBHandler
                      &lt;/ramp:passwordCallbackClass&gt;
  
                      &lt;ramp:signatureCrypto&gt;
                          &lt;ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"&gt;
                              &lt;ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type"&gt;JKS&lt;/ramp:property&gt;
                              &lt;ramp:property name="org.apache.ws.security.crypto.merlin.file"&gt;service.jks&lt;/ramp:property&gt;
                              &lt;ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password"&gt;apache
                              &lt;/ramp:property&gt;
                          &lt;/ramp:crypto&gt;
                      &lt;/ramp:signatureCrypto&gt;
                  &lt;/ramp:RampartConfig&gt;
  
              &lt;/wsp:All&gt;
          &lt;/wsp:ExactlyOne&gt;
      &lt;/wsp:Policy&gt;
      &lt;/service&gt;
  &lt;/serviceGroup&gt;
  </code></pre>
  
  <p><strong>Client Stub</strong></p>
  
  <pre><code>SimpleServiceStub stub = new SimpleServiceStub("http://sbswsvm1426:9091/axis2/services/SimpleService?wsdl");
              stub._getServiceClient().engageModule("rampart");
              stub._getServiceClient().engageModule("addressing");
              Options options = stub._getServiceClient().getOptions();
              options.setUserName("apache");
              options.setPassword("password");
              Echo oSreq=new Echo();
              oSreq.setArgs0("Echoed!!");
  
  
              EchoResponse response = stub.echo(oSreq);
              System.out.println(response.get_return());
  </code></pre>