Flowerchild.

Cube and Jersey Dropwizard SyntaxError: Unexpected Token /u001f

Tuesday, August 06, 2013

We’re experimenting with Cube which is a tool that aggregates and indexes a bunch of events, and allows you to query them to produce live dashboards etc. It’s written in javascript, and runs on node with a MongoDb back end.

We’re calling it from a Dropwizard java service, which used Jersey’s client under the hood, but when we posted an event into Cube, we got a slightly weird error, a 400 (bad request) with the following message:

1

SyntaxError: Unexpected token \u001f

tl:dr

add the following to the httpClient section of your Dropwizard config,

1

gzipEnabledForRequests:false

Long version:

What seems to happen is that Jersey’s client gzip encodes all requests by default, (and duly sets the Content-Encoding header to gzip).

We used Charles Proxy to look at the request – and noticed that the first character of the compressed request is “1f” in hex, which happens to be the hex representation of the offending unicode character “\u001f” (which is an obscure non-printing control character, and a big fat red herring.)

So either Cube, or node or something is unable to accept gzip encoded requests, and barfs out a bad request.