|
Page Edited :
OPENEJB :
Calculator Session Stateless Bean Example
Calculator Session Stateless Bean Example has been edited by David Blevins (Dec 15, 2007). Content:OverviewAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/README.txt. The system administrator has been notified.The CodeIn this example we develop a simple calculator stateless session EJB. It is an EJB 3 style pojo stateless session bean The Stateless bean has 2 business interfaces: CalculatorRemote, a remote business Local business interface
You'll notice that in EJB 3.0 the Local Business Interface of a stateless session bean does not need to extend from javax.ejb.EJBLocalObject and does not need a javax.ejb.EJBLocalHome interface. When the bean is looked up from JNDI, the container will create a new reference and pass it to the caller. No home interface required. Remote business interfaceAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java. The system administrator has been notified.As stated above, the Remote Business Interface of a bean can be any plain old interface. It does not need to extend javax.ejb.EJBObject, it does not need a javax.ejb.EJBHome, the methods do not need to throw javax.rmi.RemoteException, and the bean class can implement it! BeanAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java. The system administrator has been notified.In EJB 3.0 session beans do not need to implement the javax.ejb.SessionBean interface. You can simply annotate it as @Stateless if you want it to be a stateless session bean. And as noted above, notice the bean is actually implement the business interfaces! In the prior version of EJB implementing the remote interface (which derives from javax.ejb.EJBObject) in your bean was just not allowed. Now there is no javax.ejb.EJBObject requirement, so implementing the business interfaces is standard practice for EJB 3.0. Writing a unit test for the exampleWriting an unit test for the stateless session EJb is quite simple. We need just to write a setup method to create and initialize the InitialContext, and then write our test methods setUpAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java. The system administrator has been notified.Note the "openejb.deployments.classpath.include" parameter, which tells the ejb container to search for EJBs in the classpath, and specifies in which java packages they are to be located. Test the local business interfaceAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java. The system administrator has been notified.Test the remote business interfaceAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java. The system administrator has been notified.RunningRunning the example is fairly simple, just run: $ cd calculator-stateless-pojo Which should create output like the following. ------------------------------------------------------- T E S T S ------------------------------------------------------- [OPENEJB:surefire] Running org.apache.openejb.examples.calculator.CalculatorTest log4j:WARN No appenders could be found for logger (OpenEJB). log4j:WARN Please initialize the log4j system properly. Apache OpenEJB 3.0-incubating-SNAPSHOT build: 20070105-12:45 http://incubator.apache.org/openejb OpenEJB ready. [OPENEJB:surefire] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 2.371 sec [OPENEJB:INFO] [jar:jar] [OPENEJB:INFO] Building jar: openejb3/examples/calculator-stateless-pojo/target/simple-calculator-stateless-1.0-SNAPSHOT.jar [OPENEJB:INFO] [install:install] [OPENEJB:INFO] Installing openejb3/examples/calculator-stateless-pojo/target/simple-calculator-stateless-1.0-SNAPSHOT.jar ... [OPENEJB:INFO] ------------------------------------------------------------------------ [OPENEJB:INFO] BUILD SUCCESSFUL [OPENEJB:INFO] ------------------------------------------------------------------------ |
Unsubscribe or edit your notifications preferences
