java - Camel CXF : compressing response with CXFOutInterceptor throws classcast exception

标签 java spring web-services apache-camel cxf

我有一个服务包,我想使用 CXF GZIPFeature 来压缩响应。该 bundle 部署在 JBoss Fuse(jboss-fuse-6.1.0.redhat-379) 上。 Camel 路线配置是:

<cxf:bus id="cxf" name ="cxf">
    <cxf:features>
        <bean class="org.apache.cxf.transport.common.gzip.GZIPFeature">
            <property name="threshold">
                <value>1</value>
            </property>
        </bean>
    </cxf:features>
</cxf:bus>

<camel:camelContext ...>
    <camel:route id="test-server">
        <camel:to uri="cxfbean:servicebeans?bus=#cxf&amp;providers=#providers" />
    </camel:route>
</camel:camelContext>

但这会引发类转换异常:

java.lang.ClassCastException: org.apache.cxf.transport.common.gzip.GZIPOutInterceptor$GZipThresholdOutputStream cannot be cast to org.apache.cxf.io.CachedOutputStream
at org.apache.camel.component.cxf.transport.CamelDestination$CamelOutputStream.commitOutputMessage(CamelDestination.java:284)[204:org.apache.camel.camel-cxf-transport:2.12.0.redhat-610379]
at org.apache.camel.component.cxf.transport.CamelDestination$CamelOutputStream.doClose(CamelDestination.java:296)[204:org.apache.camel.camel-cxf-transport:2.12.0.redhat-610379]
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:220)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:241)[:1.7.0_67]
at org.apache.cxf.io.AbstractWrappedOutputStream.close(AbstractWrappedOutputStream.java:77)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:102)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]

有没有合法的方法在路由中使用CXF GZIPFeature?我不想使用 Camel 的 DataFormat 进行 gzip。

最佳答案

我正在使用 servicemix-camel-cxf 并且遇到了几乎相同的问题。最后我决定简单地将其添加到 route :

<marshal> <gzip/> </marshal>

看看 - 也许它也会对你有帮助。 但在这种情况下你必须设置 Content-Type: gzip header 。

尝试添加

<setHeader headerName="Content-Type">
    <constant>gzip</constant></setHeader>

但是对我来说这没有帮助,所以我在java代码中添加了 header 。 =)

关于java - Camel CXF : compressing response with CXFOutInterceptor throws classcast exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31585378/

相关文章:

java - Spring JPA + postgres - 如何存储createdOn字段?

html - Thymeleaf 吞下数据列表中的选项标签

javascript - 通过 javascript 将 json 对象发送到 python Web 服务

java - 如何使用 XFire 创建文档化的 WSDL

java web 应用程序和 xslt - 当 xml/xslt 文件更改时会发生什么?

Java从字符串中替换精确的子字符串

java - Log4j 2.0 - 日志文件中没有出现日志 - 使用 log4j2.xml 在同一类中尝试多个记录器

spring - 如何接收/处理发送给运行 Spring Boot/Integration 的用户的 XMPP 消息

c# - 软件设计与网络服务设计

java - 如何将动态创建的实例用作 Spring Autowiring 中的 bean