![]() |
JAX-RPC toejb Application |
JAX-RPC toejb Application
This document describes how to utilize the JAX-RPC toejb sample application in conjunction with the Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Application
Deploying the Sample Application
Overview
In this example, a stand-alone JAX-RPC client makes a remote call on a JAX-RPC service. The service locates a stateless session bean and invokes a method on the bean.You can find source code for the sample application under <install_dir>/samples/webservices/jaxrpc/toejb/src/samples/webservices/jaxrpc/toejb
At runtime, the JAX-RPC client HelloClient makes a remote call to the sayHello method of the JAX-RPC Web service:
Next, the sayHello method of the HelloImpl class invokes the sayHey method of GreetingEJB:
- System.out.println(stub.sayHello("Buzz!"));
To read more about invoking methods on EJBs using JAX-RPC, go to http://java.sun.com/webservices/docs/1.0/tutorial/doc/JAXRPC7.html.
- public String sayHello(String name) {
- String result = null;
- try {
- Context initial = new InitialContext();
- Context myEnv =
- (Context)initial.lookup("java:comp/env");
- Object objref = myEnv.lookup("ejb/SimpleGreeting");
- GreetingHome home =
- (GreetingHome)PortableRemoteObject.narrow
- (objref, GreetingHome.class);
- Greeting salutation = home.create();
- result = salutation.sayHey(name);
- } catch (Exception ex) {
- System.out.println("Exception in sayHello: " + ex.getMessage());
- }
- return result;
- }
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.
Deploy the Application.
- Execute the asant command under <install_dir>/samples/webservices/jaxrpc/toejb/src
- The default target core is executed to rebuild the .jar, .war and .ear files.
Clean the application project area.
- After you have re-created the sample application from scratch, proceed to Deploying the Sample Application.
Undeploy the Application.
- Execute the asant clean command to clean the application area.
Building Javadocs.
- Execute the asant undeploy command to undeploy the application.
- Execute the asant javadocs command to create java docs.
- The Javadocs are created under <install_dir>/samples/webservices/jaxrpc/toejb/javadocs.
Deploying the Sample Application
Pre-built jaxrpc-toejb.ear and GreetingApp.ear files are supplied with the application server installation. The pre-built .ear files are the Enterprise Archive (.ear) files of the application that contain .war and ejb-jar files. Within the .war and ejb-jar files reside the XML deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .ear files to deploy the application. If you want to compile and assemble the application from scratch, follow the instructions in 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 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).
Web-Based Deployment describes how to use the web-based administration tool to deploy the sample application.
- This is the quickest means of deploying the application.
Command Line-Based Deployment
While Command Line Interface is the quickest means of deploying the application, if you want to experience deploying 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:
>cd <install_dir>/samples/webservices/jaxrpc/toejb/src
Deploy the application file using asadmin command: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.
>cd <install_dir>/samples/webservices/jaxrpc/toejb
The deployment process involves the following operations:Execute the asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jaxrpc-toejb.ear command.
Execute the asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> GreetingApp.ear command.
It authenticates against the local application server's administrative server.
Now you are ready to run the application (see Running the Sample Application).The .ear file is transferred to the administrative server.
The administrative server begins the registration process:
Log in to the web-based administration tool from the browser.
Now you are ready to run the application (see Running the Sample Application).
Click Deploy.
- Application Server Instances --> <server instance> --> Applications --> Enterprise Apps
Click Browse to locate the jaxrpc-toejb.ear file. The file is located under <install_dir>/samples/webservices/jaxrpc/toejb/.
Enter jaxrpc-toejb in the Application Name field.
Click the jaxrpc-toejb link to verify that the application is deployed.
Application Server Instances --><server instance>-->Applications-->Enterprise Apps
Click Deploy.
Click Browse to locate the GreetingApp.ear file. The file is located under <install_dir>/samples/webservices/jaxrpc/toejb/.
Enter GreetingApp in the Application Name field.
- Click the GreetingApp link to verify that the application is deployed.
Running the Sample Application
Perform the following steps to run the sample application:
>cd <install_dir>/samples/webservices/jaxrpc/toejb/src
Execute the asant run command.
- The program should display the following line:
- Hey Buzz!
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/toejb/src/HelloWorld.wsdl is set to http://<hostname>:<instance-port>/jaxrpc-toejb/toejb. Please modify the file and execute asant core before running the sample again.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 11, 2002