jMaki Widgets Talking To Jersey Resources In JSON

In the recent post, i have announced an improvement in JSON format produced by Jersey.
Here i would like to show how you can easily consume the new format by jMaki widgets.
An example of what you can get is shown below.

Jersey back-end resources are already available within Jersey examples as jMakiBackend web application. You just need to obtain the latest Jersey bundle and then build and deploy the jMakiBackend example via following:


% cd jersey-0.6-ea/examples/jMakiBackend
% ant
% $AS_HOME/bin/asadmin start-domain
% $AS_HOME/bin/asadmin deploy dist/jMakiBackend.war

You can then test your Jersey resources:


% curl http://localhost:8080/jMakiBackend/webresources/printers/jMakiTable
{"columns":[{"id":"id","label":"Printer ID"},
{"id":"model","label":"Model"},{"id":"url","label":"URL"},{"id":"location","label":"Location"}],
"rows":[{"id":"P05","model":"Xerox345","url":"lpd://p05","location":"room 543"},
{"id":"P02","model":"OKI123","url":"lpd://p02","location":"room 12"},
{"id":"P06","model":"Xerox345","url":"lpd://p06","location":"room 203"},
{"id":"P03","model":"OKI123","url":"lpd://p03","location":"room 133"},
{"id":"P01","model":"OKI123","url":"lpd://p01","location":"room 1"}]}


%curl http://localhost:8080/jMakiBackend/webresources/printers/jMakiTree
{"root":{"label":"printers","expanded":true,
"children":[{"label":"Model Xerox345","expanded":true,"children":
[{"label":"P05 @ room 543","expanded":false},
{"label":"P06 @ room 203","expanded":false}]},
{"label":"Model OKI123","expanded":true,"children":
[{"label":"P02 @ room 12","expanded":false},
{"label":"P03 @ room 133","expanded":false},
{"label":"P01 @ room 1","expanded":false}]}]}}

Connecting jMaki widgets is very simple.
You just create a new web application in Netbeans 6 (provided you have jMaki/AJAX plugin already installed), drag and drop Yahoo table or Dojo tree widget to your page and set the widget service parameter to an appropriate URI.

Besides the two jMaki friendly resources, you can also manipulate the underlaying data
via http://localhost:8080/jMakiBackend/webresources/printers/ids/{printerid} URI.
GET, PUT and DELETE HTTP methods are available on it providing access to getting,
creating/updating and deleting particular printer records.


%curl http://localhost:8080/jMakiBackend/webresources/printers/ids/P01
{"id":"P01","model":"OKI123","url":"lpd://p01","location":"room 1"}


%curl -i -X PUT -HContent-type:application/json \\
--data '{"id":"P01","model":"OKI123456","url":"lpd://p01.b02","location":"big showroom"}' \\
http://localhost:8080/jMakiBackend/webresources/printers/ids/P01
HTTP/1.1 204 No Content
X-Powered-By: Servlet/2.5
Server: Sun Java System Application Server 9.1.1
Date: Sat, 23 Feb 2008 08:15:01 GMT


% curl -i -X DELETE http://localhost:8080/jMakiBackend/webresources/printers/ids/P01
HTTP/1.1 204 No Content
X-Powered-By: Servlet/2.5
Server: Sun Java System Application Server 9.1.1
Date: Sat, 23 Feb 2008 08:17:29 GMT

For detailed information on JAXB beans used for the jMaki models please look at the jMakiBackend example code here and here

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jakub Podlesak

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today