SOAPMessage 具有 writeTo() 方法,用于将其内容打印到流中。但是如何将 SOAPMessage 内容写入 StringBuffer?
代码行“message.writeTo(System.out);” 必须修改。。
public boolean handleMessage(SOAPMessageContext smc) {
StringBuffer sbuf = new StringBuffer();
sbuf.append("\n------------------------------------\n");
sbuf.append("In SOAPHandler " + HandlerName + ":handleMessage()\n");
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
sbuf.append("\ndirection = outbound ");
}
else {
sbuf.append("\ndirection = inbound ");
}
SOAPMessage message = smc.getMessage();
try {
sbuf.append("\n");
sbuf.append(message.toString());
//message.writeTo(System.out);
sbuf.append("\nMessage Desc:");
sbuf.append("\n");
}
catch (Exception e) {
sbuf.append("Exception in SOAP Handler: " + e);
}
sbuf.append("Exiting SOAPHandler " + HandlerName + ":handleMessage()\n");
sbuf.append("------------------------------------\n");
logger.debug(sbuf.toString());
return true;
}