|
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
PATHenvironment variable (what it's for and how to set it)- EJB and J2EE technologies
- The
deploytoolutility 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/toejbdirectory. Thegreetingsubdirectory 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-jarssubdirectory.At runtime, a JAX-RPC client named
HelloClientmakes a remote call to thesayHellomethod of the JAX-RPC Web service:System.out.println(stub.sayHello("Buzz!"));Next, the
sayHellomethod of theHelloImplclass invokes thesayHeymethod 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
sayHeymethod of theGreetingBeanclass of theGreetingEJBstateless session bean:public String sayHey(String name) { return "Hey " + name + "!"; }Packaging the JAX-RPC Client and Web Service
- If your
PATHenvironment variable includes<J2EE_HOME>/bin, change thePATHso that<JWSDP_HOME>/binprecedes<J2EE_HOME>/bin.- In a terminal window, go to the
<JWSDP_HOME>/docs/tutorial/examples/jaxrpc/toejbdirectory.- In a text editor, open the
build.xmlfile and set the value ofj2ee.hometo the location of your J2EE SDK installation.- Type the following commands:
ant build ant build-staticThe preceding commands will create the
toejb-jaxrpc.warandtoejb-client.jarfiles in thedistsubdirectory.Setting Up the J2EE SDK 1.3.1
- If Tomcat is running, shut it down.
- If the
j2eeserver is running, stop it.- Set the
PATHenvironment variable so that<J2EE_HOME>/binprecedes<JWSDP_HOME>/bin.
Note: In all subsequent steps, <J2EE_HOME>/binmust precede<JWSDP_HOME>/binin thePATHenvironment variable.
<JWSDP_HOME>/bin/jwsdponj2ee.sh $J2EE_HOME<JWSDP_HOME>\bin\jwsdponj2ee.bat %J2EE_HOME%
- The
jwsdponj2eescript 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
j2eeserver: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 yourPATHpoints to the J2EE SDK'sdeploytool, type this command:deploytool -versionDeploying the GreetingEJB Session Bean
- In the
deploytoolutility, open theGreetingApp.earfile, 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 namedGreetingEJBand a J2EE application client namedGreetingClient. This client was created to test the bean and will not be run in this example.- Deploy the
GreetingAppapplication.Deploying the JAX-RPC Service
- In
deploytool, create a new application namedHelloApp.- Add the
toejb-jaxrpc.warfile 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
MyGreetingin the JNDI Name field at the bottom.- Set the context root for the servlet.
- Deploy the
HelloAppapplication.If you have problems deploying the application, you may find it helpful to compare the
HelloApp.earfile you created with theCompareHelloApp.earfile in theprovided-jarssubdirectory. TheHelloWorldApplicationin theCompareHelloApp.earfile 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
jwsdponj2eescript, 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.