简体   繁体   English

Gzip Apache骆驼要求休息

[英]Gzip apache camel request for rest

I am using apache camel for rest service calls from spring 我正在使用apache骆驼从春季开始进行休息服务

Now we need to send the json request in our body to be passed in GZIP using apache camel. 现在我们需要在体内发送json请求,以使用apache骆驼在GZIP中传递该请求。 I tried by adding CONTENT_ENCODING as gzip, but it does not work. 我尝试通过将CONTENT_ENCODING添加为gzip进行尝试,但是它不起作用。 Please see the code 请看代码

public void process(Exchange exchange) { exchange.setPattern(ExchangePattern.InOut); 公共无效进程(Exchange交换){exchange.setPattern(ExchangePattern.InOut); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); exchange.setProperty(Exchange.CHARSET_NAME,“ UTF-8”); Message inMessage = exchange.getIn(); 消息inMessage = exchange.getIn(); inMessage.setHeader(ACCEPT_HEADER, "application/json"); inMessage.setHeader(ACCEPT_HEADER,“ application / json”); inMessage.setHeader(CONTENT_TYPE, "application/json"); inMessage.setHeader(CONTENT_TYPE,“ application / json”); inMessage.setHeader(Constants.ACCEPT_ENCODING, Constants.ACCEPT_ENCODING_TYPE); inMessage.setHeader(Constants.ACCEPT_ENCODING,Constants.ACCEPT_ENCODING_TYPE); inMessage.setHeader(Exchange.CONTENT_ENCODING, "gzip"); inMessage.setHeader(Exchange.CONTENT_ENCODING,“ gzip”); inMessage.setBody(body); inMessage.setBody(body);

In the camelContext.xml, 在camelContext.xml中,

we have defined 我们已经定义

 <route streamCache="true">
            <from uri="direct:setUpload" />
            <recipientList>
                <simple>cxfrs://{{uploadSample.url}}?throwExceptionOnFailure=false</simple>
            </recipientList>
            <unmarshal ref="sampleParser" />
        </route>

Do we need to set any other things to gzip the body JSON request 我们是否需要设置其他任何内容以gzip正文JSON请求

Please help how to correct this 请帮助解决此问题

Regards Hari 问候哈里

You can try to convert json string to gzip before recipient list. 您可以尝试在收件人列表之前将json字符串转换为gzip。

ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes());
exchange.setBody(out.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM