gpt4 book ai didi

java - 打印 SOAP 消息的 XML 内容

转载 作者:行者123 更新时间:2023-12-02 02:54:07 27 4
gpt4 key购买 nike

我正在使用 Apache CXF 作为我的网络服务。我创建了一个 AbstractSoapInterceptor 实例。在其 public void handleMessage(SoapMessage message) throws Fault 方法中,我想将截获消息的 XML 内容打印到控制台。我怎样才能实现这一目标?

最佳答案

检查this出站并搜索 INBOUND INTERCEPTOR。将其放在这里以供引用...

public class InterceptorMensajeSOAPIn extends AbstractSoapInterceptor {

private static Logger log =
Logger.getLogger(InterceptorMensajeSOAPIn.class);



private SAAJInInterceptor saajIn = new SAAJInInterceptor();

public InterceptorMensajeSOAPIn(){

super(Phase.PRE_PROTOCOL);

getAfter().add(SAAJInInterceptor.class.getName());

}


public void handleMessage(SoapMessage message) throws Fault {

SOAPMessage soapMessage = getSOAPMessage(message);

try {

soapMessage.writeTo(System.out);

} catch (Exception e) {

e.printStackTrace();

}
}


private SOAPMessage getSOAPMessage(SoapMessage smsg){

SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);

if (soapMessage == null) {

saajIn.handleMessage(smsg);

soapMessage = smsg.getContent(SOAPMessage.class);

}

return soapMessage;

}
}

关于java - 打印 SOAP 消息的 XML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3969399/

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