RESTful Web Service - How To???

Hi Folks - we saw a demo at Servoy Camp of using Servoy 5 to make RESTful web services, but it was pretty quick and I did’nt get too many notes and what I did get I’m struggling to make sense of :? (I seem to recall a discussion that the Camp video would make it all clear LOL but that was after the bar opened so I may have hallucinated it :lol: ).

Are there any step-by-step guides available to implement this plugin (which Plugin is it)?

Hi Ian,

it’s not a plugin like ‘the others’. This is what I got from the wiki pages:

Added a REST webservice plugin, which makes it possible to expose (form) methods as REST API handlers:

  • The REST API is accessible through the url: ```
    http://domain:port/servoy-service/rest_ws/solutionName/formName
* The form needs to have the following methods:
o GET: ws_read()
o POST: ws_create()
o DELETE: ws_delete()
o PUT: ws_update()
* A sample solution is included in the Servoy distribution (servoy_sample_rest_ws.servoy), detailing how to retrieve data from the http request and to return a response.

So basically you need a solution with at least 1 form and 4 form-methods that will hold/call the code to be executed.

The sample solution can be found at “/application_server/solutions/examples”

Hope this helps!

Thanks Marc - that’s a good starter for us. Looked in the Wiki but didn’t search on REST Doh…

Cheers

Ian

FYI, I also have a plugin wich allows publishing Web Services from your application from Servoy version 3.x - current. Let me know if you are interested. It hasn’t been released yet, but will be soon. It also offers the ability to serialize JSDatasets to JSON to provider standard way of sharing data from your application.

goldcougar:
FYI, I also have a plugin wich allows publishing Web Services from your application from Servoy version 3.x - current. Let me know if you are interested. It hasn’t been released yet, but will be soon. It also offers the ability to serialize JSDatasets to JSON to provider standard way of sharing data from your application.

I’d be very interested to hear how that works Scott.

We currently don’t know what information we will need to share but we do know that there are three applications our Clients use that need to have interaction with our Solution (including SAP). Initially we want to make specific items of information available - and the demo of the REST services looks like it will do that, however doubtless we’ll need to share more sophisticated data as the Clients model of what he wants and his experience grows.

Hi, using v5.1rc3, when I send the following URL:
http://localhost:8080/servoy-service/rest_ws/servoy_sample_rest_ws/ws_employees
I get this error in FireFox:

XML Parsing Error: junk after document element
Location: http://localhost:8080/servoy-service/re … _employees
Line Number 2, Column 15:123456789java.util.ArrayList
--------------^

whereas Safari tells me this:

This page contains the following errors:

error on line 2 at column 10: Extra content at the end of the document
Below is a rendering of the page up to the first error.

I get a similar error if I specify an employee id:
in FireFox:

XML Parsing Error: junk after document element
Location: http://localhost:8080/servoy-service/re … mployees/2
Line Number 2, Column 30:Andrew2Fuller
-----------------------------^

in Safari:

This page contains the following errors:

error on line 2 at column 15: Extra content at the end of the document
Below is a rendering of the page up to the first error.

Andrew

Any clue as to what could be wrong? I’m using the original (unmodified) sample methods.

TIA,

Ben

goldcougar:
FYI, I also have a plugin wich allows publishing Web Services from your application from Servoy version 3.x - current. Let me know if you are interested. It hasn’t been released yet, but will be soon. It also offers the ability to serialize JSDatasets to JSON to provider standard way of sharing data from your application.

Hi Scott,

Is it possible to serialize XML documents into JSON?

So that I can do:

var str = plugins.serialize.toJSON(myXMLDocument)
var obj = plugins.serialize.fromJSON(str)
return obj; //  as result of a webservice

LOGIsoft:
Hi, using v5.1rc3, when I send the following URL:
http://localhost:8080/servoy-service/rest_ws/servoy_sample_rest_ws/ws_employees
I get this error in FireFox:

XML Parsing Error: junk after document element
Location: http://localhost:8080/servoy-service/re … _employees
Line Number 2, Column 15:123456789java.util.ArrayList
--------------^

whereas Safari tells me this:

This page contains the following errors:

error on line 2 at column 10: Extra content at the end of the document
Below is a rendering of the page up to the first error.

I get a similar error if I specify an employee id:
in FireFox:

XML Parsing Error: junk after document element
Location: http://localhost:8080/servoy-service/re … mployees/2
Line Number 2, Column 30:Andrew2Fuller
-----------------------------^

in Safari:

This page contains the following errors:

error on line 2 at column 15: Extra content at the end of the document
Below is a rendering of the page up to the first error.

Andrew

Any clue as to what could be wrong? I’m using the original (unmodified) sample methods.

TIA,

Ben

Ben how does your call to the webservice look like? (The object/XML dcument that you want to post on the service, not the http call)

LOGIsoft:
Any clue as to what could be wrong? I’m using the original (unmodified) sample methods.

Ben,

RESTful webservices are not meant for browsers to be clients, you have to use a client that speaks http and understands the xml or json response.

We also shipped the test-page that Jan Blok used in the ServoyCamp demo which is an easy tool for testing/debugging your ws solution, the default url for this is:

http://localhost:8080/examples/restfulws_testpage.html

Rob

Has this test page been updated?

I don’t see the server result on the page

RESTful webservices are not meant for browsers to be clients, you have to use a client that speaks http and understands the xml or json response.

We also shipped the test-page that Jan Blok used in the ServoyCamp demo which is an easy tool for testing/debugging your ws solution, the default url for this is:

http://localhost:8080/examples/restfulws_testpage.html

Aha! That explains it, thanks Rob…

Ben how does your call to the webservice look like? (The object/XML dcument that you want to post on the service, not the http call)

Martin, I was just issuing a call in my browser address bar, so that was wrong… :oops:

Using the testpage, I receive this result when firing a GET from “http://localhost:8080/servoy-service/rest_ws/servoy_sample_rest_ws/ws_employees”:

<?xml version="1.0" encoding='UTF-8'?> <list>1</list><list>2</list><list>3</list><list>4</list><list>5</list><list>6</list><list>7</list><list>8</list><list>9</list><list>10</list><javaClass>java.util.ArrayList</javaClass>

How can we get the array of the rest of the data (not just a list of the ids), in other words “Nancy1Davolio”, “Andrew2Fuller”, etc. ?

martinh:
Has this test page been updated?

I don’t see the server result on the page

On my machine, the path is “file:///Applications/Servoy5.1/application_server/server/webapps/ROOT/examples/restfulws_testpage.html”

HTH,

Ben

Hi guys,
I’ve got a solution that runs gracefully in smartclient. Now I need to expose data to a webapp through RESTfull WS plugin, so I took the form and wrote the ws_read() method, but when i try to retrieve data, I get a 500 and this instead:

org.apache.wicket.WicketRuntimeException: There is no application attached to current thread http-8080-1 
    	at org.apache.wicket.Application.get(Application.java:179) 
    	at org.apache.wicket.Component.getApplication(Component.java:1323) 
    	at org.apache.wicket.Component.<init>(Component.java:920) 
    	at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:113) 
    	at org.apache.wicket.markup.html.WebMarkupContainer.<init>(WebMarkupContainer.java:49) 
    	at org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup.<init>(WebMarkupContainerWithAssociatedMarkup.java:51) 
    	at org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup.<init>(WebMarkupContainerWithAssociatedMarkup.java:43) 
    	at org.apache.wicket.markup.html.panel.Panel.<init>(Panel.java:76) 
    	at com.servoy.j2db.server.headlessclient.WebForm.<init>(WebForm.java:1) 
    	at com.servoy.j2db.server.headlessclient.Zf.Ze(Zf.java:56) 
    	at com.servoy.j2db.Zpb.<init>(Zpb.java:996) 
    	at com.servoy.j2db.Zwb.Zg(Zwb.java:10) 
    	at com.servoy.j2db.plugins.ClientPluginAccessProvider$MethodExecutor.run(ClientPluginAccessProvider.java:17) 
    	at com.servoy.j2db.plugins.ClientPluginAccessProvider.executeMethod(ClientPluginAccessProvider.java:87) 
    	at com.servoy.extensions.plugins.rest_ws.servlets.RestWSServlet.wsService(RestWSServlet.java:232) 
    	at com.servoy.extensions.plugins.rest_ws.servlets.RestWSServlet.doGet(RestWSServlet.java:72) 
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) 
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    	at com.servoy.j2db.server.servlets.WebServicesServlet.service(WebServicesServlet.java:35) 
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567) 
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) 
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) 
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) 
    	at java.lang.Thread.run(Unknown Source)

any suggestion?

Omar,

Do you have elements on the form?

Try use a form with the ws_* methods and no UI elements on the form.

Rob

You can check out ALL the ServoyCamp 2009 videos here:

MANY thanks to Harjo and Karel for making this happen!

Omar,

Btw, what version are you on?
Please try the latest (5.1).

Rob

Thanks to everyone for the answers, reading carefully the Wiki I found the problem, it was the Authentication, that is not supported.
Once removed I found a lot of problems with some “particular” listeners that I have in my solution, so I stop the tests because I can’t do anything without authentication.

I started a new Solution and everything goes well.

Thanks to all again.

Hi guys, I’ve got another question: is possible to reach the WS via https anyway? I tried with “https//: etcetera” and the result was 404 for each call.

You have to configure the tomcat instance first so that it has a https connecter that accepts stuff on 443 (default https port)

jcompagner:
You have to configure the tomcat instance first so that it has a https connecter that accepts stuff on 443 (default https port)

I’ll try, thanks for your quick response