【问题标题】:Camel CXF: compressing response with CXFOutInterceptor throws classcast exceptionCamel CXF:使用 CXFOutInterceptor 压缩响应会引发类转换异常
【发布时间】:2015-07-23 10:58:21
【问题描述】:

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

<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。

【问题讨论】:

    标签: java spring web-services apache-camel cxf


    【解决方案1】:

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

    <marshal> <gzip/> </marshal>

    检查一下 - 也许它也会对您有所帮助。 但在这种情况下,您必须设置 Content-Type: gzip 标头。

    尝试添加

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 1970-01-01
      相关资源
      最近更新 更多