Tomcat Ejb Container



Installing the EasyBeans container in Apache Tomcat 5.5.x server or Apache Tomcat 6.x server. (Tested on 5.5.27 and 6.0.18 versions)

When the project moved to Source Forge in 2002 an Apache Tomcat integration was created. Again rather than follow what most in the industry were doing and putting Tomcat into OpenEJB, the project decided to follow its vision and provide an integration that allowed Tomcat users to plug in OpenEJB to gain EJB support in the Tomcat platform. Tomcat is a servlet-container, and only application servers are required to support EJB. Tomcat with integrated EJB support is basically TomEE. Replace Tomcat by TomEE. You can keep using the Tomcat server plugin in IDE to manage TomEE.

Container-Managed Transactions. In an enterprise bean with container-managed transaction demarcation, the EJB container sets the boundaries of the transactions.You can use container-managed transactions with any type of enterprise bean: session or message-driven. Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling. Originally referred to as a 'local' EJB container and what lead the project to describe itself as being able to run in two modes: Local and Remote. In August 2003 the project helped launch the Apache Geronimo application server.

JDK 5.0

To run the EasyBeans container, a JDK 5.0 or higher is required. A JDK 1.4.x will not work.

EasyBeans Web application

The EasyBeans container is provided as a .war file named ow_easybeans.war which allows to add or remove it in a few steps.
The .war file needs to be copied into $CATALINA_BASE/webapps directory.
Note : CATALINA_BASE could be replaced by CATALINA_HOME if CATALINA_BASE is not defined.

Note

This war file is specific to Tomcat. It will detect the Tomcat application server and register some libraries in Tomcat application server.
Also, the java: naming of EasyBeans will be redirected to Tomcat naming mechanism automatically.
By removing the war file of EasyBeans + easybeans-deploy/ folder (and examples), all is removed (No libraries or configuration files are copied).

Examples

The examples provided in this EasyBeans release need to be copied in the $CATALINA_BASE/examples_ejb3s/ directory. The resulting directory will be $CATALINA_BASE/examples_ejb3s with subfolders like statelessbean.

Deploying the EasyBeans container in a Tomcat server.

Launching Tomcat

As usual, Tomcat is launched with the catalina start or catalina run command. Note that a JDK 5.0 is required

Deploying EasyBeans container

ow_easybeans.war file located in $CATALINA_BASE/webapps directory will be autoloaded at the tomcat startup.

Trying examples.

Stateless Bean

Trying the example

This release is bundled with some examples. The first one is a stateless bean

Here are the steps for launching this example :

  1. Check that CATALINA_HOME (and maybe CATALINA_BASE) environment variables are defined before launching ant scripts

    ant needs to be launched in $CATALINA_BASE/examples_ejb3s/statelessbean directory. This will compile the source code and copy the archive into the $CATALINA_BASE/easybeans-deploy/stateless.jar/ directory.
  2. On the server side, some traces will be printed. This is because EasyBeans has detected a new module in the $CATALINA_BASE/easybeans-deploy directory. The bean was loaded automatically.
  3. Then, the client can be executed by running the command ant run.client
    If the client is executed without errors, the output will be :
  4. There is also a servlet's client that has been put in $CATALINA_BASE/webapps directory.
    It can be accessed with the default url :

Understanding the example

This example shows the use of JDK 5.0 annotations, the EJB3 interceptors and the EJB3 callbacks.

The SessionBean class is annotated with @Stateless. This means that this class will be used as a stateless session bean.

The method trace is annotated with @AroundInvoke EJB3 annotation. This method will be called at each call on a business method. The business methods are defined in the interface implemented by the SessionBean class.

As a new feature of the EJB3, the interface doesn't need to extend the Remote interface. On the client side, there is no need to do a PortableRemoteObject.narrow() call.

Customizing the example

Some annotations are commented in the session bean example. To discover some new features like interceptors in other classes or the EJB3 callbacks, the comments can be removed and the example compiled again.

New methods can be added in the interface and implemented in the bean class, then the only step to do is to call ant in $CATALINA_BASE/examples_ejb3s/statelessbean directory. The EJB3 container will detect the changes and reload the bean.

Stateful Bean

Trying the example

As for the stateless session bean, the example needs to be compiled and deployed by calling ant in the $CATALINA_BASE/examples_ejb3s/statefulbean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

The output will be :

Understanding the example

The @Stateful annotation is used to mark the bean as a stateful session bean.

State of the stateful session bean is notified by the transactions (default = REQUIRED), as the bean implements the SessionSynchronization interface.

Tomcat Ejb Container

Entity Bean

Tomcat Ejb Container

Trying the example

The example needs to be compiled and deployed by calling ant in the $CATALINA_BASE/examples_ejb3s/entitybean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

Note that Hibernate traces will be displayed as it will manage the Employee entity class.

Understanding the example

This example shows the use of an entity bean and using EJB3 persistence provider which is in this release Hibernate. TopLink Essentials, OpenJPA can also be used with this EasyBeans. ObjectWeb Speedo will also provide a JPA interface.

The Entity class is a POJO class annotated with @Entity. The entities class are managed by the persistence provider, and in this case, by Hibernate.

Message Driven Bean

Trying the example

As usual, ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/messagedrivenbean directory.

Once the bean is detected by the container and loaded, the client can be launched with ant run.client command.

The output on the server side will be :

Understanding the example

Ejb

Tomcat Ejb Container Carrier

The @MessageDriven annotation is used to mark the bean as a message driven bean.

The client send 5 messages on the SampleQueue queue object that are received by the bean and displayed on the output.

Timer Example

Trying the example

Tomcat Ejb Container Tracking

The ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/timerservice directory.

When the bean is loaded by the container, the client can be launched with the ant run.client command.

The output on the server side will be:

Understanding the example

This example shows the use of the @Timeout annotation on a method. The client invokes the TimerBean that will launch a timer. This timer will send a message to an MDB and then calls another bean which implements javax.ejb.TimedObject interface.

Security Example

Trying the example

What Is Ejb Java

The ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/security directory.

The bean will be loaded and then the client can be launched with the ant run.client command.

The output on the server side will be :

Understanding the example

All the annotations related to the security are used in this example. The annotations are @DeclareRoles, @RolesAllowed, @DenyAll and @RunAs.

To get the admin role, the @RunAs annotation is used.

As shown by the output on the server, role admin is authorized to do some actions.

Pool Example

Trying the example

The ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/pool directory.

Container

When the bean is loaded by the container, the client can be launched with the ant run.client command.

The output on the client side will be:

Understanding the example

The pool example is using XML or annotations to configure the pool of Stateless or MDB. The annotation used is @Pool

The configuration of the pool when using XML deployment descriptor is done in the META-INF/easybeans.xml file of the EJB-Jar file.

Migration Example

Trying the example

The ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/migrationejb21 directory.

When the bean is loaded by the container, the client can be launched with the ant run.client command.

The output on the server side will be:

Understanding the example

This example is using two interfaces for accessing the stateless session bean.

  • The first interface is the business interface of the stateless bean. It is the EJB 3.0 view
  • The second interface that is used is the EJB 2.1 Home interface. Then the client needs to call the create() method.

The stateless bean class EJB2And3Bean is annotated with @Remote(EJB3RemoteBusinessInterface.class) for the EJB 3.0 view. For the EJB 2.1 view, the class is annotated with @RemoteHome(EJB2RemoteHome.class). For a LocalHome, it can be annotated with @LocalHome(EJB2LocalHome.class).

EAR Example

Trying the example

This example will deploy the EJB3 included in the EAR file in EasyBeans EJB3 container while the .war file will be deployed in Tomcat Application server.

The ant command needs to be launched in the $CATALINA_BASE/examples_ejb3s/ear directory.

When the EAR is detected by EasyBeans, the following traces will be displayed :

Then, this example is available at the http://localhost:9000/ear-web/ URL.

Understanding the example

This EAR example includes an EJB3 and a WAR file. This allows to use local interface between the WEB layer and the EJB layer.

Tomcat Ejb Container Box

The EAR file has no entry named META-INF/application.xml, EasyBeans will detect the type of the given archives and use default values for the name of the web context.

Due to the use of local interface, the Entities don't need to implement the Serializable interface.

The interface is not annotated with @Local annotation as it is the default value.

Each entity class provides a @NamedQuery query that allows to get all the objects

There is a relationship between Author and Book entities. It is very simple: One Author can write several books, but a Book is written only by one Author.

@OneToMany and @ManyToOne annotations are used to define the relationship


Some aspects of EasyBeans design.

Proxy

On the client side, only the EJB3 libraries + bean's remote interface + client code is needed, no needs of the JOnAS***Stub.class, etc.

Bytecode enhancement

The generated code is done by using ASM which is faster than velocity + javac methods.

Automatic class (re)loading

Xenoblade chronicles x dlc download. It detects automatically the changes in the class made by the user and reload the bean. This can be tried on the examples provided in this release : Change the source code of a class, recompile and EasyBeans will reload the bean.

Reports

Bugs or comments can be reported on or to the EasyBeans mailing-list available at EasyBeans Mailing-List

Hibernate is a product available at http://www.hibernate.org. Toplink Essentials is a product available at https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html. OpenJPA is a product available at http://openjpa.apache.org. EclipseLink is a product available at http://www.eclipse.org/eclipselink/

J2EE containers provide runtime support for J2EE application components. J2EE application components use the protocols and methods of the container to access other application components and services provided by the server. The Application Server provides an application client container, an applet container, a Web container, and an EJB container. For a diagram that shows the containers, see the section Application Server Architecture.

The Web Container

The Web Container is a J2EE container that hosts web applications. The web container extends the web server functionality by providing developers the environment to run servlets and JavaServer Pages (JSP files).

The EJB Container

Enterprise beans (EJB components) are Java programming language server components that contain business logic. The EJB container provides local and remote access to enterprise beans.

There are three types of enterprise beans: session beans, entity beans, and message-driven beans. Session beans represent transient objects and processes and typically are used by a single client. Entity beans represent persistent data, typically maintained in a database. Index of the l word generation q. Message-driven beans are used to pass messages asynchronously to application modulesand services.

The container is responsible for creating the enterprise bean, binding the enterprise bean to the naming service so other application components can access the enterprise bean, ensuring only authorized clients have access to the enterprise bean’s methods, saving the bean’s state to persistent storage, caching the state of the bean, and activating or passivating the bean when necessary.





Comments are closed.