Sun ONE logo     
JAX-RPC simplebean Sample Application



JAX-RPC simplebean Sample Application


This document describes how to utilize the JAX-RPC simplebean sample application in conjunction with the Sun ONE Application Server version 7.

This sample application document contains the following sections:



Overview

This example demonstrates a client program invoking methods with arguments of non-primitive type, of a webservice using JAX-RPC.

You can find source code for the sample application under <install_dir>/samples/webservices/jaxrpc/simplebean/src/samples/webservices/jaxrpc/simplebean

At runtime, the JAX-RPC client HelloClient makes a remote call to the demoArray method of the JAX-RPC Web service. The webservice takes String Array as input, and returns reversed String Array.

private static void demoArray(HelloIF_Stub stub) {

try {

String[] words = {"it", "was", "a", "dark", "and", "stormy", "night"};

System.out.println("demoArray method:");
for (int j = 0; j < words.length; j++) {
System.out.println(words[j] + " ");
}
System.out.println();

String[] backwards = stub.reverse(words);
for (int j = 0; j < backwards.length; j++) {
System.out.println(backwards[j] + " ");
}
System.out.println();

} catch (Exception ex) {
ex.printStackTrace();
}

} // demoArray
At runtime, the JAX-RPC client HelloClient makes a remote call to the demoBean method of the JAX-RPC Web service. The webservice takes the SimpleAccountBean object as input, and returns the new BigDecimal account balance by calculating interest.

private static void demoBean(HelloIF_Stub stub) {

try {
System.out.println();
System.out.println("demoBean method:");
SimpleAccountBean dukesAccount = new SimpleAccountBean();
dukesAccount.setBalance(new BigDecimal("1200.00"));
dukesAccount.setCustomerName("Duke");
BigDecimal newBalance = stub.calculateInterest(dukesAccount);
System.out.println("newBalance: " + newBalance);
dukesAccount.setBalance(newBalance);

} catch (Exception ex) {
ex.printStackTrace();
}

} // demoBean



Compiling and Assembling the Application

To recompile, assemble and deploy the application, see the Sample Application Build Facility document for details on using a build facility to quickly perform these tasks.

For example, to rebuild the entire application from scratch, perform the following steps:

  1. Compile and Assemble the J2EE Application.

    Execute the asant command under <install_dir>/samples/webservices/jaxrpc/simplebean/src

    The default target core is executed to rebuild the .jar and .war files.

  2. Deploy the application.

    After you have re-created the sample application from scratch, proceed to Deploying the application.

  3. Clean the application project area.

    Execute the asant clean command to clean the application area.

  4. Undeploy the application.

    Execute the asant undeploy command to undeploy the application.

  5. Build Javadocs.

    Execute the asant javadocs command to build Javadocs.

    The Javadocs are created under <install_dir>/samples/webservices/jaxrpc/simplebean/javadocs.



Deploying the Sample Application

A pre-built jaxrpc-simplebean.war file is supplied with the application server installation. The pre-built jaxrpc-simplebean.war file contains the .xml deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .war files to deploy the application. If you want to compile and assemble the application from scratch, follow the instructions under Compiling and Assembling the Application.

To deploy the application administrative server needs to be running.

To start the administrative server if it is not already started:


For UNIX
Execute <install_dir>/domains/domain1/admin-server/startserv


For Windows
Start->Programs->Sun ONE Application Server 7->Start Application Server

Select one of the following approaches to deploy the application:

  • Command Line-Based Deployment describes how to manually register the application using a Command Line Interface (CLI).

    This is the quickest means of deploying the application.

  • Web-Based Deployment describes how to use the web-based administration tool to deploy the sample application.


Command Line-Based Deployment

While Command Line Interface is the quickest means of deploying the application, if you want to deploy through a GUI tool, follow the instructions under the Web-Based Deployment section.

CLI deployment of the application can be performed using either the asant script or the asadmin command.

The deployment process includes deploying the application .war file to the Sun ONE application server.

Deploy the application using the asant command:

  1. >cd <install_dir>/samples/webservices/jaxrpc/simplebean/src

  2. Execute the asant deploy command.

    It is an interactive command that might prompt you to provide the admin-server host, admin-server port, admin user name, admin password and appserv instance.

Deploy the application file using asadmin command

  1. >cd <install_dir>/samples/webservices/jaxrpc/simplebean

  2. Execute the asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jaxrpc-simplebean.war command.

The deployment process involves the following operations:

  • It authenticates against the local application server's administrative server.

  • The .war file is transferred to the administrative server.

  • The administrative server begins the registration process:

    • Parses the .war file.

    • Explodes the bits into the repository

    • Registers the J2EE application jaxrpc-simplebean by updating the server.xml file.

      Now you are ready to run the application (see Running the Sample Application).


Web-Based Deployment

  1. Log in to the web-based administration tool from the browser.

  2. Navigate as follows:

    Application Server Instances --> <server instance> --> Applications --> Web Apps

  3. Click Deploy.

  4. Click Browse to locate the jaxrpc-simplebean.war file.The file is located under <install_dir>/samples/webservices/jaxrpc/simplebean.

  5. Click OK.

  6. Enter jaxrpc-simplebean in the Web Application Name field.

  7. Enter jaxrpc-simplebean in the Context Root field.

  8. Click OK.

  9. Click the jaxrpc-simplebean link to verify that the application is deployed.

    Now you are ready to run the application (see Running the Sample Application).



Running the Sample Application

Perform the following steps to run the sample application:

  1. >cd <install_dir>/samples/webservices/jaxrpc/simplebean/src

  2. Execute the asant run command.

    The program should display following:

    demoArray method:
    it was a dark and stormy night
    night stormy and dark a was it

    demoBean method:
    SimpleAccountBean: setting balance to 1200.00
    SimpleAccountBean: setting customerName to Duke
    newBalance: 1260.0000
    SimpleAccountBean: setting balance to 1260.0000



Troubleshooting

If you see a Connection refused error, when you do asant run, make certain that soap:address location in <install_dir>/samples/webservices/jaxrpc/simplebean/src/HelloWorld.wsdl is set to http://<hostname>:<instance-port>/jaxrpc-simplebean/simplebean. Please modify the file and execute asant core before running the sample again.

You might see some warnings while executing asant javadocs. These warnings can be ignored.



Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated July 11, 2002