加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 使用Apache CXF发送FastInfoset请求时,我可以在日志中

发布时间:2020-12-15 01:08:48 所属栏目:Java 来源:网络整理
导读:我需要在应用程序的日志中提供请求和响应,但Apache CXF发送的请求在FastInfoset(Content-Type:application / fastinfoset)中,这导致请求和响应的日志不可读(因为它是二进制的) ).有没有办法解决这个问题,以便我保留FastInfoset消息(出于性能原因)但是我在日

我需要在应用程序的日志中提供请求和响应,但Apache CXF发送的请求在FastInfoset(Content-Type:application / fastinfoset)中,这导致请求和响应的日志不可读(因为它是二进制的) ).有没有办法解决这个问题,以便我保留FastInfoset消息(出于性能原因)但是我在日志中得到了正确的XML?

这是我现在拥有的CXF配置,如果有帮助的话:

预先感谢您的任何帮助.

最佳答案
我看了LoggingInInterceptor.logInputStream,似乎它不支持fastinfoset.但您可以使用自定义interceptor而不是LoggingInInterceptor和LoggingOutInterceptor来提取有效负载,对其进行解码并记录原始消息.

public class CustomInterceptor extends AbstractPhaseInterceptor

替换XML文件

找到如何解码FastInfoset的示例并不容易.使用DOM和FastInfoset-1.2.12.jar尝试此操作.在这个repo中,您有几个使用sTAX和SAX的示例

public void decodeFI(InputStream in,OutputStream out) throws Exception{
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();

    DOMDocumentParser parser = new DOMDocumentParser();
    parser.parse(doc,in);

    // write the content into xml file
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(out);
    transformer.transform(source,result);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读