简体   繁体   中英

In apache cxf, how do I know the SOAP request message is gzip compressed?

I'm using Apache CXF to send SOAP message. In specific case, I have to send a SOAP message gzip compressed.

Using log4j, I printed detailed info.

How can I know the message is gzip compressed and transfered to server?

Below is my Java code for gzip and log info.

java code

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

log info

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"]

You can use cxf:features to see if the message is received as 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>

Both the logging and gzip interceptors run in the same phase so the output would depend on the order. My suggestion would be to use the Logging feature and then play with the order of the features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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