2
votes

I am using apache camel for rest service calls from spring

Now we need to send the json request in our body to be passed in GZIP using apache camel. I tried by adding CONTENT_ENCODING as gzip, but it does not work. Please see the code

public void process(Exchange exchange) { exchange.setPattern(ExchangePattern.InOut); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); Message inMessage = exchange.getIn(); inMessage.setHeader(ACCEPT_HEADER, "application/json"); inMessage.setHeader(CONTENT_TYPE, "application/json"); inMessage.setHeader(Constants.ACCEPT_ENCODING, Constants.ACCEPT_ENCODING_TYPE); inMessage.setHeader(Exchange.CONTENT_ENCODING, "gzip"); inMessage.setBody(body);

In the 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

Please help how to correct this

Regards Hari

1
add a gzip endpoint before recipientList and give a try.Sureshkumar Panneerselvan
thank you for your suggestion, I tried it , but does not solve the issue, The json request does not get gzipped after giving end pointuser2907217
You can set the [@org.apache.cxf.annotations.GZIP][1] annotation in the service class method. [1]: stackoverflow.com/questions/10784422/…Willem Jiang
thank you for your suggestion, I am getting the error , java.util.ArrayList cannot be cast to org.apache.cxf.message.MessageContentsList. Do you know whether there is any issue with the type converter if the type becomes byte arrayuser2907217

1 Answers

0
votes

You can try to convert json string to gzip before recipient list.

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