Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

CORBA support will be added in future releases. Support for the JAX-RPC API is not a planned feature.

Embeddable for Testing and Java SE usage

Over the years, OpenEJB has innovated the art of the embedded/Java SE EJB container usable as a plain library much the way an embedded databases work. In a simple 1 2, 3 step of add OpenEJB to your classpath, add a META-INF/ejb-jar.xml containing at minimum "<ejb-jar/>", then use the org.apache.openejb.client.LocalInitialContextFactory when creating your client InitialContext and you've got a Java SE EJB container that can be used in unit tests, your IDE, or anyway you'd like to drop in EJB functionality. Configuration can be done through an openejb.xml file or can be encapsulated 100% in the test case through the parameters passed to the InitialContext. For example, to create a JTA DataSource for JPA usage, you can simply:

Code Block

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
p.put("movieDatabase", "new://Resource?type=DataSource");
p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

Context context = new InitialContext(p);

See the examples zip for a dozen embedded testing examples that range from simple @Stateless beans to advanced transaction and security testing.

EJB Plugin for Tomcat 6 and 5.5

OpenEJB 3.0 can be plugged into any Tomcat 6 or Tomcat 5.5 server, adding support for EJBs in Web Apps. War files themselves can contain EJBs and the Servlets can use new JavaEE 5 annotations, XA transactions, JPA, and JMS. Webapps can even support fat java clients connecting over HTTP.

Don't use EJBs?

No matter, adding OpenEJB to Tomcat gives Servlets several new Java EE 5 capabilities such as JPA, JAX-WS, JMS, J2EE Connectors, transactions, and more as well as enhancing the injection features of Tomcat 6 to now support injection of JavaEE objects like Topics, Queues, EntityManagers, JMS ConnectionFactories, JavaMail Sessions, as well as simpler data types such as Dates, Classes, URI, URL, List, Map, Set, Properties, and more. In the case of Tomcat 5.5 which doesn't support dependency injection at all, even more is gained.

CMP via JPA

Our CMP implementation is a thin layer over the new Java Persistence API (JPA). This means when you deploy an old style CMP 1.1 or CMP 2.1 bean it is internally converted and ran as a JPA bean. This makes it possible to use both CMP and JPA in the same application without any coherence issues that can come from using two competing persistence technologies against the same data. Everything is ultimately JPA in the end.

...

Dependency Injection – Enums, Classes, Dates, Files, oh my.

Dependency Injection in EJB 3.0 via @Resource is largely limited to objects provided by the container, such as DataSources, JMS Topics and Queues. It is possible for you to supply your own configuration information for injection, but standard rules allow for only data of type String, Character, Boolean, Integer, Short, Long, Double, Float and Byte. If you needed a URL, for example, you'd have to have it injected as a String then convert it yourself to a URL. This is just plain silly as the conversion of Strings to other basic data types has existed in JavaBeans long before Enterprise JavaBeans existed.

OpenEJB 3.0 supports injection of any data type for which you can supply a JavaBeans PropertyEditor. We include several built-in PropertyEditors already such as Date, InetAddress, Class, File, URL, URI, Map, List, any java.lang.Enum and more.

Code Block
titleMyBean.java
import java.net.URI;
import java.io.File;
import java.util.Date;

@Stateful 
public class MyBean {
    @Resource URI blog;
    @Resource Date birthday;
    @Resource File homeDirectory;
}

Dependency Injection – Generic Collections and Maps

Support for Java Generics makes the dependency injection that much more powerful. Declare an injectable field that leverages Java Generics and we will use that information to boost your injection to the next level. For example:

Code Block
titleMyBean.java

import java.net.URI;
import java.io.File;

@Stateful 
public class MyBean {
    @Resource List<Class> factories;
    @Resource Map<URI, File> locations;
}

Dependency Injection – Custom Types

You can easily add your own types or override the way built-in types are handled and claim dependency injection as your own making a critical part of your architecture. For example, let's register a custom editor for our Pickup enum.

Code Block

import java.beans.PropertyEditorManager;

public enum Pickup {

    HUMBUCKER,
    SINGLE_COIL;

    // Here's the little magic where we register the PickupEditor
    // which knows how to create this object from a string.
    // You can add any of your own Property Editors in the same way.
    static {
        PropertyEditorManager.registerEditor(Pickup.class, PickupEditor.class);
    }
}
Code Block

public class StratocasterImpl implements Stratocaster {

    @Resource(name = "pickups")
    private List<Pickup> pickups;
}

The META-INF/env-entries.properties

...

Validation output comes in three levels. The most verbose level will tell you in detail what you did wrong, what the options are, and what to do next... even including valid code and annotation usage tailored to your app that you can copy and paste into your application. Very ideal for beginners and people using OpenEJB in a classroom setting.

Some example output might look like the following. Here we illegally add some annotations to the "Movies" beans interface as well as use the wrong annotations for various types of injection:

Code Block
none
none

ERROR - FAIL ... Movies:  @Stateful cannot be applied to an interface: org.superbiz.injection.jpa.Movies
ERROR - FAIL ... Movies:  Missing required "type" attribute on class-level @Resource usage
ERROR - FAIL ... Movies:  Mistaken use of @Resource on an EntityManagerFactory reference.  
                          Use @PersistenceUnit for ref "org.superbiz.injection.jpa.MoviesImpl/entityManagerFactory"
ERROR - FAIL ... Movies:  Mistaken use of @PersistenceUnit on an EntityManager reference.  
                          Use @PersistenceContext for ref "org.superbiz.injection.jpa.MoviesImpl/entityManager"
WARN - WARN ... Movies:	 Ignoring @RolesAllowed used on interface org.superbiz.injection.jpa.Movies method deleteMovie.
                         Annotation only usable on the bean class.
WARN - WARN ... Movies:	 Ignoring @TransactionAttribute used on interface org.superbiz.injection.jpa.Movies method addMovie.
                         Annotation only usable on the bean class.

JNDI Name Formatting

A complication when using EJB is that plain client applications are at the mercy of vendor's chosen methodology for how JNDI names should be constructed. OpenEJB breaks the mold by allowing you to specify the exact format you'd like OpenEJB to use for your server or any individual application. Supply us with a formatting string, such as "ejb/{ejbName}/{interfaceClass.simpleName}", to get a JNDI layout that best matches your needs.

...