Using EAServer 4.0 with Apache's Tomcat 3.3 - Sybase

thumbsshameServers

Nov 17, 2013 (3 years and 10 months ago)

131 views
























































By Ian Pearce, Sybase Professional Services, Sybase UK
Using EAServer 4 with Apache’s Tomcat 3.3
Table of Contents

Table of Contents
...........................................................................................................................................2

General Configuration
....................................................................................................................................3

Overview
........................................................................................................................................................4

Installation and configuration of Tomcat
.......................................................................................................4

Creating a Stateless Session Bean
..................................................................................................................7

Deploying an EJB through Jaguar Manager
...................................................................................................9

Creating a JSP
..............................................................................................................................................11

Deploying to Tomcat
....................................................................................................................................12

Testing the JSP
.............................................................................................................................................13

Conclusion
....................................................................................................................................................14



2
General Configuration

￿￿ In order to follow the examples outlined in this white paper, you will need to use EAServer 4.0, in
conjunction with the Apache Tomcat Servlet Engine, Version 3.3. You may also want to take
advantage of the facilities available in Sybase PowerJ Version 3.6 in order to develop an Enterprise
Java Bean.

￿￿ If you do elect to use PowerJ, make sure it is using JDK 1.2 at design time. Go to Tools ￿ Options ￿
Design Time VM tab. ‘Use JDK 1.2 at design time’ should be selected.

￿￿ Ensure that the EAServer (jdk12) is started. For our example we will use the default Jaguar server,
which listens on port 9000 on a machine called localhost.

￿￿ Download Tomcat 3.3 using the link located at
http://jakarta.apache.org/builds/jakarta-
tomcat/release/v3.3/bin/jakarta-tomcat-3.3.zip


￿￿ Expand Tomcat 3.3 into a directory on your hard drive. For the purposes of this example, we will use
C:\apache\jakarta-tomcat-3.3 as our tomcat root directory.



3
Overview

Enterprise Application Server (EAServer) from Sybase, Inc. is a robust and scalable J2EE application
server designed to host both Web Components and Enterprise Java Beans. EAServer is capable of running
Servlets using the Servlet 2.3 and JSP 1.2 J2EE specification; however, in some installations, users may
wish to use the Apache Tomcat engine as a Web Container, and delegate EJB requests to the EAServer. In
this white paper, we show you how to achieve just that.

Installation and configuration of Tomcat

Extract the zip file downloaded from
http://jakarta.apache.org/builds/jakarta-
tomcat/release/v3.3/bin/jakarta-tomcat-3.3.zip
.

Make a note of the installation directory. For the purposes of this example we will use the directory
c:\apache\Jakarta-tomcat-3.3
as our Tomcat root directory.

From this point onwards, this directory location will be known as
%TOMCAT_INSTALL%


In order to allow Tomcat to listen to HTTP requests from a client application such as a browser, we need to
configure the port number that Tomcat will use. In this example, we are going to set this value to port
8079
on the local machine. To set this value, open the file
%TOMCAT_INSTALL%\conf\server.xml
.

By default, Tomcat will listen to HTTP requests on port
8080
, which will clash with EAServer’s own
HTTP port, so we need to change that value in the configuration file. To do so, search the
server.xml
file for a value of
8080
, and change it to
8079
. This instructs tomcat to start listening on that port number.
Now save the file.

Open
tomcat.bat
and
startup.bat
files located in the
%TOMCAT_INSTALL%\bin
directory and
add a couple of lines to each file in order to let Tomcat know where the installation can be found. Apply
these changes to the start of the relevant files, just after the
rem
statements which start each file, as
follows;



tomcat.bat



startup.bat

4



After saving these files, start tomcat by locating the
startup.bat
file in your
%TOMCAT_INSTALL%\bin
directory. You should see a command window appear, which shows
something like this.



In order to verify that Tomcat is running on the correct port, try accessing one of the test JSPs that are
provided in the examples web application through your browser using a URL like this;

http://localhost:8079/examples/jsp/dates/date.jsp


This should produce output similar to the following;


5






6
Creating a Stateless Session Bean
We now need to develop a very simple Stateless Session EJB. If you do not have PowerJ 3.6 available, or
wish to skip these steps, you can simply skip to the section entitled ‘Deploying an EJB using Jaguar
Manager’. If, however, you want to follow through with the creation of the bean using PowerJ, take the
following steps;

￿￿ Start PowerJ and create a new workspace. In this example, we are using a workspace called
tomcat_eas.

￿￿ The next step is to create the bean. Right click over the workspace name and select ‘New …’.

￿￿ When the dialog appears, select EJB 1.1 and follow through the wizard steps, ensuring that you
create a Stateless Session bean.

￿￿ When asked for the name of the bean, type in TomcatEAS33.

￿￿ When you are prompted for the Java package name, choose com.eas40.

￿￿ When asked if you want to create a deployment target, accept the default value of
TomcatEAS33All,

￿￿ DO NOT configure the Jaguar deployment target, since all we want PowerJ to do is to create a
JAR file for use; we will deploy the bean ourselves!

Once PowerJ has created the EJB, we need to add a method to that bean.

￿￿ Right click over the REMOTE interface class com.eas40.TomcatEAS33 and choose Insert |
Method




