1

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

我做了一些谷歌搜索并将其添加到我的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>

但是当我使用压缩请求从客户端应用程序调用服务时,我在日志文件中收到错误Invalid UTF-8 start byte 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?`?$Ï?@?ý-?-µ?ý?iG#)½*?-eVe]f?@¦Ý?+¸Ì{´¢¸Ì{´
¢¸¦;?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).
--------------------------------------
4

2 回答 2

5

在 CXF 中,您可以使用

@GZIP

用于压缩消息的注释

于 2012-09-20T21:32:42.383 回答
3

答案是拦截器没有从 XML 文件中获取。我尝试在我的服务方法上方添加此注释并开始工作:

@org.apache.cxf.interceptor.InInterceptors (interceptors = {"org.apache.cxf.transport.common.gzip.GZIPInInterceptor" })
于 2012-05-28T15:00:34.880 回答