|
Guidelines, Patterns, and code for end-to-end Java applications.
Java Pet Store Demo 1.3.1 > Changes made to enable Web-services
Changes made to enable Web-services in the Demo
Listed below are the changes that went into the
Java PetStore Demo sample application to showcase use of Web-services technologies
in the J2EE platform.
The pet store sample application has four distinct parts:
- The PetStore Website application
that implements the interaction with the user and submits the user's order
- The Order Processing Center (OPC)
application that implements the workflow involved in processing the orders
- The Supplier application that satisfies
the approved orders from OPC and sends back the invoice to the OPC
- The Admin application that interacts
with the OPC. The Admin application provides a JavaWebStart enabled Swing
client for use by the administrator
In the non Web-services case, both the PetStore-OPC
communication and the OPC-Supplier communication are done using the the Java
Messaging Service (JMS) technology which provided a portable way of
doing asynchronous communication. For more information on this refer
to the
Architecture of the Sample Application and
Design and Implementation of Sample Application chapters of the Designing
Enterprise Applications with the J2EE Platform, Second Edition.
We changed this communication to use Web-services.
Web-services for Document-Oriented Interactions
The document-oriented interaction style facilitates
loosely-coupled Web-services. In this case, the Web-service applications
interact with each-other by exchanging XML documents. To demonstrate this
scenario, we changed the OPC-Supplier communication to use the Java API for
XML based RPC (JAXRPC) for passsing XML documents. The application design
also illustrate how to extend your existing J2EE applications to use Web-services.
The communications that happen between the OPC and
the Supplier are
- The OPC submits the approved purchase
order to the Supplier
- The Supplier returns back the invoice
back to the OPC for the Items that have been shipped
To clearly demarcate the Web-services specific
changes, we placed all such modifications in a separate source tree, named
webservices, under the <petstore.home>/src directory.
Here are the changes contained in this directory:
- The Supplier has been changed to provide
a Web-service that processes purchase orders from the OPC.
- The OPC has been changed to provide
a Web-service that processes invoices from the Supplier.
- Both the purchase order and invoice
processing Web-services, offered by the Supplier and OPC respectively,
follow the Asynchronous Service model as described in the
BluePrints for Web-services
document. This is because both Web-services can take some time for processing
and the service requestor should not be made to wait until the service
is completed.
- Both the Web-services receive an XML
document (namely purchase order or invoice), validate them, place the validated
XML document on an appropriate JMS queue for processing and return the answer
to the requestor.
- The interface and implementation of
the WebServices provided by the OPC have been implemented in files /font><petstore.home>src/webservices/apps/opc/src/com/sun/j2ee/blueprints/opc/webservice/OPC*.java
.
- The interface
and implementation of the WebServices provided by the Supplier have been
implemented in files <petstore.home>/src/webservices/apps/supplier/src/com/sun/j2ee/blueprints/supplier/webservice/Supplier*.java.
- To make the OPC communicate with the
Supplier through JAXRPC and vice versa, two new Transition Delegates have
been implemented (one for OPC-Supplier communication and the other for communication
in the opposite direction). These files are <petstore.home>/src/webservices/apps/opc/src/com/sun/j2ee/blueprints/opc/webservice/transitions/OrderApprovalTD.java
and <petstore.home>/src/webservices/apps/supplier/src/com/sun/j2ee/blueprints/supplier/webservice/transitions/SupplierOrderTD.java.
- This implementation uses the Java
Web Services Developer Pack (JWSDP) for implementing the Web-services.
Accordingly, the configuration required by the JWSDP has been implemented
in files <petstore.home>/src/webservices/apps/opc/src/xrpcc-config.xml
and <petstore.home>/src/webservices/apps/supplier/src/xrpcc-config.xml.
- All the ejb-jar.xml, web.xml for both the Supplier as well as
the OPC were changed to reflect the fact that the Web-services are implemented
with a servlet endpoint and that the installation of the JWSDP changes
the port of operation to 8080 from 8000.
Web-services for RPC-Oriented Interactions
The JavaWebStart-enabled admin
application in the PetStore demonstrates how to provide rich user interfaces
for your applications. This Swing application invokes several well-defined
operations on the server, for example, to get sales statistics, to approve
pending orders and so on. The non-Web-services version of this application
uses a proprietary XML format to send these commands to the server over
HTTP POST. This required a lot of code to create, parse, and send these
commands and process their results. We now provide an alternate Web-service,
AdminWebService, for administration that reduces this complexity
significantly by providing a RPC-oriented JAXRPC interface. Here are the
changes that we made:
- We create a new Web-service, AdminWebService,
that is implemented by the JAXRPC interface <petstore.home>/src/webservices/apps/admin/src/com/sun/j2ee/blueprints/admin/webservice/AdminService.java
- The Swing client uses a Web-services specific proxy class to communicate
to the server <petstore.home>/src/webservices/apps/admin/src/client/com/sun/j2ee/blueprints/admin/client/WebServicePetStoreProxy.java.
You can run this client by going to <petstore.home>/webservices
(or <petstore.home>/src/webservices/apps/admin/build if
you have rebuilt the source code) directory and running adminwsclient.bat
(on Windows) or adminwsclient.sh (on Unix) file.
- Note that the JavaWebStart enabled client still uses the HTTP POST
for communicating to the server. This client uses the HTTP POST specific
proxy class to communicate to the server <petstore.home>/src/apps/admin/src/client/com/sun/j2ee/blueprints/admin/client/HttpPostPetStoreProxy.java
|