【问题标题】:How to make CXF SOAP Request to be printed under log file如何使 CXF SOAP 请求打印在日志文件下
【发布时间】:2013-01-23 22:12:24
【问题描述】:
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor"  )
@OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")

public class SKTWeb implements SKTWebService {

// method logic goes here 

}

嗨,在 CXF 方法实现中添加这两行之后。 我可以在 tomcat 服务器控制台下得到 SOAP Requestand Response 的鞭子

在 Tomcat 控制台下查看打印的 SOAP 请求实例

INFO: Inbound Message
----------------------------
ID: 1
Address: /Sktweb-33.0/services/SKTWeb
Encoding: UTF-8
Content-Type: text/xml; charset=UTF-8
Headers: {cache-control=[no-cache], content-type=[text/xml; charset=UTF-8], connection=[keep-alive], host=[local
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns4:strategy xmlns:ns

谁能告诉我如何在我的日志文件(Log4j)中得到这个

目前这是我的 log4j.properties 文件

log4j.rootCategory=INFO, A1

# A1 is a DailyRollingFileAppender

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.file=/Haieeee.log
log4j.appender.A1.datePattern='.'yyyy-MM-dd
log4j.appender.A1.append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} - %m%n

而且我在 Web 应用程序中有 META-INF\cxf\org\apache\cxf\Logger Log4jLogger.class 。 而且我还保留了

<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus> 

endpoints.xml 文件内部

请帮忙

【问题讨论】:

    标签: cxf


    【解决方案1】:

    看起来有点混乱。你需要你的组装应用程序有一个可定位的文件META-INF/cxf/org.apache.cxf.Logger(是的,那些是点!它不是一个 .java 或 .class 文件),它应该有内容:

    org.apache.cxf.common.logging.Log4jLogger
    

    我在我的代码中完全使用了上面的内容,它就像一个魅力。 (不过,我不将它与消息记录功能一起使用功能;根据我的口味,部署时流量过多……)

    【讨论】:

      【解决方案2】:

      基本上,您希望 CXF 选择您的属性文件,然后它使用此属性文件而不是 CXF。 我在我的 CXF 应用程序中使用弹簧配置。如果您没有使用任何 Spring 配置,则创建一个新配置并在启动时使用 Spring 上下文侦听器加载它,然后您可以在 XML 文件中添加以下代码。

      <bean id="log4jInitialization"
              class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
              <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
              <property name="targetMethod" value="initLogging" />
              <property name="arguments">
                  <list>
                      <value>file:fullpath/filename.properties</value>
                  </list>
              </property>
          </bean>
      

      您还可以在&lt;list&gt; &lt;/list&gt; 中添加classpath:filename.properties。 Spring 框架中实现的日志记录将用于记录所有请求和响应。您还可以在您的应用程序中使用相同的日志记录实现。

      【讨论】:

        【解决方案3】:

        始终使用拦截器...添加 slf4j-log4j12-1.6.1.jar、slf4j-api-1.6.1.jar 和 commons-logging-1.1.1.jar。将以下代码粘贴到您的 cxf.xml...

        <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" id="loggingInInterceptor" />
            <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="logOutInterceptor" />
            <cxf:bus>
                <cxf:inInterceptors>
                    <ref bean="loggingInInterceptor" />
                </cxf:inInterceptors>
                <cxf:outInterceptors>
                    <ref bean="logOutInterceptor" />
                </cxf:outInterceptors>
            </cxf:bus>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-08-14
          • 2013-04-16
          • 1970-01-01
          • 2020-02-23
          • 1970-01-01
          • 1970-01-01
          • 2017-08-10
          • 2021-10-03
          相关资源
          最近更新 更多