You can reuse RESTful client stubs in multiple web applications by wrapping the stub in jMaki components, also called a jMaki "widget." This tutorial shows you how to create a RESTful client as a jMaki widget and use the widget in other web applications.
Contents
To follow this tutorial, you need the following software and resources.
GlassFish can be installed with the Web and Java EE distribution of NetBeans IDE. Alternatively, you can visit the GlassFish downloads page.
This tutorial also requires the RESTful Web Services and jMaki Ajax Support plugins. In the IDE, go to the Plugin Manager, under the Tools menu, and check whether the RESTful Web Services and jMaki Ajax Support Plugins are installed, under the Installed tab. If either plugin is not installed, install it from the Available Plugins tab, as shown below for RESTful Web Services:
NetBeans IDE comes with a sample CustomerDB RESTful Web Service. (Alternatively, you can create this service yourself, as shown in Getting Started with RESTful Web Services.) You can use this sample in the New Projects wizard.
To use the sample CustomerDB Service:
Click Next and then click Finish. The sample project opens in the IDE, with its project structure in the Projects window. You can deploy and test the web service in a single step. In the Projects window, right click the project and choose Test RESTful Web Services.
The server starts and the IDE deploys the web service to the server. The browser then opens, displaying the test client.
To test the web service, select the /customers link and then click Test. Next, select a customer link (such as /customers/1/) and click Test again. The client displays code 200, "Success."
Create a jMaki framework-enabled web application to which you will add the RESTful client stubs.
To create a jMaki framework-enabled web application.
Create RESTful client stubs in the jMaki-enabled web application you created in the previous step.
To create the client stubs.
The New RESTful Web Service Client Stubs dialog opens. Click Add Project and browse for the CustomerDB Project. Leave all other settings at default and click Finish.
The IDE creates jMaki components under /CustomerTestApp/web/resources/dojo/rest. The IDE also creats an archive file named CustomerDB.zip (as shown below). The contents and the structure of the archive file are the same as the contents and the structure of the /CustomerTestApp/web directory.
Using NetBeans IDE, you can build, deploy and test the client stubs with a single action.
To test the client stubs.
The server starts and the browser opens, displaying the Customers in a table, displaying the Customer table jMaki Widget. In the drop-down field, select Customers, and a table of the customers from CustomerDB opens. You can perform all CRUD (Create, Retrieve, Update and Delete) functions in this table and the RESTful Web Service propagates your changes to the database.
The jMaki component customerstable uses the CustomersStore dojo component (also generated by the IDE). To test the dojo component, navigate to TestResourcesTable.html, then right-click the file node and select Run File.
NetBeans IDE makes it easy to reuse RESTful web service client stubs in other web applications. When you generate jMaki-enabled RESTful web service client stubs, you automatically create a jMaki component archive of the client stubs. Add the archive file to the IDE's palette for JSP and HTML pages. Then you can drag and drop the client stubs into other web applications.
To add client stub jMaki components to the IDE's palette.
A dialog opens in which you browse for the jMaki component archive to add to the palette. Browse for the CustomerDB.zip file, which is in the top level of the CustomerTestApp project.
When you open a JSP page or HTML file, the Palette now includes the CustomerDB category, which contains the Customers and DiscountCodes services. (You may need to open the palette window from the Window menu.)
With the CustomerDB category in the palette, you can now test how the client stub jMaki components work in another web application.
To test the jMaki Client Stubs.
A tag entry is now added to index.jsp. Click Ctrl-S to save the page.
In the Projects window, right-click the index.jsp node and select Run File from the context menu. The IDE builds the file and starts the server. A browser window opens, displaying the customers in a table.
For more information about using NetBeans IDE to develop Java EE applications, see the following resources:
To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE Java EE development features, join the mailing list.
You are viewing a mobilized version of this site...
View original page here