2012-05-28 39 views
1

我使用Apache CXF开发JAX-RS服务。我的服务正在运行,但我想将其更改为接受压缩(gzipped)请求。接受CXF中的gzip请求

我做了一些谷歌上搜索,并将此我beans.xml文件:

<bean id="GZIPInInterceptor" class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor"/> 
<bean id="compressGZIPFeature" class="org.apache.cxf.transport.http.gzip.GZIPFeature"/> 
<cxf:bus> 
    <cxf:inInterceptors> 
     <ref bean="GZIPInInterceptor"/> 
    </cxf:inInterceptors> 
    <cxf:features> 
     <ref bean="compressGZIPFeature"/> 
     <cxf:logging/> 
    </cxf:features> 
</cxf:bus> 

但是当我用压缩请求调用该服务从我的客户端应用程序,我得到的错误无效的UTF-8开始字节0x8b,这在日志文件:

28-May-2012 12:59:42 org.apache.cxf.interceptor.AbstractLoggingInterceptor log 
INFO: Inbound Message 
---------------------------- 
ID: 5 
Address: http://localhost:8080/ .../
Encoding: ISO-8859-1 
Http-Method: POST 
Content-Type: application/xml 
Headers: {Accept=[application/xml], connection=[Keep-Alive], content-encoding=[g 
zip], Content-Length=[246], content-type=[application/xml], expect=[100-continue 
], host=[localhost:8080]} 
Payload: ?  ? ý¢`?I?%&/m-{¦J§JÎÓt?`?$Ï[email protected]?ý-?-µ?ý?iG#)½*?-eVe][email protected]¦Ý?+¸Ì{´¢¸Ì{´ 
¢¸¦;?N'¸¯ ?\fd?l÷+J++?!?¬+??~|??"? ?´?ez?ÎMQ-?¹hw+¾Q?/ºi¼X^|÷Ц=¯>°Þ¸8z|͵?ú4}|· 
???¡-÷t+ÍÎgO?÷vv¸v÷w÷´¦ tg¦¸-/Õ+´Ý}¦¦w?¦+C¤/²®_·dþÚ¦²{;'??>³¶ßÚ+¦'¤?Ý|·õ¦±¦¦¦?O? 
¯Ý>¥¦?·°.w 
-------------------------------------- 
28-May-2012 12:59:43 org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleJA 
XBException 
WARNING: javax.xml.bind.UnmarshalException 
- with linked exception: 
[com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x8b (at char #2, by 
te #-1)] 
     at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStrea 
mException(UnmarshallerImpl.java:426) 

... 

28-May-2012 12:59:43 org.apache.cxf.interceptor.AbstractLoggingInterceptor log 
INFO: Outbound Message 
--------------------------- 
ID: 5 
Response-Code: 400 
Content-Type: text/plain 
Headers: {Content-Type=[text/plain], Date=[Mon, 28 May 2012 11:59:43 GMT]} 
Payload: JAXBException occurred : Invalid UTF-8 start byte 0x8b (at char #2, byt 
e #-1). Invalid UTF-8 start byte 0x8b (at char #2, byte #-1). 
-------------------------------------- 

回答

2

答案是,拦截没有得到从XML文件回升。我尝试添加该注释上面我的服务方法,并开始工作:

@org.apache.cxf.interceptor.InInterceptors (interceptors = {"org.apache.cxf.transport.common.gzip.GZIPInInterceptor" }) 
+1

你可以去更容易并使用@ org.apache.cxf.annotations.GZIP注释。 :-) –

5

在CXF,你可以使用

@GZIP

注释用于压缩消息