FAQ
History
PreviousHomeNext Search
Feedback
Divider

Deploying and Running the Application

The source code for the Coffee Break application is located in the directory <INSTALL>/j2eetutorial/examples/cb. Within the cb directory are subdirectories for each Web application--jaxm, jaxrpc, cbservice.

Add Web services JARs to the compilation classpath. To do so:

  1. Choose Options from the Tools menu.
  2. Expand the Building node, then the Compiler Types node.
  3. Choose External Compilation.
  4. Select the Expert tab.
  5. Click the Class Path property and open the property editor.
  6. Click Add JAR/Zip.
  7. In the file chooser, navigate to the <S1AS7_HOME>/share/lib directory and choose the jaxr-api.jar and saaj-api.jar files.
  8. Click OK.
  9. Click OK in the property editor, then click Close in the Options window.
  10. The JARs are also located in the <S1STUDIO_HOME>/jwsdp/common/lib directory, so you may specify that location for the classpath if you prefer.

Building, Deploying, and Registering the JAX-RPC Service

This section contains step-by-step instructions for the following tasks:

Creating the JAX-RPC Service

  1. In the IDE, mount this filesystem:
    <INSTALL>/j2eetutorial/examples/cb/jaxrpc
  2. Expand the jaxrpc node.
  3. Compile the beans, registry, and service packages.

The beans package contains JavaBeans components that represent business information, such as AddressBean. In the JAX-RPC service's methods, these beans are parameters or return types.

The registry package holds the JAXR programs that publish the service in (and remove it from) the registry.

The service package contains DateHelper, a utility class; PriceLoader, which loads coffee prices into a list; and Supplier, which implements the service's remote procedures.

  1. Right-click the service package and choose NewRight ArrowWeb ServicesRight ArrowWeb Service.
  2. In the wizard's Specify Web Service pane, do the following.
    1. In the Name field, enter SupplierService.
    2. In the Package field, enter service.
    3. For the Create From buttons, choose Java Methods.
    4. For the Architecture buttons, choose Web centric.
    5. Click Next.
  3. In the wizard's Select Methods pane, do the following.
    1. Expand the nodes in the service package until you see the methods beneath the Supplier class.
    2. Choose the getPriceList and placeOrder methods. These are the methods that remote clients may call.
    3. Click Finish.

If the "Collection of What?" window appears, click Cancel. In Sun ONE Studio 4 update 1, a bug prevents this operation from working correctly.

In the Explorer, the IDE displays a Web service node (a cube containing a sphere) for the SupplierService.

Specifying the Serializers

The JAX-RPC runtime system uses serializers when converting Java objects into XML data types. The runtime system needs a serializer for every parameter and return type of the service's methods. The IDE generates the serializers automatically when you perform the Generate Web Service task, as in the next section. The IDE identifies the serializers it needs to generate by examining the classes of the parameters and return types. However, if such a class contains a collection, the IDE cannot automatically identify the type of the collection's members. In this case, you must specify the collection's member type so that the IDE can generate a serializer for the member.

In this example, the getPriceList method returns a PriceListBean, a collection made up of PriceItemBean components. The placeOrdermethod passes an OrderBean parameter, which contains a collection of LineItemBean components. To specify serializers for LineItemBean and PriceItemBean, perform these steps:

  1. Right-click the Web service node for SupplierService (a cube containing a sphere) and choose Properties.
  2. In the properties sheet, choose Serialization Classes and open the properties editor.
  3. In the properties editor, add the beans.LineItemBean and beans.PriceItemBean classes.
  4. Click OK to close the properties editor.
  5. Close the properties sheet.

Generating the Service's WSDL File, Serializers, and other Helper Classes

To generate these files and classes, right-click the Web service node for SupplierService and choose Generate Web Service. The IDE creates the following:

Deploying the JAX-RPC Service

Right-click the Web service node for SupplierService (a cube containing a sphere) and choose Deploy.

Testing the JAX-RPC Service

To test the service, you create a Web service client and run the TestOrderCaller and TestPriceFetcher programs. Contained in the test package, these programs are static stub clients. (For more information, see the section Static Stub Client Example.)


Note: The test programs assume that you have deployed SupplierService on localhost. If you are running the service on a different host, you need to update the service URLs.


  1. Right-click the clientutil package and choose FileRight ArrowNewRight ArrowWeb ServicesRight ArrowWeb Service Client.
  2. In the wizard's Specify Web Service Client pane, do the following:
    1. In the Name field enter Order.
    2. In the Package field, enter clientutil.
    3. For the Create From buttons, choose Local WSDL File.
    4. Click Next.
  3. In the wizard's Select Local WSDL File pane, expand the service package and choose the SupplierService WSDL node (a rectangle with a sphere in the lower-left corner)
  4. Click Finish.
  5. Right-click the Order client node and choose Generate Client Proxy.

