【问题标题】:Logging CXF rest service记录CXF休息服务
【发布时间】:2015-11-27 10:54:25
【问题描述】:

我正在尝试在 cxf.xml 中记录我的休息服务,如下所示,

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    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.xsd
    http://cxf.apache.org/jaxrs
    http://cxf.apache.org/schemas/jaxrs.xsd">

    <jaxrs:server id="base" address="/Restful">

    <jaxrs:serviceBeans>
         <ref bean="Service" />
    </jaxrs:serviceBeans>

    <jaxrs:features>
         <cxf:logging />
    </jaxrs:features>

    </jaxrs:server>

    <bean id="Service" class="com.xxx.yyy.services.ServiceImpl" />

    </beans>

在控制台中它只打印出站消息,如下所示,

Nov 27, 2015 3:36:47 PM org.apache.cxf.interceptor.LoggingOutInterceptor
    INFO: Outbound Message
    ---------------------------
    ID: 1
    Response-Code: 200
    Content-Type: text/plain
    Headers: {Content-Type=[text/plain], Date=[Fri, 27 Nov 2015 10:06:47 GMT]}
    Payload: your request has been proceed..
    --------------------------------------

问题,

如果您也能告诉我如何启用入站消息,我们将不胜感激?

更多详情,

CXF 3.1.4 Java 7

谢谢,

【问题讨论】:

    标签: java apache web-services cxf slf4j


    【解决方案1】:

    请参考stackoverflow链接How to log Apache CXF Soap Request and Soap Response using Log4j

    另外,Apache CFX 网站Apache CXF 部分“使用普通 Spring bean 元素启用消息日志记录”

    希望这会有所帮助!

    【讨论】:

    • 感谢您的回复, 1. 提供的 stackoverflow 链接是关于 SOAP 服务的。 2. 我已经参考了 Apache CXF 链接,但是当我尝试它时,我在使用总线时遇到了以下异常--> 原因:org.springframework.beans.factory.BeanCreationException:创建名称为“cxf”的 bean 时出错:不能在设置 bean 属性 'busConfig' 时解析对 bean 'cxf.config0' 的引用;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf.config0' is defined
    【解决方案2】:

    你可以这样设置配置:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 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.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
    
    
    <bean id="abstractLoggingInterceptor" abstract="true">
        <property name="prettyLogging" value="true"/>
    </bean>
    <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" parent="abstractLoggingInterceptor"/>
    <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" parent="abstractLoggingInterceptor"/>
    
    
    
        <jaxrs:server id="base" address="/Restful">
    
        <jaxrs:serviceBeans>
             <ref bean="Service" />
        </jaxrs:serviceBeans>
    
        <jaxrs:inInterceptors>
           <ref bean="loggingInInterceptor"/>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
           <ref bean="loggingOutInterceptor"/>
        </jaxrs:outInterceptors>
        <jaxrs:outFaultInterceptors>
           <ref bean="loggingOutInterceptor"/>
        </jaxrs:outFaultInterceptors>
        <jaxrs:inFaultInterceptors>
           <ref bean="loggingInInterceptor"/>
        </jaxrs:inFaultInterceptors>
    
        </jaxrs:server>
    
        <bean id="Service" class="com.xxx.yyy.services.ServiceImpl" />
    
        </beans>
    

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 1970-01-01
      • 2013-10-02
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多