簡體   English   中英

記錄 CXF 休息服務

[英]Logging CXF rest service

我試圖在 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

謝謝,

請參考 stackoverflow 鏈接How to log Apache CXF Soap Request and Soap Response using Log4j

此外,Apache CFX 網站Apache CXF部分“使用普通 Spring bean 元素啟用消息日志記錄”

希望這可以幫助!

您可以像這樣設置配置:

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