![]() |
|
||||||||||||||||
|
|||||||||||||||||
When we started WebLogic, we used the Example configuration. This accomplishes
two things. First, it puts WebLogic in a de
velopment
mode where it's easier to deploy and to find out what problems were encountered. Second, it makes the WebLogic
server examples available. To start the server in the Example configuration (in Windows) you do this:
cd \bea\wlserver6.1\config\examples
startExamplesServer.cmd
Using the WebLogic example environment
Let's try out a WebLogic example. Open a new command window (in Windows) - and go to the same directory, and run the Example setup:
cd \bea\wlserver6.1\config\examples
setExamplesEnv.cmd
This sets up the environment to run WebLogic examples. Then go to the statelessSession example and build it:
cd \bea\wlserver6.1\samples\examples\ejb\basic\statelessSession
ant
Running the ant command builds and deploys the EJBs for the statelessSession example - which you can now run by entering:
cd \bea\wlserver6.1\samples\
java examples.ejb.basic.statelessSession.Client "t3://localhost:7001"
When you run this, you should get the following output:
Beginning statelessSession.Client...
Creating a trader
Buying 100 shares of BEAS.
Buying 200 shares of MSFT.
Buying 300 shares of AMZN.
Buying 400 shares of HWP.
Selling 100 shares of BEAS.
Selling 200 shares of MSFT.
Selling 300 shares of AMZN.
Selling 400 shares of HWP.
Removing the trader
End statelessSession.Client...
Testing the new EJB in the WebLogic
Now, using this same environment, we're going to test the new EJB we just deployed. First, here is an edited version of the Client.java from the Trader example (c) WebLogic above - but modified to run our new stateless session bean: MySessionEJB. Create an empty directory and save the program Client.java Client.txt
To run this program, you need a slightly different classpath. The classpath you need is as follows:
set classpath=;.;\bea\wlserver6.1\lib\weblogic.jar;<JDeveloper>\jdev\mywork\Workspace1\Project1\ejb1.jar;
javac Client.java
java Client "t3://localhost:7001"
When you run this program it shoud display the following:
Beginning statefulSession.Client...
Creating MySessionEJB
Here's what MySessionEJB returns: StartInfo
End statefulSession.Client...
Testing the EJB from the Servlet
Now let's test the EJB using a Servlet. We're going to run the Servlet in Tomcat. If you don't have a copy of Tomcat, go to http://jakarta.apache.org/tomcat/index.html and download either Tomcat 3.x or the new Tomcat 4.0.
After you download it, install it, and then let's get the required elements into the classpath.
(1) weblogic.jar
cd <tomcat>\bin
wordpad catalina.batFind the tag ":noJsse" and insert the command:
set CP=%CP%;<bea>\wlserver6.1\lib\weblogic.jar
This ensures that <bea>\wlserver6.1\lib\weblogic.jar is in the classpath. Otherwise, instead you can copy weblogic.jar to the tomcat\lib directory. But it is 25Meg.
(2) ejb1.jar
copy <JDeveloper>\jdev\mywork\Workspace1\Project1\ejb1.jar \tomcat\lib
There are several other ways to accomplish this within JDeveloper.
(3) MyServlet1.class
In JDeveloper, let's change the doPost() method so that it runs the EJB. You'll need to import some new libraries as well. When you finish, the program should look like MyServlet1.java:MyServlet1.txt
Now go to your browser and enter:
http://127.0.0.1:8080/webapp1/servlet/mypackage1.MyServlet1
When the servlet runs, you should see the following displayed:
The servlet has received a request. This is the reply.
Start: Preparing environment to connect to J2EE EJB AppServer
Creating JNDI Context
Doing a JNDI Lookup on Home Interface
Create Remote Reference
Now, narrow to a session bean.
We have the following data from the session bean: StartInfo
On to ==> Summary