I have just committed support for JSONP to the RHQ REST-api.
To use it you need to pass an 'accept' header of
application/jsonp
as well as a parameter for the callback. Lets look at an example:
$ curl -i -u rhqadmin:rhqadmin \
http://localhost:7080/rest/1/alert?callback=foo \
-Haccept:application/jsonp
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 CET
X-Powered-By: Servlet 2.4; JBoss-4.2.0.CR2
Content-Type: application/javascript
Transfer-Encoding: chunked
Date: Thu, 14 Jun 2012 09:25:09 GMT
foo( [{"name":"test","resource":{"typeName":null, ……..])
The name of the callback parameter is callback and the name of the callback function to return is
foo . In the output of the server you see how the json-data is then wrapped inside foo() .
The wrapping will only happen when both the right content-type is requested and the callback parameter is present.
The content type returned is then
application/javascript
.Setting the name of the callback parameter
Then name of the callback parameter (callback in above example) can be set in
web.xml
:
<filter>
<filter-name>JsonPFilter</filter-name>
<filter-class>org.rhq.enterprise.rest.JsonPFilter</filter-class>
<init-param>
<param-name>filter.jsonp.callback</param-name>
<param-value>callback </param-value>
<description>Name of the callback to use for JsonP /description>
</init-param>
</filter>