title: Error on adding Signature using Spring WS Security
body: <p>I am having an issue on using the Spring WS-Security on my application. Goal is to include a Signature, UsernameToken and Encrypt on my XML SOAP request. But I got this errors:</p>
  
  <pre><code>    12/01/16 14:41:41 - [main] ERROR org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor - Could not secure response: Error during encryption: ; nested exception is org.apache.ws.security.WSSecurityException: Error during encryption: 
  org.springframework.ws.soap.security.wss4j.Wss4jSecuritySecurementException: Error during encryption: ; nested exception is org.apache.ws.security.WSSecurityException: Error during encryption: 
      at org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor.secureMessage(Wss4jSecurityInterceptor.java:523)
      at org.springframework.ws.soap.security.AbstractWsSecurityInterceptor.handleRequest(AbstractWsSecurityInterceptor.java:203)
      at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:580)
      at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:539)
      at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:386)
      at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:380)
      at net.virtela.ws.pricing.client.VerizonPricingApiClient.submitOrderWithSpring(VerizonPricingApiClient.java:79)
      at net.virtela.rest.api.test.NcopQueryRestApiTest.testVerizon(NcopQueryRestApiTest.java:465)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: org.apache.ws.security.WSSecurityException: Error during encryption: 
      at org.apache.ws.security.action.EncryptionAction.execute(EncryptionAction.java:93)
      at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:202)
      at org.springframework.ws.soap.security.wss4j.Wss4jHandler.doSenderAction(Wss4jHandler.java:120)
      at org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor.secureMessage(Wss4jSecurityInterceptor.java:520)
      ... 35 more
  Caused by: org.apache.ws.security.WSSecurityException: Cannot encrypt data
      at org.apache.ws.security.message.WSSecEncrypt.encryptElement(WSSecEncrypt.java:493)
      at org.apache.ws.security.message.WSSecEncrypt.doEncryption(WSSecEncrypt.java:406)
      at org.apache.ws.security.message.WSSecEncrypt.encryptForRef(WSSecEncrypt.java:289)
      at org.apache.ws.security.message.WSSecEncrypt.build(WSSecEncrypt.java:246)
      at org.apache.ws.security.action.EncryptionAction.execute(EncryptionAction.java:91)
      ... 38 more
  Caused by: org.apache.xml.security.c14n.CanonicalizationException: Element ns3:serviceRequest has a relative namespace: ns3="e2eiServiceRequest"
      at org.apache.xml.security.c14n.implementations.Canonicalizer20010315.handleAttributesSubtree(Canonicalizer20010315.java:227)
      at org.apache.xml.security.c14n.implementations.CanonicalizerBase.canonicalizeSubTree(CanonicalizerBase.java:295)
      at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalizeSubTree(CanonicalizerBase.java:203)
      at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalizeSubTree(CanonicalizerBase.java:121)
      at org.apache.xml.security.c14n.Canonicalizer.canonicalizeSubtree(Canonicalizer.java:284)
      at org.apache.xml.security.encryption.AbstractSerializer.serializeToByteArray(AbstractSerializer.java:123)
      at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1047)
      at org.apache.xml.security.encryption.XMLCipher.encryptData(XMLCipher.java:1027)
      at org.apache.xml.security.encryption.XMLCipher.encryptElementContent(XMLCipher.java:798)
      at org.apache.xml.security.encryption.XMLCipher.doFinal(XMLCipher.java:930)
      at org.apache.ws.security.message.WSSecEncrypt.encryptElement(WSSecEncrypt.java:490)
      ... 42 more
  </code></pre>
  
  <p>By the way, this is my application context used:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>http://www.springframework.org/schema/beans/spring-beans.xsd"></p>
  
  <pre><code>&lt;bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor"&gt;
      &lt;property name="securementActions" value="Encrypt Signature UsernameToken" /&gt;
  
      &lt;!-- UsernameToken --&gt;
      &lt;property name="securementUsername" value="user1234" /&gt;
      &lt;property name="securementPassword" value="abc1234" /&gt;
      &lt;property name="securementPasswordType" value="PasswordText" /&gt;
      &lt;property name="securementUsernameTokenElements" value="Nonce Created" /&gt;
  
      &lt;!-- Signature --&gt;
      &lt;property name="securementSignatureKeyIdentifier" value="X509KeyIdentifier" /&gt;
      &lt;property name="securementSignatureUser" value="1" /&gt;
      &lt;property name="securementSignatureCrypto" ref="cryptoFactory"/&gt;
  
      &lt;!-- Encrypt --&gt;
      &lt;property name="securementEncryptionUser" value="1"/&gt;
      &lt;property name="securementEncryptionCrypto" ref="cryptoFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="cryptoFactory" class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean"&gt;
      &lt;property name="keyStorePassword" value="abc1234" /&gt;
      &lt;property name="keyStoreLocation" value="classpath:/certificate/telco.sample.net.jks" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- Configuring Client --&gt;
  &lt;bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/&gt;
  
  &lt;bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
      &lt;property name="classesToBeBound"&gt;
          &lt;list&gt;
              &lt;value&gt;net.sample.ws.pricing.model.telco.ServiceRequest&lt;/value&gt;
              &lt;value&gt;net.sample.ws.pricing.model.telco.ServiceResponse&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"&gt;
      &lt;constructor-arg ref="messageFactory"/&gt;
      &lt;property name="defaultUri" value="https://wsgateway.verizon.com:443/VRDOrderingService_v2.0r1"/&gt;
      &lt;property name="marshaller" ref="marshaller" /&gt;
      &lt;property name="unmarshaller" ref="marshaller"/&gt;
      &lt;property name="interceptors"&gt;
          &lt;list&gt;
              &lt;ref bean="wsSecurityInterceptor"/&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Main error is: <strong>org.apache.xml.security.c14n.CanonicalizationException: Element ns3:serviceRequest has a relative namespace: ns3="e2eiServiceRequest"</strong></p>
  
  <p>Can someone help me with this problem? </p>
  
  <p>Thanks.</p>