Search code examples
encodingcharacter-encodinggzipapache-camelrestlet

Camel Restlet GZIP Charset Encoding


I'm creating a camel web application exposing a REST endpoint via the camel-restlet component and am having some issues with character encodings of the compressed xml responses.

I have manually set Content-Type and charset to text/xml and UTF-8 respectively; set the Content-Encoding to gzip and have used the <marshal><gzip/></marshal> pattern as the final component in the camel route in order to return a gzipped payload to the client.

The returned payload from the route results in an invalid gzipped file. I have inspected the payloads using Notepad++ at each stage of the gzip marshal and transfer - seeing my valid XML before- and a valid gzipped file after the <marshal/> step but the response that is received by the client appears to have been encoded differently by the restlet component.

The normal [US]< initial header is displayed in the valid gzip file in Notepad++, however the < has been encoded as � in the response from the restlet, along with different representations of the other printable characters. This is returned both to curl and my client with Accept-Encoding: gzip- which leads me to suspect that I need to remove/change a default character encoding in the restlet component. Removing the charset header gives me a different, still incorrectly-encoded response, which seems to confirm my suspicions.

If I'm correct in thinking restlet is the component causing the change in encoding of the binary data, which encoding should I set/remove, and if not, what should I be looking for to output valid gzipped payloads via restlet?

Many thanks for taking the time to read,

mids


Solution

  • I decided in the end to opt for a Servlet setup - I could not see in the end, how I could use the restlet to achieve what I wanted.

    Setting the headers Exchange.HTTP_CHARACTER_ENCODING to UTF-8 and Exchange.SKIP_GZIP_ENCODING to false, and removing my <marshal><gzip/></marshal> component left the gzip compression to be dealt with automatically by the default transport settings for the servlet.

    Adding the additional <servlet>...</servlet> and <servlet-mapping>...</servlet-mapping> to my web.xml file and consuming on servlet:///exposedEndpoint enabled me to consume the messages in my client using gzip with no further issues.

    -mids