Apache camel Camel HTTP4删除bridgeEndpoint=true上的内容编码头

Apache camel Camel HTTP4删除bridgeEndpoint=true上的内容编码头,apache-camel,Apache Camel,有这样的路线 <route id="proxy"> <from uri="jetty:http://0.0.0.0:9092/Domain?matchOnUriPrefix=true"/> <to uri="http4://localhost:8080/Domain?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/> </route> 来自本地主机的响应:9092 HT

有这样的路线

<route id="proxy">
  <from uri="jetty:http://0.0.0.0:9092/Domain?matchOnUriPrefix=true"/>
  <to uri="http4://localhost:8080/Domain?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
</route>
来自本地主机的响应:9092

HTTP/1.1 202 Accepted
Content-Type: multipart/mixed
Server: Apache-Coyote/1.1
Vary: Accept-Encoding
Transfer-Encoding: chunked
即使bridgeEndpoint设置为true,HTTP4组件似乎也会解压缩GZIP流并删除内容编码头

当我在to uri中使用相同的代理时

<to uri="http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>

它按预期工作

我错过了什么/做错了什么


我正在使用Camel 2.15.1

回答可能太晚了,但我最近偶然发现了同样的问题,例如,通过Camel代理请求时,内容编码头被删除。起初我认为驼峰HTTP组件有问题,但显然是ApacheHTTP客户端

例如,如果您将Apache HTTP Client builder的默认配置保留在Camel中,它将返回拦截器,拦截器将自动解码gzip的内容并从响应中清除内容编码头,因此Camel甚至没有机会读取头。检查HttpClientBuilder的contentCompressionDisabled属性

因此,我的解决方案是覆盖默认的HttpClientBuilder以禁用内容压缩,例如

public class CustomHttp4Component extends HttpComponent {
  @Override
  protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters,
                                                    final Map<String, Object> httpClientOptions) throws Exception {
    HttpClientBuilder builder = super.createHttpClientBuilder(uri, parameters, httpClientOptions);
    // If not set, http client will decompress the entity and remove content-encoding headers from response.
    // There is logic in Camel to decompress if header is set hence we leave decompression logic to Camel and disable decomp in Apache HTTP client.
    builder.disableContentCompression();
    return builder;
}
<to uri="jetty:http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
public class CustomHttp4Component extends HttpComponent {
  @Override
  protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters,
                                                    final Map<String, Object> httpClientOptions) throws Exception {
    HttpClientBuilder builder = super.createHttpClientBuilder(uri, parameters, httpClientOptions);
    // If not set, http client will decompress the entity and remove content-encoding headers from response.
    // There is logic in Camel to decompress if header is set hence we leave decompression logic to Camel and disable decomp in Apache HTTP client.
    builder.disableContentCompression();
    return builder;
}