繁体   English   中英

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

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

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

添加log4j.logger.org.apache.cxf=DEBUG, C会导致CXF日志记录显示在日志文件中。 但是,SOAP消息在到达服务器时不会被记录。 我已经按照指南的要求设置了cxf.xml 该文件如下所示:

<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 

然而,原始的肥皂消息拒绝记录。 我究竟做错了什么?

编辑:根据请求添加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>

您是否尝试将其添加到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 使用Spring编写服务来声明您的服务。

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

暂无
暂无

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

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