使用这样的路线
<route id="proxy">
<from uri="jetty:http://0.0.0.0:9092/Domain?matchOnUriPrefix=true"/>
<to uri="http4://localhost:8080/Domain?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
</route>
如果来自本地主机的响应是来自代理的响应不是GZIP编码的。
来自localhost的回复:8080
HTTP/1.1 202 Accepted
Server: Apache-Coyote/1.1
Content-Encoding: gzip
Date: Sat, 10 Sep 2016 15:39:31 GMT
Vary: Accept-Encoding
Content-Type: multipart/mixed
Transfer-Encoding: chunked
来自localhost的回复: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流并删除Content-Encoding标头?
当我在uri
中使用相同的代理时<to uri="http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
或
<to uri="jetty:http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
它按预期工作。
我错过了什么/做错了什么?
(我使用的是Camel 2.15.1)
答案 0 :(得分:1)
答案可能为时已晚,但我最近偶然发现了同一个问题,例如通过Camel代理请求时,将删除Content-Encoding标头。最初,我认为Camel HTTP组件出了点问题,但显然是Apache HTTP Client。
例如如果在Camel中为Apache HTTP Client构建器保留默认配置,它将带有拦截器,该拦截器会自动解码gzip的内容并从响应中清除Content-Encoding标头,因此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;
}