如何使CXF日志功能与SOAP消息一起使用?

时间:2013-05-15 23:30:32

标签: java soap log4j cxf

我为CXF设置了日志记录。它使用log4j成功记录。作为测试,我修改了log4j.properties中的设置,其中根记录器设置为INFO

添加log4j.logger.org.apache.cxf=DEBUG, C会导致CXF日志记录显示在日志文件中。但是,SOAP消息在到达服务器时不会被记录。我已将cxf.xml设置为the guide指令。该文件如下所示:

<beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://cxf.apache.org/core 
  http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

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

此文件打包在.war中时,位于/WEB-INF/classes/cxf.xml。根据我的阅读,这是让CXF开始记录入站和出站邮件所必需的。

我有:

  1. 已成功将log4j替换为CXF的默认记录器。
  2. 将记录功能添加到cxf总线。
  3. 确保CXF组件能够记录。
  4. 另外将特定记录器指定为允许:

    log4j.logger.org.apache.cxf.interceptor.LoggingInInterceptor=DEBUG, C
    log4j.logger.org.apache.cxf.interceptor.LoggingOutInterceptor=DEBUG, C
    
  5. 然后,原始的肥皂消息拒绝记录。我做错了什么?

    编辑:按要求添加web.xml和applicationContext.xml

    的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
    
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
      <servlet>
          <servlet-name>cxf</servlet-name>
          <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
          <servlet-name>cxf</servlet-name>
          <url-pattern>/*</url-pattern>
      </servlet-mapping>
    
      <session-config>
          <session-timeout>60</session-timeout>
      </session-config>
    </web-app>
    

    的applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:soap="http://cxf.apache.org/bindings/soap"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
         http://www.springframework.org/schema/jee
         http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-2.5.xsd
         http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
       default-dependency-check="none" default-lazy-init="false">
    
    <!-- Load the needed resources that are present in the cxf* jars -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    
    <!--Endpoint Info is below here -->
    </beans>
    

1 个答案:

答案 0 :(得分:3)

您是否尝试将其添加到WEB-INF / cxf-servlet.xml中?以下配置适用于记录服务器端消息。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:cxf="http://cxf.apache.org/core" 
    xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
     http://cxf.apache.org/core 
     http://cxf.apache.org/schemas/core.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

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

    <jaxws:endpoint ... />        
</beans>

这假设您根据CXF的Writing a service with Spring声明您的服务。

至于cxf.xml,我相信可能是客户端配置,虽然我找不到任何支持文档。