￿￿ Change the default method signature as required. In this example, we are creating a method with
the name
someInfo
, which accepts no parameters and returns a
java.lang.String
data
type.


7


￿￿ With the code window for the Bean Implementation open, add some code to the method body
that indicates that your method has been called. We are just going to return the name of the class
in our example.



Now, we need to compile the bean and create an EJB jar. Since PowerJ has already created a target
dependency on our behalf, all we need to do is to build the TomcatEAS33 JAR.

Once you have built the JAR, you need to deploy it to EAServer. This can be achieved in one of two ways:
either use Sybase Central Java Edition (a.k.a. Jaguar Manager), or use the jagtool utility that is provided
with the EAServer installation in the bin directory.

In our example, we are going to use Jaguar Manager.

8

Deploying an EJB through Jaguar Manager
Open Jaguar Manager, and connect to the server in the normal fashion.

￿￿ Select the Packages folder, right click, and choose Deploy | EJB Jar



￿￿ When prompted for the location of the jar that you wish to deploy, locate the
TomcatEAS33All.jar file, which should have been created in the DEBUG directory of your JAR
target.



￿￿ Click on the Next button, and deployment begins …


9



Once the EJB has been deployed, we need to assign the Package to the default server.

￿￿ Open Servers folder in Jaguar Manager, then open the Installed Packages folder and choose Install
Package, now select the TomcatEAS33 package from the list.



￿￿ Once the assignment is made, remember to refresh the Jaguar server by right clicking on the server
name and selecting Refresh.

Now the bean has been deployed, we can create a JSP template that will access the bean and call the
someInfo ()
method.

10

Creating a JSP
In our example, we are going to create a WAR file that we can then add to Tomcat.

￿￿ Using a text editor, create a JSP file that contains the following snippet of code (This can be found
in the associated ZIP file that is distributed with this white paper);


￿￿ Save the file as
TomcatEASJSP.jsp
and then copy it over to the
%TOMCAT_INSTALL%\webapps\examples\jsp
directory.

11

Deploying to Tomcat
Now we need to configure the examples webapp to ensure that it can locate our EJB client stubs and the
required support classes from the EAServer installation.

To do this, follow these instructions EXACTLY:
￿￿ Switch to a command prompt and create a directory called
c:\temp\easclient

￿￿ Open Winzip, (or a similar ZIP management utility), and locate the file called
easclient.jar
which lives in the
%JAGUAR%\java\lib
directory.
￿￿ Expand this JAR file into your newly create
c:\temp\easclient
directory.
￿￿ When the expansion is complete (and it may take a while), switch to the command prompt and
type the following as two separate lines:

cd c:\temp\easclient
c:
del org\apache\*.* /s /q

￿￿ Now create a JAR file which contains all the classes in the
c:\temp\easclient


jar cvf easclient_tomcat_3.3.jar *.*


￿￿ Once the JAR file has been created, we need to add it to the
WEB-INF\lib
directory for the
examples webapp in Tomcat (Type the following as one complete line, answering ‘F’ when asked
if you want to create a File or a Directory).

xcopy easclient_tomcat_3.3.jar %TOMCAT_INSTALL%\webapps\examples\WEB-
INF\lib\easclient_tomcat_3.3.jar

￿￿ We also need to make sure that the EJB support classes are available to the examples webapp in
Tomcat. To do this, type the following as one complete line:

copy %JAGUAR%\java\lib\easj2ee.jar
%TOMCAT_INSTALL%\webapps\examples\WEB-INF\lib\easj2ee.jar


￿￿ Finally, we need to add the client classes, in unexpanded form, to the examples webapp. To do
this, type the following as one complete line, answering ‘D’ when the prompt asks for a File or a
Directory:

xcopy %JAGUAR%\html\classes\com\eas40\TomcatEAS33*.class
%TOMCAT_INSTALL%\webapps\examples\WEB-INF\classes\com\eas40



12
Testing the JSP
Prior to testing, we need to restart Tomcat:
￿￿ Locate the
shutdown.bat
file in the
%TOMCAT_INSTALL%\bin
directory, and run it
￿￿ Now start Tomcat using the startup command file

Now we can test our JSP:

￿￿ Switch to a browser, and type in the following URL in the address bar:

http://localhost:8079/examples/jsp/TomcatEASJSP.jsp


￿￿ If all goes well, you should see output similar to the following:





13
Conclusion
This white paper has shown you how to configure the Tomcat Servlet engine in order to make use of the
J2EE capabilities of Sybase EAServer.

The JSP that has been developed in this example is functional, but should be changed to incorporate the
MVC architecture favored by today’s Web architects.

Applying the MVC model to our own example developed above, Tomcat would host the JSPs and the
JavaBeans, leaving EAServer to deliver the required performance and reliability expected of a robust and
scalable EJB container.


































































14






























































Sybase Incorporated
Worldwide Headquarters
6475 Christie Avenue
Emeryville, CA 94608, USA
Tel: 1-800-8-Sybase, Inc.
Fax: 1-510-922-3210
www.sybase.com


Copyright © 2001 Sybase, Inc. All rights reserved. Unpublished rights reserved under U.S. copyright laws. Sybase and the Sybase logo are
trademarks of Sybase, Inc. All other trademarks are property of their respective owners. ® Indicates registration in the United States.
Specifications are subject to change without notice. Printed in the U.S.A.

15