简体   繁体   English

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

[英]How to make CXF Logging feature work with SOAP messages?

I have logging set up for CXF. 我为CXF设置了日志记录。 It is successfully logging using log4j. 它使用log4j成功记录。 As a test I have modified the settings in log4j.properties , where the root logger is set to INFO . 作为测试,我修改了log4j.properties的设置,其中根记录器设置为INFO

Adding log4j.logger.org.apache.cxf=DEBUG, C causes CXF logging to appear in the log file. 添加log4j.logger.org.apache.cxf=DEBUG, C会导致CXF日志记录显示在日志文件中。 However, SOAP messages are not getting logged as they hit the server. 但是,SOAP消息在到达服务器时不会被记录。 I have set up cxf.xml as the guide dictates. 我已经按照指南的要求设置了cxf.xml The file looks like this: 该文件如下所示:

<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>

This file, when packaged in the .war, is in /WEB-INF/classes/cxf.xml . 打包在.war中时,此文件位于/WEB-INF/classes/cxf.xml Based on my reading, this is all that is necessary to have CXF start logging inbound and outbound messages. 根据我的阅读,这是让CXF开始记录入站和出站邮件所必需的。

I have: 我有:

  1. Successfully replaced log4j as CXF's default logger. 成功将log4j替换为CXF的默认记录器。
  2. Added the logging feature to the cxf bus. 将记录功能添加到cxf总线。
  3. Ensured that CXF components are able to log. 确保CXF组件能够记录。
  4. Additionally specified the specific loggers as allowable: 另外将特定记录器指定为允许:

     log4j.logger.org.apache.cxf.interceptor.LoggingInInterceptor=DEBUG, C log4j.logger.org.apache.cxf.interceptor.LoggingOutInterceptor=DEBUG, C 

The raw soap messages however, refuse to get logged. 然而,原始的肥皂消息拒绝记录。 What am I doing wrong? 我究竟做错了什么?

edit: adding web.xml and applicationContext.xml as requested 编辑:根据请求添加web.xml和applicationContext.xml

web.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 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>

Have you tried adding it to your WEB-INF/cxf-servlet.xml? 您是否尝试将其添加到WEB-INF / cxf-servlet.xml中? The following configuration works for logging server side messages. 以下配置适用于记录服务器端消息。

<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>

This assumes that you are declaring your services according to CXF's Writing a service with Spring . 这假设您根据CXF 使用Spring编写服务来声明您的服务。

As for cxf.xml, I believe that may be for client configuration, although I could not locate any supporting documentation. 至于cxf.xml,我相信可能是客户端配置,虽然我找不到任何支持文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM