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 =
msgContext.getRequestMessage();
String oldRequest =
soapMessage.getSOAPPart().getEnvelope().toString();

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

ByteArrayInputStream istream = new
ByteArrayInputStream(newRequest.getBytes());
Message msg = new Message(istream, false);
msgContext.setRequestMessage(msg);

}
catch(Exception e) {
e.printStackTrace();
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.

Comments

Popular Posts