在apache cxf中,我怎么知道SOAP请求消息是gzip压缩的?

时间:2012-08-14 10:44:22

标签: java web-services apache cxf

我正在使用Apache CXF发送SOAP消息。 在特定情况下,我必须发送一个压缩的gzip SOAP消息。

使用log4j,我打印了详细信息。

我如何知道该消息是gzip压缩并转移到服务器?

以下是我的gzip和日志信息的Java代码。

java代码

Client cxfClient = ClientProxy.getClient(port);
/** Logging Interceptor */
cxfClient.getInInterceptors().add(new GZIPInInterceptor());
cxfClient.getOutInterceptors().add(new GZIPOutInterceptor()); 

日志信息

20120814 18:56:15,351       DEBUG                   Interceptors contributed by bus: []
20120814 18:56:15,351       DEBUG                   Interceptors contributed by client: [org.apache.cxf.transport.http.gzip.GZIPOutInterceptor@1682a53]
20120814 18:56:15,351       DEBUG                   Interceptors contributed by endpoint: [org.apache.cxf.interceptor.MessageSenderInterceptor@1b2d7df, org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@7a9224, org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@110b640, org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@2d59a3]
20120814 18:56:15,351       DEBUG                   Interceptors contributed by binding: [org.apache.cxf.interceptor.AttachmentOutInterceptor@158015a, org.apache.cxf.interceptor.StaxOutInterceptor@c0c8b5, org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@b914b3, org.apache.cxf.interceptor.BareOutInterceptor@fdfc58, org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@c22a3b, org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@1629e71]
20120814 18:56:15,351       DEBUG                   Interceptors contributed by databinding: []
20120814 18:56:15,357       DEBUG                   Adding interceptor org.apache.cxf.transport.http.gzip.GZIPOutInterceptor@1682a53 to phase prepare-send
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor@1b2d7df to phase prepare-send
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@7a9224 to phase pre-logical
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@110b640 to phase pre-logical
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@2d59a3 to phase pre-logical
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.interceptor.AttachmentOutInterceptor@158015a to phase pre-stream
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.interceptor.StaxOutInterceptor@c0c8b5 to phase pre-stream
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@b914b3 to phase pre-logical
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.interceptor.BareOutInterceptor@fdfc58 to phase marshal
20120814 18:56:15,358       DEBUG                   Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@c22a3b to phase post-logical
20120814 18:56:15,359       DEBUG                   Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@1629e71 to phase write
20120814 18:56:15,360       DEBUG                   Chain org.apache.cxf.phase.PhaseInterceptorChain@31688f was created. Current flow:
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor, GZIPOutInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [BareOutInterceptor]

