Wednesday, November 24, 2010

Thank God for Tripper McCarthy

A long time ago, in our galaxy, Tripper McCarthy posted this:

Tripper McCarthy Tue Jun 24 2003 19:19:31 GMT-0500 (CDT)

There have been several posts asking how to change the body of a message
(not the header) from within a handler. Here is a way to pull it off. It's a
little strange, but it works.

public void invoke(MessageContext msgContext) throws AxisFault {
try {
javax.xml.soap.SOAPMessage soapMessage =
String oldRequest =

int index = oldRequest.indexOf(" index = oldRequest.indexOf(">",index);
String newRequest = oldRequest.substring(0,index+1) +
"5" +

ByteArrayInputStream istream = new
Message msg = new Message(istream, false);

catch(Exception e) {
throw new AxisFault(e.getMessage());

Thanks Tripper. I've been beating my head for hours trying to modify the message using the deeply-nested object model in Handler. Your solution cut to the chase.