Hierarchical Web Service Development with NetBeans IDE
Hierarchical Web Service Development with NetBeans IDE
Join the DZone community and get the full member experience.Join For Free
Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.
This article is based on the NetBeans e-Commerce tutorial that is available here:
- Note: The reader should first go through this really fascinating work which demonstrates how an end-to-end retail application can be built using Web Services, Session Beans, and Entities with a MySQL database at the backend. It also uses Servlets on the application layer and JSPs on the presentation layer.
This article extends the e-commerce tutorial by building a client application which has a Web Service of its own which uses the Web Services published by the retail application. I would like to thank my colleague Sushanta Chakraborty as co-author of this article. He helped a lot in the development of the project as well as in writing the text below.
The Client also has a Servlet which can be accessed by browser clients. These browser clients use the Web services of the client to access the Web Services of the Server and thus multiple client customers can transact in the online retail store concurrently. There can be multiple instances of the Web Client, each of which can serve multiple customers concurrently, all accessing the same Retail Application Server.
We refer to this as 1st Level Client Web Services.
This model can easily be extended in a similar fashion to another level of clients, 2nd Level Clients, who publish their services based on the 1st level client web services. Both these scenarios are depicted in the diagrams below.
Fig 1. Ist Level Client with Web Services based on Web Services of Retail Application Server
Fig 2. 2nd Level Client with Web Services based on Web Services of 1st Level Client
This solution is hierarchical and flexible and scalable. At the same time, it preserves consistency in concurrent client access of a retail database at the Retail Application server.
Unzip and extract all the files from the SUPPLYCHAINSUPPORTINGS.zip attached. A MySQL database has been used in this project. Ensure you have MySQL installed. (We have used MySQL Server 5.5 on Windows.) Use mysql dump to extract the tables from the “mydb.sql” file in the zipped attachment. The following sequence of commands can be used to extract the tables:
mysql> CREATE DATABASE IF NOT EXISTS myOwnDb; mysql> USE myOwnDb; mysql> source C:\jvsql\mydb.sql;The "myOwnDb" is the database you are creting to host the tables in “mydb.sql”. The path of the “mydb.sql” file should be mentioned. Above, we have stored mydb.sql in C:\jvsql. The table structure is shown below.
Figure 3: Retail Supply Chain Table Design
1. category Table shows the different types of food products like grains, cereals, oils, beverages etc.
2. customer Table has all customer details
3. customer_order table has details of each order including customer_id
4. ordered_product has all product-ids for a customer_order
5. product table has products of all types icluding price and quantity on hand
6. Supplier table has supplier details
7. Finally userauth table is a table used for authentication of user with a simple password for each user and corresponding customer_id
Note: SupplierDemand table, table which gives quotes per supplier per product , has not been used, although specified in project for the sake of completeness.
Tables we used were similar to the ones in the ecommerce example, the supplier table and the auth table have been added for incorporating replenishment of products by suppliers and for user authentication respectively. Although user authentication has been implemented, suplier replenishment has not been incorporated as of now in the sample project in the attachment. Once these tables are extracted you need to populate this table in order to test the application.
Retail Application Server with Web Service and Client Web Service
After unzipping and extracting the SUPPLYCHAINSUPPORTINGS.zip, load the SuppChain_Server and SuppChain_Client projects in NeBbeans IDE. We used NetBeans IDE 7.0.1.
Fig 4: Entities and Session Beans
In the SuppChain_Server project, the entities and session beans (Façade and Local) were automatically generated based on the database design. As can be seen there is one entity per table. Correspondingly Façade and Local session beans have been generated by NetBeans as per table. The only addition with respect to the ecommerce application is the addition of the OnePointSess and OrderProd sessin beans which were customize session beans which used the services of the NetBeans created session beans. These beans are used to develop the client side Web Services as will be explained later. All these beans can be inspected in the Source Packages folder as show in Fig 5.
Fig 5: Session Beans in SupplyChain_Server
UI for Supply Chain Server
The UI for Supply Chain Server is more or less same as the ecommerce application. Clients can access the servelet and the servlet uses the Web Services defined to give the on line retail application functionality as described in the ecommerce application.
Client Web Service
Follow the steps outlined below to create the client web services.
Fig 6: Creating Client Web Service
Fig 7: How to invoke WSDL and Client Location
Servlet and UI for Client Web Service
The Servlet and UI for the Client Web Service are designed in a similar fashion, the code can be examined in the folders: Web Pages/WEB-INF/view for the jsp pages and Source Packages/SuppChainServ.java for the servlet. The flow of control from the user to the client Web Services and the Retail Application Web Services and beans can be seen in the following depiction. The flow for the user authentication is shown. Similarly the flow for the transactions can be similarly visualized.
Fig 8: Flow of Control for Customer Authentication from Customer to Client Web Serve to Retail Application Web Service.
Screen CapturesSome screencaptures of the final application are shown below. All contemporary screens have been captured and included in the zip file.
Fig 9a: Customer Login
Fig 9b: Browsing Product Categories
Fig 10: Adding to Shopping Cart
Fig 11: Modifying Shopping Cart
Fig 12: Finalized Shopping Cart
Running the Projects
The Suplychain_Servr and SupplyChain_Client projects can be built and run. MySQL with JDBC connectivity should be configured. Browsers from remote systems can connect to the SuplyChain_Client sevlet and invoke the Web Services at Client and Server for shopping on the retail food chain. The database should be populated initially with suitable categories of food products and the corresonding products for each category with prices.
Opinions expressed by DZone contributors are their own.