[RSS]

Creating and consuming RESTful Web Service jMaki Components in Web Applications

This tutorial outlines the steps to create and consume jMaki components build from NB RESTful Web services projects.

To see how to create a mashup using REST jMaki component, go to "How to use Rest JMaki Table component"

Preparation:

0. Required Installations:

  • JDK 1.6.0_01
  • Latest NetBeans 6.0 bits - http://download.netbeans.org/netbeans/6.0/final/ (If you choose Full install, then GlassFish AppServer gets installed also)
  • GlassFish V2 - http://download.netbeans.org/netbeans/6.0/final/ or GF website (https://glassfish.dev.java.net/)
  • After installing NB 6.0, get NB 6.0 'RESTful Web Services' plugin from the NB 6.0 IDE menu "Tools->Plugins->Available Plugins. After installing the plugin(s), IDE restarts.


InstallRestPlugin.png

  • Also install the jMaki Ajax plugin (in IDE follow Tools->Plugins->Available Plugins,
then select 'jMaki Ajax support' and click 'Install' button), as shown below:


InstalljMakiPlugin.png

Note: You can also download org-netbeans-modules-sun-jmaki.nbm from jMaki Netbeans plugin area and install the plugin seperately.

1. Creating a 'CustomerDB' Web Project

First, you need to create a web project. In this case, we will use one of the samples that is included in the New Project wizard as our starting point.

  • Choose File > New Project. Under Categories, select Samples and then RESTful Web Services. Under Projects, select Customer Database, as shown below:


CreateCustomerDB.png

  • Click Next and click Finish.

The sample project opens in the IDE, with its project structure in the Projects window.

2. Testing the 'CustomerDB' RESTful Web Services

To test the application, do the following:

  • In the Projects window, right click the project and choose Test RESTful Web Services. The server starts and the browser opens, displaying the RESTful web client, which you can use for testing the interaction with the RESTful web service.


TestCustomerDB.png

  • Now, Select the '/customers' link and then click Test. Next, select a customer link (such as '/customers/1/') and then click Test again.


TestPage.png

Create jMaki widget

1. Create REST jMaki components from 'CustomerDB' RESTful Web Services

First, you need to create a web project.

  • Choose File > New Project. Under Categories, select Web and then enter 'CustomerTestApp', as shown below:


CreateClientApp.png

  • Click 'Next', then select 'jMaki Ajax Framework', as shown below:


SelectjMakiFramework.png

  • Invoke action to create REST jMaki components, as shown below:


GenerateClientComponents.png

  • Add RESTful Web Service projects, as shown below:


AddCustomerDB.png

  • On 'Finish' jMaki components are created under '/CustomerTestApp/Web Pages/resources/dojo/rest'. A zip file 'CustomerDB.zip' is also created (as shown below). The contents and the structure of the zip file is same as that laid out on the '/CustomerTestApp/Web Pages' directory.


ZipStructure.png

2. Testing CustomerDB jMaki components in 'CustomerTestApp'

To test the application, do the following:

  • In the Projects window, navigate to 'TestResourcesTable.jsp', then right click and run this file.


RunjMakiTest.png

  • The server starts and the browser opens, displaying the Customers in a table. You can also do 'Add', 'Update' and 'Delete' operations, thus fulfilling the CRUD (Create, Retrieve, Update and Delete) functionality of a RESTful Web Service (in this case 'CustomerService').


DojoResult.png

3. Using CustomerDB jMaki components in Web Applications

To use the REST jMaki components in another web project, do the following.

  • Invoke Tools -> Palette -> Add jMaki Library


AddNewComp.png

  • Load the 'CustomerDB.zip'


AddNewComp1.png

  • CustomerDB Category with 'Customers Service' and 'DiscountCodes Service' shows up as palette items.


CustomerDBService.png

4. Testing CustomerDB jMaki component tags in a Web Application

To test the newly created jMaki components, do the following

  • Create a web project.
  • Choose File > New Project. Under Categories, select Web and then enter 'MyApp', as shown below:


NewAppConsumejMaki.png

  • Click Next and click Finish.

The sample project opens in the IDE, with its project structure in the Projects window.

  • Drag-n-Drop the 'Customers Service' to index.jsp of this app.


CustomerDBServiceDnD.png

A tag entry is made in the jsp page.

  • Now run index.jsp


RunJsp.png

  • The server starts and the browser opens, displaying the Customers in a table.


MyAppCustomerDBResult.png

Attachments

AddCustomerDB.png Info on AddCustomerDB.png 68055 bytes
AddNewComp.png Info on AddNewComp.png 223626 bytes
AddNewComp1.png Info on AddNewComp1.png 47814 bytes
CreateClientApp.png Info on CreateClientApp.png 68508 bytes
CreateCustomerDB.png Info on CreateCustomerDB.png 73826 bytes
CustomerDBService.png Info on CustomerDBService.png 12941 bytes
CustomerDBServiceDnD.png Info on CustomerDBServiceDnD.png 107171 bytes
CustomerJMakiApp.zip Info on CustomerJMakiApp.zip 2212788 bytes
DojoResult.png Info on DojoResult.png 69534 bytes
GenerateClientComponents.png Info on GenerateClientComponents.png 135761 bytes
GeneratedFileStructure.png Info on GeneratedFileStructure.png 199575 bytes
InstallRestPlugin.png Info on InstallRestPlugin.png 129485 bytes
InstalljMakiPlugin.png Info on InstalljMakiPlugin.png 122446 bytes
JMakiRestLayout.png Info on JMakiRestLayout.png 384238 bytes
JMakiRestZip.png Info on JMakiRestZip.png 281417 bytes
MyAppCustomerDBResult.png Info on MyAppCustomerDBResult.png 76203 bytes
NewAppConsumejMaki.png Info on NewAppConsumejMaki.png 67919 bytes
RestStubs.png Info on RestStubs.png 327224 bytes
RunDojoTest.png Info on RunDojoTest.png 59273 bytes
RunJsp.png Info on RunJsp.png 43133 bytes
RunjMakiTest.png Info on RunjMakiTest.png 61795 bytes
SelectjMakiFramework.png Info on SelectjMakiFramework.png 67050 bytes
TestCustomerDB.png Info on TestCustomerDB.png 68812 bytes
TestDojoRest.png Info on TestDojoRest.png 285091 bytes
TestJMakiRest.png Info on TestJMakiRest.png 251031 bytes
TestPage.png Info on TestPage.png 81134 bytes
TestStubs.png Info on TestStubs.png 444176 bytes
ZipStructure.png Info on ZipStructure.png 60842 bytes
jMakiTestResult.png Info on jMakiTestResult.png 115986 bytes