Home
TOC Index |
JAX-RPC on the J2EE SDK 1.3.1
In the example of this section, a stand-alone JAX-RPC client makes a remote call on a JAX-RPC service that is deployed as a servlet on the J2EE SDK. The servlet locates a stateless session bean and then invokes a method on the bean.
Note: The instructions in this section apply only to version 1.3.1 of the J2EE SDK.
Prerequisites
This section is for advanced users who are familiar with the following:
- The
PATH
environment variable (what it's for and how to set it)- EJB and J2EE technologies
- The
deploytool
utility of the J2EE SDKTo learn about EJB and J2EE technologies, see the J2EE Tutorial:
http://java.sun.com/j2ee/tutorial/index.htmlTo run this example, you'll need to download and install the J2EE SDK, which is available at the following URL:
http://java.sun.com/j2ee/sdk_1.3/index.html
Note: On the page of the preceding URL, be sure to read the section, Supported Operating Systems and Required Software. The J2EE SDK 1.3.1 does not support Windows 95, 98, ME, or XP.
Example Code
The example files are located in the
<JWSDP_HOME>
/docs/tutorial/examples/jaxrpc/toejb
directory. Thegreeting
subdirectory contains the source code for the stateless session bean namedGreetingEJB
. You don't have to compile or package the bean, because it's already packaged in a J2EE application archive namedGreetingApp.ear
. This EAR file is in theprovided-jars
subdirectory.At runtime, a JAX-RPC client named
HelloClient
makes a remote call to thesayHello
method of the JAX-RPC Web service:System.out.println(stub.sayHello("Buzz!")
);Next, the
sayHello
method of theHelloImpl
class invokes thesayHey
method ofGreetingEJB
: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; }Here is the
sayHey
method of theGreetingBean
class of theGreetingEJB
stateless session bean:public String sayHey(String name) { return "Hey " + name + "!"; }Packaging the JAX-RPC Client and Web Service
- If your
PATH
environment variable includes<J2EE_HOME>
/bin
, change thePATH
so that<JWSDP_HOME>
/bin
precedes<J2EE_HOME>
/bin
.- In a terminal window, go to the
<JWSDP_HOME>
/docs/tutorial/examples/jaxrpc/toejb
directory.- In a text editor, open the
build.xml
file and set the value ofj2ee.home
to the location of your J2EE SDK installation.- Type the following commands:
ant build ant build-staticThe preceding commands will create the
toejb-jaxrpc.war
andtoejb-client.jar
files in thedist
subdirectory.Setting Up the J2EE SDK 1.3.1
- If Tomcat is running, shut it down.
- If the
j2ee
server is running, stop it.- Set the
PATH
environment variable so that<J2EE_HOME>
/bin
precedes<JWSDP_HOME>
/bin
.
Note: In all subsequent steps, <J2EE_HOME>
/bin
must precede<JWSDP_HOME>
/bin
in thePATH
environment variable.
<JWSDP_HOME
>/bin/jwsdponj2ee.sh $J2EE_HOME<JWSDP_HOME
>\bin\jwsdponj2ee.bat %J2EE_HOME%
- The
jwsdponj2ee
script adds Java WSDP libraries to the J2EE SDK and then changes the Web server port of the J2EE SDK from 8000 to 8080. After you've finished running this example, you may want to follow the instructions in Undoing the Effects of jwsdponj2ee.
- In a terminal window, start the
j2ee
server:j2ee -verbose- Both the Java WSDP and the J2EE SDK have utilities called
deploytool
. In the steps that follow, you must run the J2EE SDK'sdeploytool
. To make sure that yourPATH
points to the J2EE SDK'sdeploytool
, type this command:deploytool -versionDeploying the GreetingEJB Session Bean
- In the
deploytool
utility, open theGreetingApp.ear
file, which is located in the directory named<JWSDP_HOME>
/docs/tutorial/examples/jaxrpc/toejb/provided-jars
.- In the tree, expand
GreetingApp
. Note that it contains an enterprise bean namedGreetingEJB
and a J2EE application client namedGreetingClient
. This client was created to test the bean and will not be run in this example.- Deploy the
GreetingApp
application.Deploying the JAX-RPC Service
- In
deploytool
, create a new application namedHelloApp
.- Add the
toejb-jaxrpc.war
file toHelloApp
. This WAR file is in the directory named<JWSDP_HOME>
/docs/tutorial/examples/jaxrpc/toejb/dist
.- Specify the reference to
GreetingEJB
.
- In the tree, select
HelloWorldApplication
.- On the EJB Refs tab, add an entry with the values shown in the following table.
- Specify the JNDI name of
GreetingEJB
.
- In the tree, select
HelloApp
.- On the JNDI Names tab, enter
MyGreeting
in the JNDI Name field at the bottom.- Set the context root for the servlet.
- Deploy the
HelloApp
application.If you have problems deploying the application, you may find it helpful to compare the
HelloApp.ear
file you created with theCompareHelloApp.ear
file in theprovided-jars
subdirectory. TheHelloWorldApplication
in theCompareHelloApp.ear
file has the correct settings and may be deployed as is.Running the JAX-RPC Client
- In a terminal window, go to the directory named
<JWSDP_HOME>
/docs/tutorial/examples/jaxrpc/toejb
.- Type the following command:
ant runUndoing the Effects of jwsdponj2ee
In the section, Setting Up the J2EE SDK 1.3.1, you ran the
jwsdponj2ee
script, which made some changes to the J2EE SDK installation. To undo these changes, perform the following:
Home
TOC Index |
This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.
All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.