Академический Документы
Профессиональный Документы
Культура Документы
Introduction........................................................................... 3
About this tutorial 3
Installing software 3
NOTE: If you haven't already downloaded the software used to create the
tutorial examples, then please refer to the installing software section
(below.) You will also need to download the tutorial sources. All Java
sources mentioned in the tutorial examples can be found in the src
subdirectory of the unpacked tutorial sources archive. They all reside in the
com.systinet.demos package.
Installing software
REQUIREMENTS: We assume that you have a Java 1.4 or later SDK and a
standard HTTP browser installed on your system and the JAVA_HOME
system variable points to the Java root directory.
If you want to follow along with the demo, you'll need to download WASP
Server for Java, 4.5
(http://www.systinet.com/products/wasp_jserver/overview ) from the
Systinet Web site. Unpack the downloaded package to a local disk and run
the install script from the bin subdirectory of the WASP Server installation.
You'll need to agree to the product license and then please answer with
default options to all installation questions (simply press Enter multiple
times).
Standard J2EE Processing Let's first summarize some important facts about the J2EE platform.
Traditionally, a J2EE client application uses the Java Naming and Directory
Interface (JNDI) to find J2EE components on the server-side. For example,
the client application looks up the EJB reference in JNDI and receives an
EJB client proxy in return. The client uses this EJB client proxy later to
access the EJB component. All J2EE communication normally occurs over
RMI.
Approaches First, we'll demonstrate the most obvious approach, creating a Web service
wrapper around the EJB. This approach is particularly appropriate in
situations where the Web service application does not map directly to the
capabilities of an individual EJB and requires some additional orchestration
of the J2EE components.
To access stateful resources using this technique you would need to set up
additional lifecycle services to manage the proper removal of orphaned
stateful resources.
NOTE: If you haven't already downloaded the software used to create the
tutorial examples, please refer to the installation section at the start of this
document. You'll also need to download the tutorial sources (. All Java
sources mentioned in the tutorial examples can be found in the src
subdirectory of the unpacked tutorial sources archive. They all reside in the
com.systinet.demos package. Similarly all scripts used in the examples are
located in the bin subdirectory.
Installing
First, invoke the J2eeIntegrate.bat script that is located in the bin
subdirectory of your WASP Server installation. The basic syntax is:
• WASP_HOME\lib\xercesImpl.jar,
• WASP_HOME\lib\xmlParserAPIs.jar
• WASP_HOME\lib\security-ng.jar
• WASP_HOME\lib\xalan.jar
Restart JBOSS using the modified run script. When JBOSS is booting, you
will notice a series of "ERROR" messages as it brings up WASP. This is
because WASP sends all of its boot event status messages to STDERR.
They are no cause for concern. You can verify that WASP has been properly
deployed by bringing up the WASP admin-console. If you are working
locally and JBOSS has been installed and started with its default settings,
this URL will be correct: http://localhost:8080/wasp/admin/console
You can see these steps in the code starting on the next page:
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.rmi.RemoteException;
NOTE: We've made this demo simple to illustrate the basic principles of
the wrapper approach. However real-life applications are usually a bit more
complex. A wrapper service is often used to assemble functionality from a
number of EJBs and other J2EE resources. In such cases, the wrapper
service usually exposes different programmatic interfaces than the original
beans.
In this example, we will use a JNDI provider on the client side that speaks
SOAP rather than RMI. As you can see in Figure 2,
1. when the client issues a JNDI call using this provider, the
request is sent over SOAP to a JNDI Web service.
Each method invocation is transported over SOAP to the J2EE proxy, which
redirects the request to the actual EJB component.
You'll notice that no code modifications are required in either the EJB
component or in the client code. Only a configuration change is required in
the client to point to the SOAP-based JNDI provider.
NOTE: Most Web service runtime servers operate in the same context as
the application server, so the redirected method invocation is very fast and
won't degrade performance.
This approach also works for non-Java clients. Since the JNDI Web service
is a standard SOAP service, any SOAP client can take advantage of its
The JNDI Web service performs automatic remote garbage collection of all
components created in the Web service runtime. Each component is given
a set life span, or time in which it can expect to live--Time to Live (TTL).
This attribute is reset each time the component is accessed. Once the
component's TTL reaches zero, WASP automatically collects it and frees the
system resources.
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.SessionSynchronization;
/**
* No argument constructor required by container.
*/
public CounterEJB() {
}
/**
* Create method specified in EJB 1.1 section 6.10.3
*/
public void ejbCreate() {
}
/**
* @see
javax.ejb.SessionBean#setContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext context){
this.context = context;
}
/**
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() {
/**
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() {
}
/**
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() {
}
The other EJB sources are fairly obvious. You can see the code of the
Counter remote and CounterHome home interfaces. We can build the
counter bean by invoking the run make_ejb_counter command.
The client application shown in Example 3 is a standard EJB client with the
exception that it uses different JNDI properties in the getInitialContext
method.
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import java.net.InetAddress;
public CounterClient() {
}
(CounterHome)javax.rmi.PortableRemoteObject.narrow(homeRef,
CounterHome.class);
// create the EJB instance
System.err.println("Creating EJB");
Counter ejb = home.create();
System.out.println("Calling count
"+ejb.getCount());
System.out.println("Calling count
"+ejb.getCount());
System.out.println("Calling count
"+ejb.getCount());
// remove the EJB
System.err.println("Removing EJB");
ejb.remove();
}
catch(java.rmi.RemoteException re) {
re.printStackTrace();
}
catch(Throwable t) {
t.printStackTrace();
}
java.net.UnknownHostException {
String localhost =
InetAddress.getLocalHost().getHostName();
jndiProperties.put("java.naming.factory.initial",
"com.idoox.jndi.InitialContextFactoryImpl");
//Preset to JBOSS3 Defaults.
//You need to set this to a valid URI for your J2EE
App. Server
jndiProperties.put("java.naming.provider.url","http://" +
localhost +
":8080/wasp");
For the sake of simplicity, we've hard coded all JNDI specific parameters.
There are two parameters that must be defined in order to redirect the
JNDI query to the JNDI Web service:
• java.naming.factory.initial, and
• java.naming.provider.url.
The next step is to compile and run the J2EE client application using the
run.bat make_counter and run.bat run_counter commands. You should see
the EJB's getCount method called three times. All communication between
the client application and the server-side is through SOAP messages. You
can also see that the state (counter value) is properly maintained.
Review
In this part of the Web services tutorial we learned about two ways to
integrate Web services with J2EE. We introduced the basic wrapper Web
service and the transparent integration framework and explained the
situations in which each approach provides substantial advantages.
Copyright and Disclaimer This document and the information contained herein are the property of
Systinet Corporation and shall not be reproduced or copied in whole or in
part without written permission of Systinet Corp.
Microsoft, Windows and Windows NT and the Windows logo are trademarks
or registered trademarks of Microsoft Corporation in the United States and
other countries.
UNIX is a registered trademark of The Open Group in the United States and
other countries.
Systinet Corp.
Five Cambridge Center, 8th Floor
Cambridge, MA 02142
Phone: 1.617.868.2224
www.systinet.com