打印 SOAP 消息的 XML 内容

发布于 2024-09-28 17:48:11 字数 180 浏览 0 评论 0原文

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

I am using Apache CXF for my webservices. I've created an instance of AbstractSoapInterceptor. In its public void handleMessage(SoapMessage message) throws Fault method I would like to print the XML content of the intercepted message to the console. How can I achieve that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妄想挽回 2024-10-05 17:48:11

检查这个并搜索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;

      }
}

Check this out and search for INBOUND INTERCEPTOR. Will place it here for reference...

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;

      }
}
梦亿 2024-10-05 17:48:11

您有什么理由不能只使用 CXF 附带的 LoggingInInterceptor 吗?您可以直接获取该代码并将其用作基础,但在 2.3 中,LoggingInInterceptor 得到了增强,允许指定要使用的打印流等,因此它可能“正常工作”。

Any reason you cannot just use the LoggingInInterceptor that is shipped with CXF? You could just grab the code for that and use that as a basis, but in 2.3, the LoggingInInterceptor was enhanced to allow specifying a printstream and such to use, so it might "just work".

ゝ偶尔ゞ 2024-10-05 17:48:11

您还可以使用以下功能:org.apache.cxf.feature.LoggingFeature

<jaxws:endpoint ...>
    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature"/>
    </jaxws:features>
</jaxws:endpoint>

You can also use a feature for this: org.apache.cxf.feature.LoggingFeature:

<jaxws:endpoint ...>
    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature"/>
    </jaxws:features>
</jaxws:endpoint>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文