Title: Handler has a problem modifying a message

I have seen this question asked before, but with no definitive answer.

I have a handler which needs to modify a message.  After some experimentation, I tried the following:

1       Message message = (Message) messageContext.getCurrentMessage();
2       SOAPBody soapBody = (SOAPBody) message.getSOAPEnvelope().getBody();
3       SOAPEnvelope soapEnvelope = new SOAPEnvelope();
4       Iterator iterator = soapBody.getChildElements();
5       while (iterator.hasNext()) {
6               SOAPBodyElement soapBodyElement = (SOAPBodyElement) iterator.next();
7               Element element = soapBodyElement.getAsDOM();
8               NodeList nodeList = element.getElementsByTagName("myTag");
9               if (nodeList.getLength() > 0) {
10                      Node node = nodeList.item(0);
11                      node.getFirstChild().setNodeValue("myNewValue");
12              }
13              soapEnvelope.addBodyElement(new SOAPBodyElement(element));
14      }
15      Message newMessage = new Message(soapEnvelope);
16      newMessage.setMessageContext(messageContext);
17      messageContext.setCurrentMessage(newMessage);

However, this results in an exception ("No deserialization context to use in MessageElement.getValueAsType()!", which I find from looking at the source code for Message element is because I did not set a DeserializationContext when I created a SOAPBodyElement in line 13.

What I can't figure out is how to create a DeserializationContext.  The constructors for DeserializationContextImpl require either an InputSource or a SOAPHandler, and it is not clear to me how to get these.

Can anyone help, or is there a better way to get modify the message in a handler?

Michael Wax
Technical Consultant
ADP Vantra



This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

Reply via email to