Add JSONP support to WebServices plugin

Discuss all feature requests you have for a new Servoy versions here. Make sure to be clear about what you want, provide an example and indicate how important the feature is for you

Add JSONP support to WebServices plugin

Postby sbutler » Tue Jul 06, 2010 6:04 pm

When accessing web services through javascript, you are limited to your single domain because of the extra security measurers with cross-domain policy stuff. jQuery supports the JSONP approach to solving this problem. Essentially it adds call back support to the web service. So the webservice itself returns back a function object with the JSON data inside of the function. Then jQuery modifies the DOM and inserts the returned object back as a script object. More info: http://en.wikipedia.org/wiki/JSON#JSONP

So, a webservice call may look like this:
Code: Select all
http://domain/servoy-service/rest_ws/SOLUTION/FORM

and return something like
Code: Select all
{ "hello" : "Hi, I'm JSON. Who are you?"}


Instead, with a JSONP request the url would look like this:
Code: Select all
http://domain/servoy-service/rest_ws/SOLUTION/FORM?callback=myCallback

and return something like
Code: Select all
myCallback({ "hello" : "Hi, I'm JSON. Who are you?"})


This would allow you to use Servoy web services with jQuery. I know the rest_ws plugin is open source, so if I make the change, can I submit a patch for this to be included as a standard part of the plugin, or would you prefer this be done as a separate plugin?
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: Add JSONP support to WebServices plugin

Postby pbakker » Wed Jul 07, 2010 9:49 am

I'd say that if it can be added to the existing plugin, without breaking the existing implementation, it's best to include it into the existing plugin.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Add JSONP support to WebServices plugin

Postby rgansevles » Wed Jul 07, 2010 4:38 pm

Scott,

That should fit quite nicely in the plugin, just send us a patch.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Add JSONP support to WebServices plugin

Postby sbutler » Fri Jul 23, 2010 12:28 am

Attached is a signed build implementing JSONP if anyone wants to test. I have a working example using jQuery at my website

Also a patch is attached. (.patch attachments not allowed to be uploaded, so is .txt)
The only actual needed changes were in RestWSServlet class. However it looks like there were some pending changes in the RESTWSPlugin class in the getJSONSerializer() function that I had to revert back because it was breaking the usage of the plugin.
Attachments
rest_ws_JSONP.txt
patch
(1.43 KiB) Downloaded 358 times
rest_ws.jar
rest_ws plugin with JSONP support
(15.17 KiB) Downloaded 344 times
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: Add JSONP support to WebServices plugin

Postby jcompagner » Fri Jul 23, 2010 1:16 pm

so the only change is the json.toString() into that if that first checks for the callback parameter right?
I will commit this.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Add JSONP support to WebServices plugin

Postby jcompagner » Fri Jul 23, 2010 3:04 pm

The parameter name is now hardcoded. But is that the "spec" of JSONP? or can it be anything?
So should we make that a property?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Add JSONP support to WebServices plugin

Postby sbutler » Fri Jul 23, 2010 3:54 pm

jcompagner wrote:so the only change is the json.toString() into that if that first checks for the callback parameter right?.

Yes

jcompagner wrote:The parameter name is now hardcoded. But is that the "spec" of JSONP? or can it be anything?
So should we make that a property?


jQuery sets param name to "callback" automatically, but it can be overridden. That is similar to each javascript library, so the webpage connecting to the API should always be able to use "callback". I don't see any reason why it would need to be configurable as long as we document that "callback" is the name of the callback parameter for JSONP requests.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: Add JSONP support to WebServices plugin

Postby jcompagner » Fri Jul 23, 2010 4:08 pm

i havent seen any updated doc in that patch ;)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Add JSONP support to WebServices plugin

Postby pbakker » Fri Jul 23, 2010 4:10 pm

A hardcoded parameter name might conflict with existing implementations using the plugin. Secondly, if other systems define how the restful webservice is called and you just have to provide an implementation, the hardcoded value might cause problems.

May seem far fetched, but it can happen.

Just that fact that jQuery does it this way doesn't make it a standard.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Add JSONP support to WebServices plugin

Postby jcompagner » Fri Jul 23, 2010 4:16 pm

other systems dont define how the webservice is called
The webservice defines how it must be called.
You program against us as an api.. So yes then we have the doc where we define that callback param must be used for jsonp. Thats our api definition. I agree with Scott about that.

dont know about existing stuff that are using json as return values and use the callback as a parameter (so yes they now get different json back)
So in that case it is more like a boolean (jsonp support or not)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Add JSONP support to WebServices plugin

Postby Harjo » Fri Apr 15, 2011 11:42 am

Hi there,

we are bumping to the exact same issue, as Scott started this topic.
Is it save to use his version? without breaking other functionality?
As far as we see, this patch is not applied to the restfull plugin in 5.2.7.

When can we expect, this patch in the version of Servoy itself??
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Add JSONP support to WebServices plugin

Postby jcompagner » Mon Apr 18, 2011 10:32 am

harjo should have upgraded its developer! :)
Because that patch was already in from 5.2.1 on.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Add JSONP support to WebServices plugin

Postby Harjo » Mon Apr 18, 2011 11:17 am

yep!, it's working now! :-)
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands


Return to Discuss Feature Requests

Who is online

Users browsing this forum: Google [Bot] and 4 guests