本文介绍了将数据(transactionId)传递给CXF拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个UI来查看从我的应用程序发出的SOAP事务。

I trying to build an UI to view the SOAP transactions that were sent out from my application.

典型的情况是每个用户事务都包含多个Web服务请求到多个系统,我正在为该用户事务生成一个transactionId,并将所有带有该transactionId的日志记录在日志文件中,以便可以使用transactionId搜索该日志文件,并且可以在UI上显示相应的日志语句。

A typical scenario is that each user transaction include multiple web-service request to multiple systems and I am generating a transactionId for that user transaction and Logging all the logs with that transactionId in log file, so that the log file can be searched using the transactionId and the corrosponding log statements can be displayed on UI.

因此,我能够将生成的transactionId附加到所有日志语句中,并能够从日志文件中提取它们。

So, I am able to append the generated transactionId to all the log statements and able to pull them from log files.

但是问题是,对于SOAP请求,我无法找到一种在SOAP请求的日志文件中添加相同transactionID的方法。

But the issue is that for the SOAP request, I am unable to figure out a way to to add the same transactionId in the log file in SOAP request.

可以有人为我提供了一些指针,我如何将生成的transactionId传递给CXF拦截器(或自定义CXF拦截器),以便当CXF记录SOAP请求并进行响应时,它将附加所传递的事务

Can someone provide me some pointers how can I pass the generated transactionId to CXF interceptors ( or custom CXF interceptors) so that when the CXF logs the SOAP request and repsonse it will append the passed transactionId.

就像这样

INFO: Outbound Message
---------------------------
transactionId=1234ABCXXX
ID: 1
Address: http://localhost:8080/Zservice/get?wsdl
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], SOAPAction=[""]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:get xmlns:ns2="http://service.zservice.com/"><arg0/></ns2:get></soap:Body></soap:Envelope>


推荐答案

我终于可以使用MDC激活它了

I am finally able to active this using MDC

在您要调用Web服务客户端的Web服务适配器中,像这样在MDC中设置交易ID。

In your web-service adapter where you are invoking the web-service client set the transaction Id in MDC like this.

      MDC.put("transaction", transId);        
      Account acct= new Account();
       //Set the requrest 

      //invoke WS client
      client.get(acct);

在自定义拦截器中,检索事务ID

In your custom interceptors, retrieve the transaction Id

public void handleMessage(SoapMessage message) {

    String transaction = MDC.get("transaction");

    logger.info("Transaction ID: {} ", transaction);
    try {

         LogInUtil.logging(logger, message, transaction);
         }
        catch (Exception ex) {
           logger.warn("Unable to save SOAP Response due to {}",ex.getMessage());
        }
}

这篇关于将数据(transactionId)传递给CXF拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:16