gpt4 book ai didi

java - 如何打印 SOAPMessage

转载 作者:搜寻专家 更新时间:2023-11-01 01:45:00 25 4
gpt4 key购买 nike

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;
}

最佳答案

好的,我已经解决了这个问题。修改后的代码块如下。

  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());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
sbuf.append("\nMessage Desc:"+baos.toString());
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;
}

关于java - 如何打印 SOAPMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13842182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com