How to modify SOAP body in JBoss 6.1.0. final?
hordak83 Feb 3, 2012 12:56 PMI'm trying to modify SOAP body for an outbound ws client SOAP message, from an application which is deployed on JBoss 6.1.0. Final.
There is a registered HandlerResolver for that purpose, which has the following code:
public boolean handleMessage(SOAPMessageContext messagecontext) { Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outbound) { try { SOAPMessage soapMessage = messagecontext.getMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); Node firstChild = soapBody.getFirstChild(); String timeStamp = getTimestamp(); String signature = getSignature(firstChild.getLocalName(), timeStamp, secretBytes); SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement signatureElement = factory.createElement("Signature"); System.out.println(signature); signatureElement.addTextNode(signature); SOAPElement timestampElement = factory.createElement("Timestamp"); timestampElement.addTextNode(timeStamp); firstChild.appendChild(signatureElement); firstChild.appendChild(timestampElement); } catch(SOAPException se) { throw new RuntimeException("SOAPException was thrown.", se); } } return true; }
However, it throws this exception:
17:59:35,527 WARN [org.apache.cxf.jaxws.handler.HandlerChainInvoker] HANDLER_RAISED_RUNTIME_EXCEPTION: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(Unknown Source) [:1.6.0_27] at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source) [:1.6.0_27] at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source) [:1.6.0_27] ... ... 17:59:35,594 ERROR [STDERR] WS exception 17:59:35,594 ERROR [STDERR] javax.xml.ws.soap.SOAPFaultException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 17:59:35,595 ERROR [STDERR] at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146) 17:59:35,595 ERROR [STDERR] at $Proxy301.itemSearch(Unknown Source) 17:59:35,595 ERROR [STDERR] at com.youandshoe.search.DoSearch.doSearch(DoSearch.java:127) 17:59:35,595 ERROR [STDERR] at com.youandshoe.search.DoSearch.doSearch(DoSearch.java:174) 17:59:35,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 17:59:35,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 17:59:35,595 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 17:59:35,596 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 17:59:35,596 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122) 17:59:35,596 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) 17:59:35,596 ERROR [STDERR] at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72) 17:59:35,596 ERROR [STDERR] at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127) 17:59:35,596 ERROR [STDERR] at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:151) 17:59:35,596 ERROR [STDERR] at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doAroundInvoke(Jsr299BindingsInterceptor.java:122) 17:59:35,596 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor374.invoke(Unknown Source) 17:59:35,596 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 17:59:35,596 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 17:59:35,597 ERROR [STDERR] at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80) 17:59:35,597 ERROR [STDERR] at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71) 17:59:35,597 ERROR [STDERR] at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62) 17:59:35,597 ERROR [STDERR] at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127) 17:59:35,597 ERROR [STDERR] at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:46) 17:59:35,597 ERROR [STDERR] at org.jboss.weld.integration.deployer.metadata.WeldLifecycleInterceptor.doAroundInvoke(WeldLifecycleInterceptor.java:55) 17:59:35,597 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor373.invoke(Unknown Source) 17:59:35,597 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ...
for this line:
firstChild.appendChild(signatureElement);
This code worked fine with JBoss 5.1.0.
Any ideas?
Thanks.