You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by sdale <sd...@toronto.ca> on 2010/09/17 20:11:54 UTC

callback function not wrapped in returned json

I am using Apache Wink 1.1.1, with Jackson for json processing.

I am using the dojo toolkit to call the generated rest service.

When I call the rest service is returns the json data, but does not wrap the
callback function in the return...

This is what is returned: {"addressResults":[],"intersectionResults":[],....

When it should be: 
dojo.io.script.jsonp_dojoIoScript3._jsonpCallback(
{"addressResults":[],"intersectionResults":[],....

Should wink do this wrapping of the callback function in the json return or
do I manually have to do this?

Thanks in advance,
Steve

Here is a sample of the dojo code....

function search() {
			 var def = dojo.io.script.get({
			    url:
"http://tormv411.corp.toronto.ca/gcc_rest_geocoder/rest/search_V5?searchTerm=1%20Yonge%20/%20St%20Clair&level=1&searchArea=1&matchType=1&prj=1&minScoreName=30&minScoreSndx=40&retMinFullScore=20&retRowLimit=50",
				timeout: 5000,
				handleAs: "json",
				preventCache: true,
				callbackParamName: "callback",
				load: function(data) {
         			alert(data);
         			var results = data.addressResults; // array of photo info
         				dojo.forEach(results, function(result){
     	     			alert(result.key_Desc);
     	   			});
				}
				,error: function(err, ioArgs) {
      
            		alert(err.toString());
            		console.log(err.toString());
           			 return;
          		}        
			});
      
		}

-- 
View this message in context: http://apache-wink-users.3471013.n2.nabble.com/callback-function-not-wrapped-in-returned-json-tp5543799p5543799.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: callback function not wrapped in returned json

Posted by sdale <sd...@toronto.ca>.
Thanks,
This did the trick.. works perfectly now.
-- 
View this message in context: http://apache-wink-users.3471013.n2.nabble.com/callback-function-not-wrapped-in-returned-json-tp5543799p5550563.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: callback function not wrapped in returned json

Posted by Bryant Luk <br...@gmail.com>.
You can probably add a custom provider that extends the Jackson one
which wraps the callback.  We already have something for the json.org
classes:

http://svn.apache.org/repos/asf/incubator/wink/trunk/wink-providers/wink-json-provider/src/main/java/org/apache/wink/providers/json/JsonProvider.java

For Jackson, it may look like:

    @Provider
    public static class JacksonJsonCallbackProvider extends
JacksonJsonProvider {

        @Context
        private UriInfo uriInfo;

        public void writeTo(Object value,
                            Class<?> type,
                            Type genericType,
                            Annotation[] annotations,
                            MediaType mediaType,
                            MultivaluedMap<String, Object> httpHeaders,
                            OutputStream entityStream) throws IOException {

            String callbackParam =
uriInfo.getQueryParameters().getFirst("callback");
            Charset charset =
Charset.forName(ProviderUtils.getCharset(mediaType));
            OutputStreamWriter writer = new
OutputStreamWriter(entityStream, charset);
            if (callbackParam != null) {
                writer.write(callbackParam);
                writer.write("(");
                writer.flush();
            }
            super.writeTo(value,
                          type,
                          genericType,
                          annotations,
                          mediaType,
                          httpHeaders,
                          entityStream);
            if (callbackParam != null) {
                writer.write(")");
            }
            writer.flush();
        }
    }

Then annotate your resource URL with your particular callback function
name.  So "http://tormv411.corp.toronto.ca/gcc_rest_geocoder/rest/search_V5?......&callback=callback
.

If you want Wink to handle it, please open a JIRA.

On Fri, Sep 17, 2010 at 1:11 PM, sdale <sd...@toronto.ca> wrote:
>
> I am using Apache Wink 1.1.1, with Jackson for json processing.
>
> I am using the dojo toolkit to call the generated rest service.
>
> When I call the rest service is returns the json data, but does not wrap the
> callback function in the return...
>
> This is what is returned: {"addressResults":[],"intersectionResults":[],....
>
> When it should be:
> dojo.io.script.jsonp_dojoIoScript3._jsonpCallback(
> {"addressResults":[],"intersectionResults":[],....
>
> Should wink do this wrapping of the callback function in the json return or
> do I manually have to do this?
>
> Thanks in advance,
> Steve
>
> Here is a sample of the dojo code....
>
> function search() {
>                         var def = dojo.io.script.get({
>                            url:
> "http://tormv411.corp.toronto.ca/gcc_rest_geocoder/rest/search_V5?searchTerm=1%20Yonge%20/%20St%20Clair&level=1&searchArea=1&matchType=1&prj=1&minScoreName=30&minScoreSndx=40&retMinFullScore=20&retRowLimit=50",
>                                timeout: 5000,
>                                handleAs: "json",
>                                preventCache: true,
>                                callbackParamName: "callback",
>                                load: function(data) {
>                                alert(data);
>                                var results = data.addressResults; // array of photo info
>                                        dojo.forEach(results, function(result){
>                                alert(result.key_Desc);
>                                });
>                                }
>                                ,error: function(err, ioArgs) {
>
>                        alert(err.toString());
>                        console.log(err.toString());
>                                 return;
>                        }
>                        });
>
>                }
>
> --
> View this message in context: http://apache-wink-users.3471013.n2.nabble.com/callback-function-not-wrapped-in-returned-json-tp5543799p5543799.html
> Sent from the Apache Wink Users mailing list archive at Nabble.com.
>