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 Application Server.This sample application document contains the following sections:
- Overview
- Compiling and Assembling the Application
- Deploying the Sample Application
Overview
This sample application demonstrates a Web Service for J2EE. This sample is similar to the JAX-RPC Simple at the <install_dir>/samples/webservices/jaxrpc/apps/simple directory but the client program invokes methods with arguments of non-primitive types.You can find source code for the sample application under <install_dir>/samples/webservices/jaxrpc/apps/simplebean
At runtime, the J2EE application client HelloClient makes a remote call to the demoArray method of the HelloWorld web service. The webservice takes String Array as input, and returns reversed String Array.
The HelloClient also makes a remote call to the demoBean method of the HelloWorld Web service. The webservice takes the SimpleAccountBean object as input, and returns the new BigDecimal account balance by calculating interest.
- private static void demoArray(HelloIF 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
- private static void demoBean(HelloIF 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:
- Compile and Assemble the J2EE Application.
- Execute the asant command under <install_dir>/samples/webservices/jaxrpc/apps/simplebean
- The default target core is executed to rebuild the .ear file.
- Deploy the application.
- After you have re-created the sample application from scratch, proceed to Deploying the application.
- Clean the application project area.
- Execute the asant clean command to clean the application area.
- Undeploy the application.
- Execute the asant undeploy command to undeploy the application.
- Build Javadocs.
- Execute the asant javadocs command to build Javadocs.
- The Javadocs are created under <install_dir>/samples/webservices/jaxrpc/apps/simplebean/javadocs.
Deploying the Sample Application
A pre-built jaxrpc-simplebean.ear file is supplied with the application server installation. This file contains the .xml deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .ear file 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>/bin/asadmin start-domain domain1
For Windows
Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default ServerSelect 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.
- GUI Based Deployment describes how to use the Admin GUI 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 GUI 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 .ear file to the application server.
Deploy the application using the asant command:
Deploy the application file using asadmin command
cd <install_dir>/samples/webservices/jaxrpc/apps/simplebean
The deployment process involves the following operations:
Execute the command:
asadmin deploy --user <username> --password <password> --host <host> --port <admin-port> --retrieve <local_dirpath> jaxrpc-simplebean.ear.
- It authenticates against the local application server's administrative server.
- The .ear file is transferred to the administrative server.
- The administrative server begins the registration process:
GUI Based Deployment
Since a pre-built Enterprise Archive (.ear) file for the sample application is included with the application server, you can use the Admin GUI to quickly read in the .ear file and deploy it to the application server.
- Start the admin server if it is not already started. Here are the commands for each platform:
- Unix - Execute the <install_dir>/bin/asadmin start-domain domain1 command.
- Windows - Click "Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default Server" command.
- Open the .ear file.
- Start Admin GUI, by entering URL http://localhost:<admin.port>/asadmin in browser. See replacing "localhost" and <admin.port> note here to determine correct values to use for your environment
- You are prompted to supply the user name and password of the application server. Enter correct values for your installed application server for "User Name:" and "Password:" input fields, then click on the "Login" button.
- In the left-hand frame, click Applications-->Enterprise Applications icon in the tree.
- In the right-hand frame, click on the "Deploy..." button.
- Choose the file to be deployed by clicking on the "Browse..." button, and navigate to select component to deploy (jaxrpc-simplebean.ear).
- In the browse dialog, click on the "OK" button.
- In the right-hand frame, click on the "Next" button.
- In the right-hand frame, click on the "OK" button. (Optionally fill in remaining values for application to be deployed)
- In the left hand pane, you will see the newly deployed module's icon in the tree. In the right hand pane you will also see the component listed as 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:
- cd <install_dir>/samples/webservices/jaxrpc/apps/simplebean
- Execute the <install_dir>/bin/appclient -client jaxrpc-simplebeanClient.jar command.
- The program uses the retrieved client stubs to display the following lines:
- 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 <install_dir>/bin/appclient -client jaxrpc-simplebeanClient.jar command, make certain that soap:address location in <install_dir>/samples/webservices/jaxrpc/apps/simplebean/simplebean-war/src/conf/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 © 2004 Sun Microsystems, Inc. All rights reserved.
Last Updated march 6,
2004