简体   繁体   English

记录 CXF 休息服务

[英]Logging CXF rest service

I am trying to log my rest service as below in cxf.xml,我试图在 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>

In console it prints only Outbound message as below,在控制台中,它仅打印出站消息,如下所示,

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

Question,题,

It would be appreciated if you could let me know how to enable Inbound message as well?如果您能让我知道如何启用入站消息,我将不胜感激?

Additional details,额外细节,

CXF 3.1.4 Java 7 CXF 3.1.4 Java 7

Thanks,谢谢,

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

Also, Apache CFX web site Apache CXF section "Enabling message logging using plain Spring bean elements"此外,Apache CFX 网站Apache CXF部分“使用普通 Spring bean 元素启用消息日志记录”

Hope this helps!希望这可以帮助!

You can set configuration like this:您可以像这样设置配置:

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

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

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