dev@jersey.java.net

JSONPContainerResponseFilter.java

From: Felix Berger <bflat1_at_gmx.net>
Date: Thu, 15 Jul 2010 12:05:30 -0400

I wrote a ContainerResponseFilter that transforms JSON responses into
JSONP responses if the query parameters of the request url contain a
callback argument.

If http://host/api/search?q=foo returns

Content-Type: application/json

 ["foo1", "foo2"]

http://host/api/search?q=foo?callback=functionName will return

Content-Type: application/javascript

functionName(["foo1", "foo2"]);

The code can be found here.

http://gist.github.com/476245

I've been looking for something like this, so I hope it's useful for
others too.

The filter doesn't apply if there are any cookies in the request or
there is an Authorization header to avoid any malicious xss attacks.

Any feedback is welcome.

Cheers,
Felix