JBoss Community

How to modify SOAP body in JBoss 6.1.0. final?

created by Martin Jondzic in JBoss Web Services - View the full discussion

I'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]

for this line:

 

 firstChild.appendChild(signatureElement);

 

This code worked fine with JBoss 5.1.0.

 

Any ideas?

Thanks.

Reply to this message by going to Community

Start a new discussion in JBoss Web Services at Community