在CXF中接受压缩的请求 [英] Accepting gzipped requests in CXF

查看:94
本文介绍了在CXF中接受压缩的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Apache CXF to develop a JAX-RS service. My service is working, but I want to change it to accept compressed (gzipped) requests.

我已经进行了一些谷歌搜索并将其添加到我的 beans.xml 文件:

I've done some googling and added this to my beans.xml file:

<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 ,并在日志文件中显示以下内容:

but when I call the service from my client application with a compressed request, I get the error Invalid UTF-8 start byte 0x8b and this in the log file:

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).
--------------------------------------


推荐答案

答案是,拦截器未从XML文件中拾取。我尝试在我的服务方法上方添加此批注,然后它开始工作:

The answer was that the interceptor was not getting picked up from the XML file. I tried adding this annotation above my service method and it started working:

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

这篇关于在CXF中接受压缩的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