Hi Paul,
This is a very common practice so you can use the service from a
<script> include within a web page. I am actually surprised that JAX-
RS doesn't support JSON callbacks out of the box because it is such a
widespread practice. For instance, all Yahoo web service APIs support
this as one of the result formats. It is generally referred to as
JSONP. There should likely be a provider that supports it:
http://en.wikipedia.org/wiki/JSON#JSONP
http://developer.yahoo.com/common/json.html#callbackparam
Sam
On Jan 6, 2009, at 1:58 AM, Paul Sandoz wrote:
> Hi,
>
> See the source code of the GZIP and logging filter:
>
> https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-server/src/main/java/com/sun/jersey/api/container/filter/GZIPContentEncodingFilter.java?view=markup
>
> https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-server/src/main/java/com/sun/jersey/api/container/filter/GZIPContentEncodingFilter.java?view=markup
>
> Your adapter could do something like this:
>
> private static final class Adapter implements
> ContainerResponseWriter {
> private final ContainerResponseWriter crw;
>
> private OutputStream out;
>
> Adapter(ContainerResponseWriter crw) {
> this.crw = crw;
> }
>
> public OutputStream writeStatusAndHeaders(long
> contentLength, ContainerResponse response) throws IOException {
> out = crw.writeStatusAndHeaders(-1, response);
>
> out.write("zzz(".getBytes());
> return out;
> }
>
> public void finish() throws IOException {
> out.write(")".getBytes());
> }
> }
>
> And you register it like this:
>
> if(query string 'callback' is set) {
> response.setContainerResponseWriter(
> new
> Adapter(response.getContainerResponseWriter()));
> }
>
> But. given that the client states what the function should be in the
> query parameter why can't it do the work itself and wrap the JSON
> around the function? why it is necessary to do this on the server
> side?
>
> Paul.
>
> On Jan 6, 2009, at 7:25 AM, À¯Àç±Õ wrote:
>
>> Thank you Sandoz.
>>
>> https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=3746
>> this question is related above url.
>>
>> I have make Filter class.
>> --------------------------------------------------------------
>> public class JsonCallbackFilter implements ContainerResponseFilter{
>> public ContainerResponse filter(ContainerRequest request,
>> ContainerResponse response) {
>> if(query string 'callback' is set) {
>> ContainerResponseWriter crw =
>> response.getContainerResponseWriter();
>>
>> // TODO how to add 'callback' value ???
>>
>> response.setContainerResponseWriter(crw);
>> }
>> return response;
>> }
>> --------------------------------------------------------------
>>
>> the request url is like this.
>> http://xxxxxxxxxx/member/info?name=yyy&callback=zzz&type=json
>>
>> and expected result is
>> zzz({"code":"12312","name":"yyy"})
>>
>>
>> please help me.
>>
>> °³ÀοëÀÚ·á - Á¢±Ù±ÝÁö
>>
>> Ãâó°¡ ¸íÈ®ÇÏÁö ¾ÊÀº °Ô½Ã¹°ÀÌ ¸¹ÀÌ Æ÷ÇԵǾîÀÖ½À´Ï´Ù.
>> °ü°èÀÚ°¡ ¾Æ´ÑºÐÀº ¹æ¹®À» »ï°¡ÇØ ÁֽʽÿÀ.
>>
>