This action creates the OrderGenClient package, which contains the stub class, serializer classes, and other helper classes required by the client at runtime.

  1. In the test package, execute TestOrderCaller. The output window should display:
  2. orderId = 123
    shippingDate =
    mm/dd/yy (tomorrow's date)

  3. . Execute TestPriceFetcher. The output window should display:
  4. mm/dd/yy (today's date) mm/dd/yy (60 days from today)
    Mocca 4.00
    Wake Up Call 5.50
    French Roast 5.00
    Kona 6.50

Registering the JAX-RPC Service

  1. Start the UDDI Registry.
    1. Select the Runtime tab of the Explorer.
    2. Expand the UDDI Server Registry node.
    3. Right-click the Internal UDDI Registry node and choose Start Server.
  2. Register the service with the Registry Server.
    1. Select the Filesystems tab of the Explorer.
    2. In the jaxrpc subdirectory, expand the registry package.
    3. Execute the OrgPublisher program.
    4. The registration process can take some time, so wait until you see the following output before proceeding:
    5.     Created connection to registry
          Got registry service, query manager, and life cycle manager
          Established security credentials
          Organization saved
          Organization key is xxxxxxxx 
      

Later on, you can remove the JAX-RPC service from the registry by executing OrgRemover.

Deploying the JAXM Service

To build and deploy the JAXM service:

  1. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/cb/jaxm/service.
  2. Right-click the WEB-INF directory and choose Deploy.

Testing the JAXM Service

To test the JAXM service, you run the test programs TestPriceListRequest or TestOrderRequest in the <INSTALL>/j2eetutorial/examples/cb/jaxm/test directory.


Note: The test programs assume that you have deployed the JAXM service on localhost. If you are running the service on a different host, you need to update the service URLs.


To run the test programs in the IDE:

  1. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/cb/jaxm.
  2. Right-click TestPriceListRequest or TestOrderRequest and choose Execute. Here is what you should see when you run the former:
  3.     Arabica        4.50
        Espresso        5.00
        Dorada        6.00
        House Blend        5.00 
    

Deploying the Coffee Break Server

Server Configuration

The Coffee Break Server accesses three services--registry, JAX-RPC service, JAXM service--to build retail price lists and order coffee. The information needed to access the services is stored in the file <INSTALL>/examples/cb/cbservice/CoffeeServices.properties. This file contains URLs and security parameters for accessing the registry, the name under which the JAX-RPC service is registered, and the URLs for making requests on the JAXM service.

registryQuery.url=http://localhost:8089/registry-
server/RegistryServerServlet
registryPublish.url=http://localhost:8089/registry-
server/RegistryServerServlet
registry.username=testuser
registry.password=testuser
JAXRPCService.name=JAXRPCCoffeeDistributor
JAXMPricelist.url=http://localhost:80/jaxm-coffee-
supplier/getPriceList
JAXMOrder.url=http://localhost:80/jaxm-coffee-
supplier/orderCoffee 

Note: The default configuration assumes that you are running the registry server and JAXM service on localhost. If you are running either service on a different host, you need to update the service URLs.


Importing the JAX-RPC Client

The Coffee Break server imports the JAX-RPC client classes in the package clientutil. To make the classes available for compilation and deployment:

  1. Make sure the filesystem
    <INSTALL>/j2eetutorial/examples/cb/jaxrpc is mounted. This is required so that the IDE includes the clientutil subdirectory of jaxrpc in the classpath during compilation.
  2. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/cb/cbservice.
  3. Expand the cbservice node.
  4. Add the clientutil subdirectory of jaxrpc to the Web module as an extra file. When the IDE packages the cbservice Web module it will include the clientutil directory. To add the directory as an extra file:
    1. Right-click the WEB-INF directory.
    2. Select the Archive property sheet.
    3. Click the Extra Files property and open the property editor.
    4. In the Chosen Content pane, select the WEB-INF/classes Directory Prefix from the drop-down list.
    5. In the Source pane, expand the <INSTALL>/j2eetutorial/examples/cb/jaxrpc node.
    6. Select the clientutil node.
    7. Click Add.
    8. Click OK.
  5. Right-click the WEB-INF node and choose View WAR Content to check that the clientutil package was added.

Deploying the Coffee Break Server.

To deploy the Coffee Break server, right-click the WEB-INF directory of <INSTALL>/j2eetutorial/examples/cb/cbservice and choose Deploy.

Running the Coffee Break Client

After you have deployed all the Web applications, check that all the applications--SupplierService, jaxm-coffee-supplier, cbservice--are running by viewing the deployed Web applications with the IDE or the application server administration tool.

You may need to add <S1AS7_HOME>/share/lib/xercesImpl.jar to the application server classpath suffix and restart the application server using the application server administration tool. To do so:

  1. Open the URL http://localhost:4848 in a browser.
  2. Select the server1 node.
  3. Select the JVM Settings tab.
  4. Click the Path Settings link.
  5. Add <S1AS7_HOME>/share/lib/xercesImpl.jar to the Classpath Suffix text area.
  6. Click Save.
  7. Click the General tab.
  8. Stop and restart the server.

To run the Coffee Break client, open the Coffee Break server URL in a Web browser:

http://localhost:80/cbservice/orderForm 

You should see a page something like the one shown in Figure 12-2.

Order Form

Figure 12-2 Order Form

After you have gone through the application screens, you will get an order confirmation that looks like the one shown in Figure 12-3.

Order Confirmation

Figure 12-3 Order Confirmation

Divider
FAQ
History
PreviousHomeNext Search
Feedback
Divider

All of the material in The J2EE Tutorial for the Sun ONE Platform is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.