users@jersey.java.net

Re: [Jersey] JSONP Callback support

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 03 Feb 2009 09:18:30 +0100

Hi Farrukh,

it is great you managed to implement the workaround.
Besides this, i am going to provide a javascript wrapper
and a special entity provider as Paul suggested
in the issue report [1].
If time allows me, it would go into 1.0.2, but i am
not 100 % sure i will manage it.

~Jakub

[1]https://jersey.dev.java.net/issues/show_bug.cgi?id=180

On Mon, Feb 02, 2009 at 09:21:24PM -0500, Farrukh Najmi wrote:
> Farrukh Najmi wrote:
>> Farrukh Najmi wrote:
>>> Farrukh Najmi wrote:
>>>>
>>>> Hi Guys,
>>>>
>>>> I am in need of JSONP Callback support mentioned in this post:
>>>>
>>>> <http://n2.nabble.com/-Filter--how-to-customize-context-body---td2116754.html>
>>>>
>>>> Has there been any progress on that front? Is an issue logged yet? Is
>>>> there a fix in svn yet?
>>>>
>>>> Please let me know. Thanks.
>>>>
>>>
>>> Just found the issue here:
>>>
>>> <https://jersey.dev.java.net/issues/show_bug.cgi?id=180>
>>>
>>> I would really appreciate some idea from dev team when this could be
>>> available in svn as it is a critical issue for me and likely many other
>>> folks. If it will be a while then I would be grateful if someone could
>>> expand a little on how to do the workaround suggest by Paul in cited
>>> thread above where an Adpater is used in a Response Filter. Thanks.
>>>
>>
>> So I tried out the workaround suggested by Paul:
>>
>> I implemented a ResponseFilter as follows. Note JSONCallbackResponseFilter
>> is "static final" class because it is nested inside another class
>> 'xxx.SomeClass':
>>
>>
>> public static final class JSONCallbackResponseFilter implements
>> ContainerResponseFilter {
>>
>> public ContainerResponse filter(ContainerRequest request,
>> ContainerResponse response) {
>>
>> MultivaluedMap<String, String> queryParamsMapMulti =
>> request.getQueryParameters();
>> Map queryParamsMap =
>> convertMultiToSingleValueMap(queryParamsMapMulti);
>> LOG.debug("JSONCallbackResponseFilter queryParamsMap=" +
>> queryParamsMap);
>> String callback = (String) queryParamsMap.get("callback");
>> LOG.debug("callback=" + callback);
>> if (callback != null) {
>> response.setContainerResponseWriter(new
>> JSONCallbackResponseAdapter(response.getContainerResponseWriter(),
>> callback));
>> }
>> return response;
>> }
>>
>> /**
>> *
>> * See:
>> http://n2.nabble.com/-Filter--how-to-customize-context-body---td2116754.html
>> */
>> private static final class JSONCallbackResponseAdapter implements
>> ContainerResponseWriter {
>> private final ContainerResponseWriter crw;
>>
>> private OutputStream out;
>> private String callback;
>>
>> JSONCallbackResponseAdapter(ContainerResponseWriter crw, String
>> callback) {
>> this.crw = crw;
>> this.callback = callback;
>> }
>>
>> public OutputStream writeStatusAndHeaders(long contentLength,
>> ContainerResponse response) throws IOException {
>> out = crw.writeStatusAndHeaders(-1, response);
>>
>> out.write((this.callback + "(").getBytes());
>> return out;
>> }
>>
>> public void finish() throws IOException {
>> out.write(")".getBytes());
>> }
>> }
>> }
>>
>> I have the following in my web.xml:
>>
>> <servlet>
>> <servlet-name>Registry REST Interface</servlet-name>
>>
>> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
>> <init-param>
>>
>> <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
>> <param-value>xxx.SomeClass.JSONCallbackResponseFilter</param-value>
>> </init-param>
>> <load-on-startup>4</load-on-startup>
>> </servlet>
>>
>> What I am finding is that the ResponseFilter is never being called.
>>
>> Why would that be?
>>
> Apparently it has something to do with the JSONCallbackResponseFilter being
> a nested class. Once I made it a top level class all is well. I am all set
> on the workaround. Thanks.
>
> --
> Regards,
> Farrukh
>
> Web: http://www.wellfleetsoftware.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>