20120814 18:56:15,361       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@2d59a3
20120814 18:56:15,361       DEBUG                   op: [OperationInfo: {https://asp.cyberbooking.co.kr/TopasApiSvc/services}getAirAvail]
20120814 18:56:15,361       DEBUG                   op.hasOutput(): true
20120814 18:56:15,361       DEBUG                   op.getOutput().size(): 2
20120814 18:56:15,361       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@7a9224
20120814 18:56:15,364       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@110b640
20120814 18:56:15,364       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@b914b3
20120814 18:56:15,365       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@c22a3b
20120814 18:56:15,365       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor@1b2d7df
20120814 18:56:15,365       DEBUG                   Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@dc9065 to phase prepare-send-ending
20120814 18:56:15,366       DEBUG                   Chain org.apache.cxf.phase.PhaseInterceptorChain@31688f was modified. Current flow:
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor, GZIPOutInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [BareOutInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

20120814 18:56:15,366       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.transport.http.gzip.GZIPOutInterceptor@1682a53
20120814 18:56:15,366       DEBUG                   Requestor role, so gzip enabled
20120814 18:56:15,366       DEBUG                   gzip permitted: YES
20120814 18:56:15,367       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.AttachmentOutInterceptor@158015a
20120814 18:56:15,367       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxOutInterceptor@c0c8b5
20120814 18:56:15,370       DEBUG                   Adding interceptor org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor@1f488f1 to phase pre-stream-ending
20120814 18:56:15,370       DEBUG                   Chain org.apache.cxf.phase.PhaseInterceptorChain@31688f was modified. Current flow:
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor, GZIPOutInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [BareOutInterceptor]
  pre-stream-ending [StaxOutEndingInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

20120814 18:56:15,370       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@1629e71
20120814 18:56:15,383       DEBUG                   Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor@1ce663c to phase write-ending
20120814 18:56:15,384       DEBUG                   Chain org.apache.cxf.phase.PhaseInterceptorChain@31688f was modified. Current flow:
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor, GZIPOutInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [BareOutInterceptor]
  write-ending [SoapOutEndingInterceptor]
  pre-stream-ending [StaxOutEndingInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

20120814 18:56:15,384       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.BareOutInterceptor@fdfc58
20120814 18:56:15,387       DEBUG                   Compressing message.
20120814 18:56:15,388       DEBUG                   Sending POST Message with Headers to http://test.co.kr:80/###/###/###Conduit :{https://test.co.kr/###/####}###.http-conduit
Content-Type: text/xml; charset=UTF-8

20120814 18:56:15,388       DEBUG                   SOAPAction: "getAirAvail"
20120814 18:56:15,388       DEBUG                   Accept: */*
20120814 18:56:15,388       DEBUG                   Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0
20120814 18:56:15,388       DEBUG                   Content-Encoding: gzip
20120814 18:56:15,388       DEBUG                   No Trust Decider for Conduit '{https://test.co.kr/###/###}###.http-conduit'. An afirmative Trust Decision is assumed.
20120814 18:56:15,394       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor@1ce663c
20120814 18:56:15,394       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxOutInterceptor$StaxOutEndingInterceptor@1f488f1
20120814 18:56:15,394       DEBUG                   Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@dc9065
20120814 18:56:15,459       DEBUG                   Response Code: 200 Conduit: {https://test.co.kr/###/###}###.http-conduit
20120814 18:56:15,459       DEBUG                   Content length: 11034
20120814 18:56:15,459       DEBUG                   Header fields: 
    null: [HTTP/1.1 200 OK]
    Content-Language: [ko-KR]
    Date: [Tue, 14 Aug 2012 09:56:15 GMT]
    Content-Length: [11034]
    P3P: [CP='CAO PSA CONi OTR OUR DEM ONL']
    Expires: [Thu, 01 Dec 1994 16:00:00 GMT]
    Keep-Alive: [timeout=10, max=100]
    Set-Cookie: [WMONID=mL6rq_Irpa_; Expires=Wed, 14 Aug 2013 09:56:15 GMT; Path=/]
    Connection: [Keep-Alive]
    Content-Type: [text/xml; charset=utf-8]
    Server: [IBM_HTTP_Server]
    Cache-Control: [no-cache="set-cookie, set-cookie2"]

1 个答案:

答案 0 :(得分:0)

您可以使用cxf:features查看邮件是否以gzip格式收到:

    <beans>
    ...
        <bean id="compressGZIPFeature" class="org.apache.cxf.transport.http.gzip.GZIPFeature"/> 
        <bean id="loggingFeature" class="org.apache.cxf.feature.LoggingFeature"/> 
        <cxf:bus id="yourCxfBus">
            <cxf:features> 
                <ref bean="compressGZIPFeature"/> 
                <ref bean="loggingFeature"/> 
            </cxf:features> 
        </cxf:bus>
        <cxf:cxfEndpoint id="soapMessageEndpoint"
                ... 
                bus="yourCxfBus"
                ...
                 />
        ...
    </beans>

logginggzip拦截器都在同一阶段运行,因此输出将取决于顺序。我的建议是使用Logging功能,然后使用功能的顺序。