http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/helloworld-weblogic.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/helloworld-weblogic.adoc b/src/main/jbake/content/examples/helloworld-weblogic.adoc new file mode 100755 index 0000000..dd8279e --- /dev/null +++ b/src/main/jbake/content/examples/helloworld-weblogic.adoc @@ -0,0 +1,169 @@ += Helloworld Weblogic +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example helloworld-weblogic can be browsed at https://github.com/apache/tomee/tree/master/examples/helloworld-weblogic + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== HelloBean + + +[source,java] +---- +package org.superbiz.hello; + +import javax.ejb.LocalHome; +import javax.ejb.Stateless; + +/** + * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +@Stateless +@LocalHome(HelloEjbLocalHome.class) +public class HelloBean { + + public String sayHello() { + return "Hello, World!"; + } +} +---- + + +== HelloEjbLocal + + +[source,java] +---- +package org.superbiz.hello; + +import javax.ejb.EJBLocalObject; + +/** + * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public interface HelloEjbLocal extends EJBLocalObject { + + String sayHello(); +} +---- + + +== HelloEjbLocalHome + + +[source,java] +---- +package org.superbiz.hello; + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; + +/** + * @version $Revision: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public interface HelloEjbLocalHome extends EJBLocalHome { + HelloEjbLocal create() throws CreateException; +} +---- + + +== ejb-jar.xml + + +[source,xml] +---- +<ejb-jar/> +---- + + +== weblogic-ejb-jar.xml + + +[source,xml] +---- +<weblogic-ejb-jar> + <weblogic-enterprise-bean> + <ejb-name>HelloBean</ejb-name> + <local-jndi-name>MyHello</local-jndi-name> + </weblogic-enterprise-bean> +</weblogic-ejb-jar> +---- + + + + +== HelloTest + + +[source,java] +---- +package org.superbiz.hello; + +import junit.framework.TestCase; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + +/** + * @version $Revision: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public class HelloTest extends TestCase { + + public void test() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + InitialContext initialContext = new InitialContext(properties); + + HelloEjbLocalHome localHome = (HelloEjbLocalHome) initialContext.lookup("MyHello"); + HelloEjbLocal helloEjb = localHome.create(); + + String message = helloEjb.sayHello(); + + assertEquals(message, "Hello, World!"); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.hello.HelloTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/helloworld-weblogic +INFO - openejb.base = /Users/dblevins/examples/helloworld-weblogic +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/helloworld-weblogic/target/classes +INFO - Beginning load: /Users/dblevins/examples/helloworld-weblogic/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/helloworld-weblogic/classpath.ear +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean HelloBean: Container(type=STATELESS, id=Default Stateless Container) +INFO - Enterprise application "/Users/dblevins/examples/helloworld-weblogic/classpath.ear" loaded. +INFO - Assembling app: /Users/dblevins/examples/helloworld-weblogic/classpath.ear +INFO - Jndi(name=MyHello) --> Ejb(deployment-id=HelloBean) +INFO - Jndi(name=global/classpath.ear/helloworld-weblogic/HelloBean!org.superbiz.hello.HelloEjbLocalHome) --> Ejb(deployment-id=HelloBean) +INFO - Jndi(name=global/classpath.ear/helloworld-weblogic/HelloBean) --> Ejb(deployment-id=HelloBean) +INFO - Created Ejb(deployment-id=HelloBean, ejb-name=HelloBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=HelloBean, ejb-name=HelloBean, container=Default Stateless Container) +INFO - Deployed Application(path=/Users/dblevins/examples/helloworld-weblogic/classpath.ear) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.414 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + +
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/index-ng.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/index-ng.adoc b/src/main/jbake/content/examples/index-ng.adoc new file mode 100755 index 0000000..822efdd --- /dev/null +++ b/src/main/jbake/content/examples/index-ng.adoc @@ -0,0 +1,5 @@ += Examples +:jbake-date: 2016-08-30 +:jbake-type: examples +:jbake-status: published +:jbake-tomeepdf: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/index.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/index.adoc b/src/main/jbake/content/examples/index.adoc new file mode 100755 index 0000000..822efdd --- /dev/null +++ b/src/main/jbake/content/examples/index.adoc @@ -0,0 +1,5 @@ += Examples +:jbake-date: 2016-08-30 +:jbake-type: examples +:jbake-status: published +:jbake-tomeepdf: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/injection-of-connectionfactory.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/injection-of-connectionfactory.adoc b/src/main/jbake/content/examples/injection-of-connectionfactory.adoc new file mode 100755 index 0000000..c861c7b --- /dev/null +++ b/src/main/jbake/content/examples/injection-of-connectionfactory.adoc @@ -0,0 +1,180 @@ += Injection Of Connectionfactory +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example injection-of-connectionfactory can be browsed at https://github.com/apache/tomee/tree/master/examples/injection-of-connectionfactory + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== Messages + + +[source,java] +---- +package org.superbiz.injection.jms; + +import javax.annotation.Resource; +import javax.ejb.Stateless; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; + +@Stateless +public class Messages { + + @Resource + private ConnectionFactory connectionFactory; + + @Resource + private Queue chatQueue; + + + public void sendMessage(String text) throws JMSException { + + Connection connection = null; + Session session = null; + + try { + connection = connectionFactory.createConnection(); + connection.start(); + + // Create a Session + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(chatQueue); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a message + TextMessage message = session.createTextMessage(text); + + // Tell the producer to send the message + producer.send(message); + } finally { + // Clean up + if (session != null) session.close(); + if (connection != null) connection.close(); + } + } + + public String receiveMessage() throws JMSException { + + Connection connection = null; + Session session = null; + MessageConsumer consumer = null; + try { + connection = connectionFactory.createConnection(); + connection.start(); + + // Create a Session + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageConsumer from the Session to the Topic or Queue + consumer = session.createConsumer(chatQueue); + + // Wait for a message + TextMessage message = (TextMessage) consumer.receive(1000); + + return message.getText(); + } finally { + if (consumer != null) consumer.close(); + if (session != null) session.close(); + if (connection != null) connection.close(); + } + } +} +---- + + +== MessagingBeanTest + + +[source,java] +---- +package org.superbiz.injection.jms; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; + +public class MessagingBeanTest extends TestCase { + + public void test() throws Exception { + + final Context context = EJBContainer.createEJBContainer().getContext(); + + Messages messages = (Messages) context.lookup("java:global/injection-of-connectionfactory/Messages"); + + messages.sendMessage("Hello World!"); + messages.sendMessage("How are you?"); + messages.sendMessage("Still spinning?"); + + assertEquals(messages.receiveMessage(), "Hello World!"); + assertEquals(messages.receiveMessage(), "How are you?"); + assertEquals(messages.receiveMessage(), "Still spinning?"); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.injection.jms.MessagingBeanTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/injection-of-connectionfactory +INFO - openejb.base = /Users/dblevins/examples/injection-of-connectionfactory +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/injection-of-connectionfactory/target/classes +INFO - Beginning load: /Users/dblevins/examples/injection-of-connectionfactory/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/injection-of-connectionfactory +WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime. +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean Messages: Container(type=STATELESS, id=Default Stateless Container) +INFO - Configuring Service(id=Default JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory) +INFO - Auto-creating a Resource with id 'Default JMS Connection Factory' of type 'javax.jms.ConnectionFactory for 'Messages'. +INFO - Configuring Service(id=Default JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter) +INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.injection.jms.Messages/connectionFactory' in bean Messages to Resource(id=Default JMS Connection Factory) +INFO - Configuring Service(id=org.superbiz.injection.jms.Messages/chatQueue, type=Resource, provider-id=Default Queue) +INFO - Auto-creating a Resource with id 'org.superbiz.injection.jms.Messages/chatQueue' of type 'javax.jms.Queue for 'Messages'. +INFO - Auto-linking resource-env-ref 'java:comp/env/org.superbiz.injection.jms.Messages/chatQueue' in bean Messages to Resource(id=org.superbiz.injection.jms.Messages/chatQueue) +INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.injection.jms.MessagingBeanTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Enterprise application "/Users/dblevins/examples/injection-of-connectionfactory" loaded. +INFO - Assembling app: /Users/dblevins/examples/injection-of-connectionfactory +INFO - Jndi(name="java:global/injection-of-connectionfactory/Messages!org.superbiz.injection.jms.Messages") +INFO - Jndi(name="java:global/injection-of-connectionfactory/Messages") +INFO - Jndi(name="java:global/EjbModule1634151355/org.superbiz.injection.jms.MessagingBeanTest!org.superbiz.injection.jms.MessagingBeanTest") +INFO - Jndi(name="java:global/EjbModule1634151355/org.superbiz.injection.jms.MessagingBeanTest") +INFO - Created Ejb(deployment-id=Messages, ejb-name=Messages, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=org.superbiz.injection.jms.MessagingBeanTest, ejb-name=org.superbiz.injection.jms.MessagingBeanTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=Messages, ejb-name=Messages, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=org.superbiz.injection.jms.MessagingBeanTest, ejb-name=org.superbiz.injection.jms.MessagingBeanTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/injection-of-connectionfactory) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.562 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/injection-of-datasource.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/injection-of-datasource.adoc b/src/main/jbake/content/examples/injection-of-datasource.adoc new file mode 100755 index 0000000..4637a56 --- /dev/null +++ b/src/main/jbake/content/examples/injection-of-datasource.adoc @@ -0,0 +1,248 @@ += Injection Of Datasource +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example injection-of-datasource can be browsed at https://github.com/apache/tomee/tree/master/examples/injection-of-datasource + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== Movie + + +[source,java] +---- +package org.superbiz.injection; + +/** + * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class Movie { + private String director; + private String title; + private int year; + + public Movie() { + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + +} +---- + + +== Movies + + +[source,java] +---- +package org.superbiz.injection; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.ejb.Stateful; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; + +@Stateful +public class Movies { + + /** + * The field name "movieDatabase" matches the DataSource we + * configure in the TestCase via : + * p.put("movieDatabase", "new://Resource?type=DataSource"); + * <p/> + * This would also match an equivalent delcaration in an openejb.xml: + * <Resource id="movieDatabase" type="DataSource"/> + * <p/> + * If you'd like the freedom to change the field name without + * impact on your configuration you can set the "name" attribute + * of the @Resource annotation to "movieDatabase" instead. + */ + @Resource + private DataSource movieDatabase; + + @PostConstruct + private void construct() throws Exception { + Connection connection = movieDatabase.getConnection(); + try { + PreparedStatement stmt = connection.prepareStatement("CREATE TABLE movie ( director VARCHAR(255), title VARCHAR(255), year integer)"); + stmt.execute(); + } finally { + connection.close(); + } + } + + public void addMovie(Movie movie) throws Exception { + Connection conn = movieDatabase.getConnection(); + try { + PreparedStatement sql = conn.prepareStatement("INSERT into movie (director, title, year) values (?, ?, ?)"); + sql.setString(1, movie.getDirector()); + sql.setString(2, movie.getTitle()); + sql.setInt(3, movie.getYear()); + sql.execute(); + } finally { + conn.close(); + } + } + + public void deleteMovie(Movie movie) throws Exception { + Connection conn = movieDatabase.getConnection(); + try { + PreparedStatement sql = conn.prepareStatement("DELETE from movie where director = ? AND title = ? AND year = ?"); + sql.setString(1, movie.getDirector()); + sql.setString(2, movie.getTitle()); + sql.setInt(3, movie.getYear()); + sql.execute(); + } finally { + conn.close(); + } + } + + public List<Movie> getMovies() throws Exception { + ArrayList<Movie> movies = new ArrayList<Movie>(); + Connection conn = movieDatabase.getConnection(); + try { + PreparedStatement sql = conn.prepareStatement("SELECT director, title, year from movie"); + ResultSet set = sql.executeQuery(); + while (set.next()) { + Movie movie = new Movie(); + movie.setDirector(set.getString("director")); + movie.setTitle(set.getString("title")); + movie.setYear(set.getInt("year")); + movies.add(movie); + } + } finally { + conn.close(); + } + return movies; + } +} +---- + + +== MoviesTest + + +[source,java] +---- +package org.superbiz.injection; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import java.util.List; +import java.util.Properties; + +//START SNIPPET: code +public class MoviesTest extends TestCase { + + public void test() throws Exception { + + Properties p = new Properties(); + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + Context context = EJBContainer.createEJBContainer(p).getContext(); + + Movies movies = (Movies) context.lookup("java:global/injection-of-datasource/Movies"); + + movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); + movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List<Movie> list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.injection.MoviesTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/injection-of-datasource +INFO - openejb.base = /Users/dblevins/examples/injection-of-datasource +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/injection-of-datasource/target/classes +INFO - Beginning load: /Users/dblevins/examples/injection-of-datasource/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/injection-of-datasource +WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime. +INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) +INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container) +INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.injection.Movies/movieDatabase' in bean Movies to Resource(id=movieDatabase) +INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.injection.MoviesTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Enterprise application "/Users/dblevins/examples/injection-of-datasource" loaded. +INFO - Assembling app: /Users/dblevins/examples/injection-of-datasource +INFO - Jndi(name="java:global/injection-of-datasource/Movies!org.superbiz.injection.Movies") +INFO - Jndi(name="java:global/injection-of-datasource/Movies") +INFO - Jndi(name="java:global/EjbModule1508028338/org.superbiz.injection.MoviesTest!org.superbiz.injection.MoviesTest") +INFO - Jndi(name="java:global/EjbModule1508028338/org.superbiz.injection.MoviesTest") +INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) +INFO - Created Ejb(deployment-id=org.superbiz.injection.MoviesTest, ejb-name=org.superbiz.injection.MoviesTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) +INFO - Started Ejb(deployment-id=org.superbiz.injection.MoviesTest, ejb-name=org.superbiz.injection.MoviesTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/injection-of-datasource) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.276 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/injection-of-ejbs.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/injection-of-ejbs.adoc b/src/main/jbake/content/examples/injection-of-ejbs.adoc new file mode 100755 index 0000000..4eb9b59 --- /dev/null +++ b/src/main/jbake/content/examples/injection-of-ejbs.adoc @@ -0,0 +1,234 @@ += Injection Of Ejbs +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example injection-of-ejbs can be browsed at https://github.com/apache/tomee/tree/master/examples/injection-of-ejbs + + +This example shows how to use the @EJB annotation on a bean class to refer to other beans. + +This functionality is often referred as dependency injection (see +http://www.martinfowler.com/articles/injection.html), and has been recently introduced in +Java EE 5. + +In this particular example, we will create two session stateless beans + + * a DataStore session bean + * a DataReader session bean + +The DataReader bean uses the DataStore to retrieve some informations, and +we will see how we can, inside the DataReader bean, get a reference to the +DataStore bean using the @EJB annotation, thus avoiding the use of the +JNDI API. + +== DataReader + + +[source,java] +---- +package org.superbiz.injection; + +import javax.ejb.EJB; +import javax.ejb.Stateless; + +/** + * This is an EJB 3.1 style pojo stateless session bean + * Every stateless session bean implementation must be annotated + * using the annotation @Stateless + * This EJB has 2 business interfaces: DataReaderRemote, a remote business + * interface, and DataReaderLocal, a local business interface + * <p/> + * The instance variables 'dataStoreRemote' is annotated with the @EJB annotation: + * this means that the application server, at runtime, will inject in this instance + * variable a reference to the EJB DataStoreRemote + * <p/> + * The instance variables 'dataStoreLocal' is annotated with the @EJB annotation: + * this means that the application server, at runtime, will inject in this instance + * variable a reference to the EJB DataStoreLocal + */ +//START SNIPPET: code +@Stateless +public class DataReader { + + @EJB + private DataStoreRemote dataStoreRemote; + @EJB + private DataStoreLocal dataStoreLocal; + @EJB + private DataStore dataStore; + + public String readDataFromLocalStore() { + return "LOCAL:" + dataStoreLocal.getData(); + } + + public String readDataFromLocalBeanStore() { + return "LOCALBEAN:" + dataStore.getData(); + } + + public String readDataFromRemoteStore() { + return "REMOTE:" + dataStoreRemote.getData(); + } +} +---- + + +== DataStore + + +[source,java] +---- +package org.superbiz.injection; + +import javax.ejb.LocalBean; +import javax.ejb.Stateless; + +/** + * This is an EJB 3 style pojo stateless session bean + * Every stateless session bean implementation must be annotated + * using the annotation @Stateless + * This EJB has 2 business interfaces: DataStoreRemote, a remote business + * interface, and DataStoreLocal, a local business interface + */ +//START SNIPPET: code +@Stateless +@LocalBean +public class DataStore implements DataStoreLocal, DataStoreRemote { + + public String getData() { + return "42"; + } +} +---- + + +== DataStoreLocal + + +[source,java] +---- +package org.superbiz.injection; + +import javax.ejb.Local; + +/** + * This is an EJB 3 local business interface + * A local business interface may be annotated with the @Local + * annotation, but it's optional. A business interface which is + * not annotated with @Local or @Remote is assumed to be Local + */ +//START SNIPPET: code +@Local +public interface DataStoreLocal { + + public String getData(); +} +---- + + +== DataStoreRemote + + +[source,java] +---- +package org.superbiz.injection; + +import javax.ejb.Remote; + +/** + * This is an EJB 3 remote business interface + * A remote business interface must be annotated with the @Remote + * annotation + */ +//START SNIPPET: code +@Remote +public interface DataStoreRemote { + + public String getData(); +} +---- + + +== EjbDependencyTest + + +[source,java] +---- +package org.superbiz.injection; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; + +/** + * A test case for DataReaderImpl ejb, testing both the remote and local interface + */ +//START SNIPPET: code +public class EjbDependencyTest extends TestCase { + + public void test() throws Exception { + final Context context = EJBContainer.createEJBContainer().getContext(); + + DataReader dataReader = (DataReader) context.lookup("java:global/injection-of-ejbs/DataReader"); + + assertNotNull(dataReader); + + assertEquals("LOCAL:42", dataReader.readDataFromLocalStore()); + assertEquals("REMOTE:42", dataReader.readDataFromRemoteStore()); + assertEquals("LOCALBEAN:42", dataReader.readDataFromLocalBeanStore()); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.injection.EjbDependencyTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/injection-of-ejbs +INFO - openejb.base = /Users/dblevins/examples/injection-of-ejbs +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/injection-of-ejbs/target/classes +INFO - Beginning load: /Users/dblevins/examples/injection-of-ejbs/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/injection-of-ejbs +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean DataReader: Container(type=STATELESS, id=Default Stateless Container) +INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.injection.EjbDependencyTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Enterprise application "/Users/dblevins/examples/injection-of-ejbs" loaded. +INFO - Assembling app: /Users/dblevins/examples/injection-of-ejbs +INFO - Jndi(name="java:global/injection-of-ejbs/DataReader!org.superbiz.injection.DataReader") +INFO - Jndi(name="java:global/injection-of-ejbs/DataReader") +INFO - Jndi(name="java:global/injection-of-ejbs/DataStore!org.superbiz.injection.DataStore") +INFO - Jndi(name="java:global/injection-of-ejbs/DataStore!org.superbiz.injection.DataStoreLocal") +INFO - Jndi(name="java:global/injection-of-ejbs/DataStore!org.superbiz.injection.DataStoreRemote") +INFO - Jndi(name="java:global/injection-of-ejbs/DataStore") +INFO - Jndi(name="java:global/EjbModule355598874/org.superbiz.injection.EjbDependencyTest!org.superbiz.injection.EjbDependencyTest") +INFO - Jndi(name="java:global/EjbModule355598874/org.superbiz.injection.EjbDependencyTest") +INFO - Created Ejb(deployment-id=DataReader, ejb-name=DataReader, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=DataStore, ejb-name=DataStore, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=org.superbiz.injection.EjbDependencyTest, ejb-name=org.superbiz.injection.EjbDependencyTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=DataReader, ejb-name=DataReader, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=DataStore, ejb-name=DataStore, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=org.superbiz.injection.EjbDependencyTest, ejb-name=org.superbiz.injection.EjbDependencyTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/injection-of-ejbs) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.225 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/injection-of-entitymanager.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/injection-of-entitymanager.adoc b/src/main/jbake/content/examples/injection-of-entitymanager.adoc new file mode 100755 index 0000000..e80e407 --- /dev/null +++ b/src/main/jbake/content/examples/injection-of-entitymanager.adoc @@ -0,0 +1,249 @@ += Injection Of Entitymanager +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example injection-of-entitymanager can be browsed at https://github.com/apache/tomee/tree/master/examples/injection-of-entitymanager + + +This example shows use of `@PersistenceContext` to have an `EntityManager` with an +`EXTENDED` persistence context injected into a `@Stateful bean`. A JPA +`@Entity` bean is used with the `EntityManager` to create, persist and merge +data to a database. + +== Creating the JPA Entity + +The entity itself is simply a pojo annotated with `@Entity`. We create one called `Movie` which we can use to hold movie records. + + +[source,java] +---- +package org.superbiz.injection.jpa; + +import javax.persistence.Entity; + +@Entity +public class Movie { + + @Id @GeneratedValue + private long id; + + private String director; + private String title; + private int year; + + public Movie() { + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } +} +---- + + +== Configure the EntityManager via a persistence.xml file + +The above `Movie` entity can be created, removed, updated or deleted via an `EntityManager` object. The `EntityManager` itself is +configured via a `META-INF/persistence.xml` file that is placed in the same jar as the `Movie` entity. + + +[source,xml] +---- +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + + <persistence-unit name="movie-unit"> + <jta-data-source>movieDatabase</jta-data-source> + <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source> + <class>org.superbiz.injection.jpa.Movie</class> + + <properties> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> + </properties> + </persistence-unit> +</persistence> +---- + + +Notice that the `Movie` entity is listed via a `<class>` element. This is not required, but can help when testing or when the +`Movie` class is located in a different jar than the jar containing the `persistence.xml` file. + +== Injection via @PersistenceContext + +The `EntityManager` itself is created by the container using the information in the `persistence.xml`, so to use it at +runtime, we simply need to request it be injected into one of our components. We do this via `@PersistenceContext` + +The `@PersistenceContext` annotation can be used on any CDI bean, EJB, Servlet, Servlet Listener, Servlet Filter, or JSF ManagedBean. If you don't use an EJB you will need to use a `UserTransaction` begin and commit transactions manually. A transaction is required for any of the create, update or delete methods of the EntityManager to work. + + +[source,java] +---- +package org.superbiz.injection.jpa; + +import javax.ejb.Stateful; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.Query; +import java.util.List; + +@Stateful +public class Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public void addMovie(Movie movie) throws Exception { + entityManager.persist(movie); + } + + public void deleteMovie(Movie movie) throws Exception { + entityManager.remove(movie); + } + + public List<Movie> getMovies() throws Exception { + Query query = entityManager.createQuery("SELECT m from Movie as m"); + return query.getResultList(); + } +} +---- + + +This particular `EntityManager` is injected as an `EXTENDED` persistence context, which simply means that the `EntityManager` +is created when the `@Stateful` bean is created and destroyed when the `@Stateful` bean is destroyed. Simply put, the +data in the `EntityManager` is cached for the lifetime of the `@Stateful` bean. + +The use of `EXTENDED` persistence contexts is **only** available to `@Stateful` beans. See the link:../../jpa-concepts.html[JPA Concepts] page for an high level explanation of what a "persistence context" really is and how it is significant to JPA. + +== MoviesTest + +Testing JPA is quite easy, we can simply use the `EJBContainer` API to create a container in our test case. + + +[source,java] +---- +package org.superbiz.injection.jpa; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import java.util.List; +import java.util.Properties; + +//START SNIPPET: code +public class MoviesTest extends TestCase { + + public void test() throws Exception { + + final Properties p = new Properties(); + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + final Context context = EJBContainer.createEJBContainer(p).getContext(); + + Movies movies = (Movies) context.lookup("java:global/injection-of-entitymanager/Movies"); + + movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); + movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List<Movie> list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + } +} +---- + + += Running + +When we run our test case we should see output similar to the following. + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.injection.jpa.MoviesTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/injection-of-entitymanager +INFO - openejb.base = /Users/dblevins/examples/injection-of-entitymanager +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/injection-of-entitymanager/target/classes +INFO - Beginning load: /Users/dblevins/examples/injection-of-entitymanager/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/injection-of-entitymanager +INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) +INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container) +INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.injection.jpa.MoviesTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Configuring PersistenceUnit(name=movie-unit) +INFO - Auto-creating a Resource with id 'movieDatabaseNonJta' of type 'DataSource for 'movie-unit'. +INFO - Configuring Service(id=movieDatabaseNonJta, type=Resource, provider-id=movieDatabase) +INFO - Adjusting PersistenceUnit movie-unit <non-jta-data-source> to Resource ID 'movieDatabaseNonJta' from 'movieDatabaseUnmanaged' +INFO - Enterprise application "/Users/dblevins/examples/injection-of-entitymanager" loaded. +INFO - Assembling app: /Users/dblevins/examples/injection-of-entitymanager +INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 462ms +INFO - Jndi(name="java:global/injection-of-entitymanager/Movies!org.superbiz.injection.jpa.Movies") +INFO - Jndi(name="java:global/injection-of-entitymanager/Movies") +INFO - Jndi(name="java:global/EjbModule1461341140/org.superbiz.injection.jpa.MoviesTest!org.superbiz.injection.jpa.MoviesTest") +INFO - Jndi(name="java:global/EjbModule1461341140/org.superbiz.injection.jpa.MoviesTest") +INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) +INFO - Created Ejb(deployment-id=org.superbiz.injection.jpa.MoviesTest, ejb-name=org.superbiz.injection.jpa.MoviesTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) +INFO - Started Ejb(deployment-id=org.superbiz.injection.jpa.MoviesTest, ejb-name=org.superbiz.injection.jpa.MoviesTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/injection-of-entitymanager) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.301 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/injection-of-env-entry.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/injection-of-env-entry.adoc b/src/main/jbake/content/examples/injection-of-env-entry.adoc new file mode 100755 index 0000000..add6d0e --- /dev/null +++ b/src/main/jbake/content/examples/injection-of-env-entry.adoc @@ -0,0 +1,271 @@ += Using EnvEntries +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example injection-of-env-entry can be browsed at https://github.com/apache/tomee/tree/master/examples/injection-of-env-entry + + +The `@Resource` annotation can be used to inject several things including +DataSources, Topics, Queues, etc. Most of these are container supplied objects. + +It is possible, however, to supply your own values to be injected via an `<env-entry>` +in your `ejb-jar.xml` or `web.xml` deployment descriptor. Java EE 6 supported `<env-entry>` types +are limited to the following: + + - java.lang.String + - java.lang.Integer + - java.lang.Short + - java.lang.Float + - java.lang.Double + - java.lang.Byte + - java.lang.Character + - java.lang.Boolean + - java.lang.Class + - java.lang.Enum (any enum) + +See also the link:../custom-injection[Custom Injection] exmaple for a TomEE and OpenEJB feature that will let you +use more than just the above types as well as declare `<env-entry>` items with a plain properties file. + += Using @Resource for basic properties + +The use of the `@Resource` annotation isn't limited to setters. For +example, this annotation could have been used on the corresponding *field* +like so: + + +[source,java] +---- +@Resource +private int maxLineItems; + +A fuller example might look like this: + +package org.superbiz.injection.enventry; + +import javax.annotation.Resource; +import javax.ejb.Singleton; +import java.util.Date; + +@Singleton +public class Configuration { + + @Resource + private String color; + + @Resource + private Shape shape; + + @Resource + private Class strategy; + + @Resource(name = "date") + private long date; + + public String getColor() { + return color; + } + + public Shape getShape() { + return shape; + } + + public Class getStrategy() { + return strategy; + } + + public Date getDate() { + return new Date(date); + } +} +---- + + +Here we have an `@Singleton` bean called `Confuration` that has the following properties (`<env-entry>` items) + +- String color +- Shape shape +- Class strategy +- long date + +== Supplying @Resource values for <env-entry> items in ejb-jar.xml + +The values for our `color`, `shape`, `strategy` and `date` properties are supplied via `<env-entry>` elements in the `ejb-jar.xml` file or the +`web.xml` file like so: + + + +[source,xml] +---- +<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="false"> + <enterprise-beans> + <session> + <ejb-name>Configuration</ejb-name> + <env-entry> + <env-entry-name>org.superbiz.injection.enventry.Configuration/color</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>orange</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>org.superbiz.injection.enventry.Configuration/shape</env-entry-name> + <env-entry-type>org.superbiz.injection.enventry.Shape</env-entry-type> + <env-entry-value>TRIANGLE</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>org.superbiz.injection.enventry.Configuration/strategy</env-entry-name> + <env-entry-type>java.lang.Class</env-entry-type> + <env-entry-value>org.superbiz.injection.enventry.Widget</env-entry-value> + </env-entry> + <env-entry> + <description>The name was explicitly set in the annotation so the classname prefix isn't required</description> + <env-entry-name>date</env-entry-name> + <env-entry-type>java.lang.Long</env-entry-type> + <env-entry-value>123456789</env-entry-value> + </env-entry> + </session> + </enterprise-beans> +</ejb-jar> +---- + + + +=== Using the @Resource 'name' attribute + +Note that `date` was referenced by `name` as: + + +[source,java] +---- +@Resource(name = "date") +private long date; + +When the `@Resource(name)` is used, you do not need to specify the full class name of the bean and can do it briefly like so: + + <env-entry> + <description>The name was explicitly set in the annotation so the classname prefix isn't required</description> + <env-entry-name>date</env-entry-name> + <env-entry-type>java.lang.Long</env-entry-type> + <env-entry-value>123456789</env-entry-value> + </env-entry> + +Conversly, `color` was not referenced by `name` + +@Resource +private String color; + +When something is not referenced by `name` in the `@Resource` annotation a default name is created. The format is essentially this: + +bean.getClass() + "/" + field.getName() + +So the default `name` of the above `color` property ends up being `org.superbiz.injection.enventry.Configuration/color`. This is the name +we must use when we attempt to decalre a value for it in xml. + + <env-entry> + <env-entry-name>org.superbiz.injection.enventry.Configuration/color</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>orange</env-entry-value> + </env-entry> + +### @Resource and Enum (Enumerations) + +The `shape` field is actually a custom Java Enum type + +package org.superbiz.injection.enventry; + +public enum Shape { + + CIRCLE, + TRIANGLE, + SQUARE +} +---- + + +As of Java EE 6, java.lang.Enum types are allowed as `<env-entry>` items. Declaring one in xml is done using the actual enum's class name like so: + + <env-entry> + <env-entry-name>org.superbiz.injection.enventry.Configuration/shape</env-entry-name> + <env-entry-type>org.superbiz.injection.enventry.Shape</env-entry-type> + <env-entry-value>TRIANGLE</env-entry-value> + </env-entry> + +Do not use `<env-entry-type>java.lang.Enum</env-entry-type>` or it will not work! + +== ConfigurationTest + + +[source,java] +---- +package org.superbiz.injection.enventry; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import java.util.Date; + +public class ConfigurationTest extends TestCase { + + + public void test() throws Exception { + final Context context = EJBContainer.createEJBContainer().getContext(); + + final Configuration configuration = (Configuration) context.lookup("java:global/injection-of-env-entry/Configuration"); + + assertEquals("orange", configuration.getColor()); + + assertEquals(Shape.TRIANGLE, configuration.getShape()); + + assertEquals(Widget.class, configuration.getStrategy()); + + assertEquals(new Date(123456789), configuration.getDate()); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.injection.enventry.ConfigurationTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/injection-of-env-entry +INFO - openejb.base = /Users/dblevins/examples/injection-of-env-entry +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Found EjbModule in classpath: /Users/dblevins/examples/injection-of-env-entry/target/classes +INFO - Beginning load: /Users/dblevins/examples/injection-of-env-entry/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/injection-of-env-entry +WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime. +INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container) +INFO - Auto-creating a container for bean Configuration: Container(type=SINGLETON, id=Default Singleton Container) +INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.injection.enventry.ConfigurationTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Enterprise application "/Users/dblevins/examples/injection-of-env-entry" loaded. +INFO - Assembling app: /Users/dblevins/examples/injection-of-env-entry +INFO - Jndi(name="java:global/injection-of-env-entry/Configuration!org.superbiz.injection.enventry.Configuration") +INFO - Jndi(name="java:global/injection-of-env-entry/Configuration") +INFO - Jndi(name="java:global/EjbModule1355224018/org.superbiz.injection.enventry.ConfigurationTest!org.superbiz.injection.enventry.ConfigurationTest") +INFO - Jndi(name="java:global/EjbModule1355224018/org.superbiz.injection.enventry.ConfigurationTest") +INFO - Created Ejb(deployment-id=org.superbiz.injection.enventry.ConfigurationTest, ejb-name=org.superbiz.injection.enventry.ConfigurationTest, container=Default Managed Container) +INFO - Created Ejb(deployment-id=Configuration, ejb-name=Configuration, container=Default Singleton Container) +INFO - Started Ejb(deployment-id=org.superbiz.injection.enventry.ConfigurationTest, ejb-name=org.superbiz.injection.enventry.ConfigurationTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=Configuration, ejb-name=Configuration, container=Default Singleton Container) +INFO - Deployed Application(path=/Users/dblevins/examples/injection-of-env-entry) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.664 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/interceptors.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/interceptors.adoc b/src/main/jbake/content/examples/interceptors.adoc new file mode 100755 index 0000000..d59fc72 --- /dev/null +++ b/src/main/jbake/content/examples/interceptors.adoc @@ -0,0 +1,888 @@ += Interceptors +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example interceptors can be browsed at https://github.com/apache/tomee/tree/master/examples/interceptors + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== ClassLevelInterceptorOne + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class ClassLevelInterceptorOne { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== ClassLevelInterceptorSuperClassOne + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class ClassLevelInterceptorSuperClassOne { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== ClassLevelInterceptorSuperClassTwo + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class ClassLevelInterceptorSuperClassTwo extends SuperClassOfClassLevelInterceptor { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== ClassLevelInterceptorTwo + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class ClassLevelInterceptorTwo { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== DefaultInterceptorOne + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.annotation.PostConstruct; +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class DefaultInterceptorOne { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } + + @PostConstruct + protected void postConstructInterceptor(InvocationContext ic) throws Exception { + Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== DefaultInterceptorTwo + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class DefaultInterceptorTwo { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== FullyIntercepted + + +[source,java] +---- +package org.superbiz.interceptors; + +import java.util.List; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public interface FullyIntercepted { + + List<String> businessMethod(); + + List<String> methodWithDefaultInterceptorsExcluded(); +} +---- + + +== FullyInterceptedBean + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.ejb.Local; +import javax.ejb.Stateless; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptors; +import javax.interceptor.InvocationContext; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +@Stateless +@Local +@Interceptors({ClassLevelInterceptorOne.class, ClassLevelInterceptorTwo.class}) +public class FullyInterceptedBean extends FullyInterceptedSuperClass implements FullyIntercepted { + + @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class}) + public List<String> businessMethod() { + List<String> list = new ArrayList<String>(); + list.add("businessMethod"); + return list; + } + + @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class}) + public List<String> methodWithDefaultInterceptorsExcluded() { + List<String> list = new ArrayList<String>(); + list.add("methodWithDefaultInterceptorsExcluded"); + return list; + } + + @AroundInvoke + protected Object beanClassBusinessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, "beanClassBusinessMethodInterceptor"); + } +} +---- + + +== FullyInterceptedSuperClass + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.Interceptors; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +@Interceptors({ClassLevelInterceptorSuperClassOne.class, ClassLevelInterceptorSuperClassTwo.class}) +public class FullyInterceptedSuperClass { +} +---- + + +== MethodLevelInterceptorOne + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class MethodLevelInterceptorOne { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== MethodLevelInterceptorOnlyIntf + + +[source,java] +---- +package org.superbiz.interceptors; + +import java.io.Serializable; +import java.util.List; + +public interface MethodLevelInterceptorOnlyIntf<T extends Serializable> { + public List<T> makePersistent(T entity); +} +---- + + +== MethodLevelInterceptorOnlyParent + + +[source,java] +---- +package org.superbiz.interceptors; + +import java.util.List; + +public interface MethodLevelInterceptorOnlyParent extends MethodLevelInterceptorOnlyIntf<String> { + + public List<String> makePersistent(String entity); +} +---- + + +== MethodLevelInterceptorOnlySLSBean + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.ejb.Local; +import javax.ejb.Stateless; +import javax.interceptor.Interceptors; +import java.util.ArrayList; +import java.util.List; + +@Local(MethodLevelInterceptorOnlyParent.class) +@Stateless +public class MethodLevelInterceptorOnlySLSBean implements MethodLevelInterceptorOnlyParent { + + @Interceptors(MethodLevelInterceptorOne.class) + public List<String> makePersistent(String entity) { + List<String> list = new ArrayList<String>(); + list.add("makePersistent"); + return list; + } +} +---- + + +== MethodLevelInterceptorTwo + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class MethodLevelInterceptorTwo { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== SecondStatelessInterceptedBean + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.ejb.Stateless; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptors; +import javax.interceptor.InvocationContext; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev: 808273 $ $Date: 2009-08-26 20:42:06 -0700 (Wed, 26 Aug 2009) $ + */ +@Stateless +@Interceptors({ClassLevelInterceptorOne.class, ClassLevelInterceptorTwo.class}) +public class SecondStatelessInterceptedBean implements SecondStatelessInterceptedLocal { + + @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class}) + public List<String> methodWithDefaultInterceptorsExcluded() { + List<String> list = new ArrayList<String>(); + list.add("methodWithDefaultInterceptorsExcluded"); + return list; + } + + @AroundInvoke + protected Object beanClassBusinessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== SecondStatelessInterceptedLocal + + +[source,java] +---- +package org.superbiz.interceptors; + +import java.util.List; + +/** + * @version $Rev: 808273 $ $Date: 2009-08-26 20:42:06 -0700 (Wed, 26 Aug 2009) $ + */ +public interface SecondStatelessInterceptedLocal { + List<String> methodWithDefaultInterceptorsExcluded(); +} +---- + + +== SuperClassOfClassLevelInterceptor + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.annotation.PostConstruct; +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +/** + * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public class SuperClassOfClassLevelInterceptor { + + @AroundInvoke + protected Object businessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } + + @PostConstruct + protected void postConstructInterceptor(InvocationContext ic) throws Exception { + Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== ThirdSLSBean + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.ejb.Stateless; +import javax.interceptor.AroundInvoke; +import javax.interceptor.ExcludeClassInterceptors; +import javax.interceptor.ExcludeDefaultInterceptors; +import javax.interceptor.Interceptors; +import javax.interceptor.InvocationContext; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +@Stateless +@Interceptors({ClassLevelInterceptorOne.class, ClassLevelInterceptorTwo.class}) +@ExcludeDefaultInterceptors +public class ThirdSLSBean implements ThirdSLSBeanLocal { + + @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class}) + public List<String> businessMethod() { + List<String> list = new ArrayList<String>(); + list.add("businessMethod"); + return list; + } + + @Interceptors({MethodLevelInterceptorOne.class, MethodLevelInterceptorTwo.class}) + @ExcludeClassInterceptors + public List<String> anotherBusinessMethod() { + List<String> list = new ArrayList<String>(); + list.add("anotherBusinessMethod"); + return list; + } + + + @AroundInvoke + protected Object beanClassBusinessMethodInterceptor(InvocationContext ic) throws Exception { + return Utils.addClassSimpleName(ic, this.getClass().getSimpleName()); + } +} +---- + + +== ThirdSLSBeanLocal + + +[source,java] +---- +package org.superbiz.interceptors; + +import java.util.List; + +/** + * @version $Rev: 607320 $ $Date: 2007-12-28 12:15:06 -0800 (Fri, 28 Dec 2007) $ + */ +public interface ThirdSLSBeanLocal { + List<String> businessMethod(); + + List<String> anotherBusinessMethod(); +} +---- + + +== Utils + + +[source,java] +---- +package org.superbiz.interceptors; + +import javax.interceptor.InvocationContext; +import java.util.ArrayList; +import java.util.List; + +/** + * @version $Rev: 808273 $ $Date: 2009-08-26 20:42:06 -0700 (Wed, 26 Aug 2009) $ + */ +public class Utils { + + public static List<String> addClassSimpleName(InvocationContext ic, String classSimpleName) throws Exception { + List<String> list = new ArrayList<String>(); + list.add(classSimpleName); + List<String> listOfStrings = (List<String>) ic.proceed(); + if (listOfStrings != null) { + list.addAll(listOfStrings); + } + return list; + } +} +---- + + +== ejb-jar.xml + + +[source,xml] +---- +<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" + version="3.0"> + <interceptors> + <interceptor> + <interceptor-class>org.superbiz.interceptors.DefaultInterceptorOne</interceptor-class> + </interceptor> + <interceptor> + <interceptor-class>org.superbiz.interceptors.DefaultInterceptorTwo</interceptor-class> + </interceptor> + </interceptors> + <assembly-descriptor> + <interceptor-binding> + <ejb-name>*</ejb-name> + <interceptor-class>org.superbiz.interceptors.DefaultInterceptorOne</interceptor-class> + </interceptor-binding> + <interceptor-binding> + <ejb-name>*</ejb-name> + <interceptor-class>org.superbiz.interceptors.DefaultInterceptorTwo</interceptor-class> + </interceptor-binding> + <interceptor-binding> + <ejb-name>FullyInterceptedBean</ejb-name> + <exclude-default-interceptors>true</exclude-default-interceptors> + <method> + <method-name>methodWithDefaultInterceptorsExcluded</method-name> + </method> + </interceptor-binding> + <interceptor-binding> + <ejb-name>SecondStatelessInterceptedBean</ejb-name> + <exclude-default-interceptors>true</exclude-default-interceptors> + </interceptor-binding> + <interceptor-binding> + <ejb-name>MethodLevelInterceptorOnlySLSBean</ejb-name> + <exclude-default-interceptors>true</exclude-default-interceptors> + </interceptor-binding> + </assembly-descriptor> +</ejb-jar> +---- + + +== FullyInterceptedTest + + +[source,java] +---- +package org.superbiz.interceptors; + +import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public class FullyInterceptedTest extends TestCase { + + private InitialContext initCtx; + + @Before + public void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*"); + + initCtx = new InitialContext(properties); + } + + @Test + public void testBusinessMethod() throws Exception { + + FullyIntercepted fullyIntercepted = (FullyIntercepted) initCtx.lookup("FullyInterceptedBeanLocal"); + + assert fullyIntercepted != null; + + List<String> expected = new ArrayList<String>(); + expected.add("DefaultInterceptorOne"); + expected.add("DefaultInterceptorTwo"); + expected.add("ClassLevelInterceptorSuperClassOne"); + expected.add("ClassLevelInterceptorSuperClassTwo"); + expected.add("ClassLevelInterceptorOne"); + expected.add("ClassLevelInterceptorTwo"); + expected.add("MethodLevelInterceptorOne"); + expected.add("MethodLevelInterceptorTwo"); + expected.add("beanClassBusinessMethodInterceptor"); + expected.add("businessMethod"); + + List<String> actual = fullyIntercepted.businessMethod(); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } + + @Test + public void testMethodWithDefaultInterceptorsExcluded() throws Exception { + + FullyIntercepted fullyIntercepted = (FullyIntercepted) initCtx.lookup("FullyInterceptedBeanLocal"); + + assert fullyIntercepted != null; + + List<String> expected = new ArrayList<String>(); + expected.add("ClassLevelInterceptorSuperClassOne"); + expected.add("ClassLevelInterceptorSuperClassTwo"); + expected.add("ClassLevelInterceptorOne"); + expected.add("ClassLevelInterceptorTwo"); + expected.add("MethodLevelInterceptorOne"); + expected.add("MethodLevelInterceptorTwo"); + expected.add("beanClassBusinessMethodInterceptor"); + expected.add("methodWithDefaultInterceptorsExcluded"); + + List<String> actual = fullyIntercepted.methodWithDefaultInterceptorsExcluded(); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } + + @After + public void tearDown() throws Exception { + initCtx.close(); + } +} +---- + + +== MethodLevelInterceptorOnlyTest + + +[source,java] +---- +package org.superbiz.interceptors; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @version $Rev: 895825 $ $Date: 2010-01-04 15:35:22 -0800 (Mon, 04 Jan 2010) $ + */ +public class MethodLevelInterceptorOnlyTest extends TestCase { + private InitialContext initCtx; + + @Before + public void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*"); + + initCtx = new InitialContext(properties); + } + + @Test + public void testInterceptedGenerifiedBusinessIntfMethod() throws Exception { + MethodLevelInterceptorOnlyParent bean = (MethodLevelInterceptorOnlyParent) initCtx.lookup("MethodLevelInterceptorOnlySLSBeanLocal"); + + assert bean != null; + + List<String> expected = new ArrayList<String>(); + expected.add("MethodLevelInterceptorOne"); + expected.add("makePersistent"); + + List<String> actual = bean.makePersistent(null); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } +} +---- + + +== SecondStatelessInterceptedTest + + +[source,java] +---- +package org.superbiz.interceptors; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public class SecondStatelessInterceptedTest extends TestCase { + + private InitialContext initCtx; + + @Before + public void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*"); + + initCtx = new InitialContext(properties); + } + + @Test + public void testMethodWithDefaultInterceptorsExcluded() throws Exception { + SecondStatelessInterceptedLocal bean = + (SecondStatelessInterceptedLocal) initCtx.lookup("SecondStatelessInterceptedBeanLocal"); + + assert bean != null; + + List<String> expected = new ArrayList<String>(); + expected.add("ClassLevelInterceptorOne"); + expected.add("ClassLevelInterceptorTwo"); + expected.add("MethodLevelInterceptorOne"); + expected.add("MethodLevelInterceptorTwo"); + expected.add("SecondStatelessInterceptedBean"); + expected.add("methodWithDefaultInterceptorsExcluded"); + + List<String> actual = bean.methodWithDefaultInterceptorsExcluded(); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } +} +---- + + +== ThirdSLSBeanTest + + +[source,java] +---- +package org.superbiz.interceptors; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public class ThirdSLSBeanTest extends TestCase { + private InitialContext initCtx; + + @Before + public void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*"); + + initCtx = new InitialContext(properties); + } + + @Test + public void testMethodWithDefaultInterceptorsExcluded() throws Exception { + ThirdSLSBeanLocal bean = (ThirdSLSBeanLocal) initCtx.lookup("ThirdSLSBeanLocal"); + + assert bean != null; + + List<String> expected = new ArrayList<String>(); + expected.add("ClassLevelInterceptorOne"); + expected.add("ClassLevelInterceptorTwo"); + expected.add("MethodLevelInterceptorOne"); + expected.add("MethodLevelInterceptorTwo"); + expected.add("ThirdSLSBean"); + expected.add("businessMethod"); + + List<String> actual = bean.businessMethod(); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } + + @Test + public void testMethodWithDefaultAndClassInterceptorsExcluded() throws Exception { + ThirdSLSBeanLocal bean = (ThirdSLSBeanLocal) initCtx.lookup("ThirdSLSBeanLocal"); + + assert bean != null; + + List<String> expected = new ArrayList<String>(); + expected.add("MethodLevelInterceptorOne"); + expected.add("MethodLevelInterceptorTwo"); + expected.add("ThirdSLSBean"); + expected.add("anotherBusinessMethod"); + + List<String> actual = bean.anotherBusinessMethod(); + assert expected.equals(actual) : "Expected " + expected + ", but got " + actual; + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.interceptors.FullyInterceptedTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/interceptors +INFO - openejb.base = /Users/dblevins/examples/interceptors +INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +INFO - Using 'openejb.deployments.classpath.include=.*interceptors/target/classes.*' +INFO - Found EjbModule in classpath: /Users/dblevins/examples/interceptors/target/classes +INFO - Beginning load: /Users/dblevins/examples/interceptors/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/interceptors/classpath.ear +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean FullyInterceptedBean: Container(type=STATELESS, id=Default Stateless Container) +INFO - Enterprise application "/Users/dblevins/examples/interceptors/classpath.ear" loaded. +INFO - Assembling app: /Users/dblevins/examples/interceptors/classpath.ear +INFO - Jndi(name=FullyInterceptedBeanLocal) --> Ejb(deployment-id=FullyInterceptedBean) +INFO - Jndi(name=global/classpath.ear/interceptors/FullyInterceptedBean!org.superbiz.interceptors.FullyIntercepted) --> Ejb(deployment-id=FullyInterceptedBean) +INFO - Jndi(name=global/classpath.ear/interceptors/FullyInterceptedBean) --> Ejb(deployment-id=FullyInterceptedBean) +INFO - Jndi(name=ThirdSLSBeanLocal) --> Ejb(deployment-id=ThirdSLSBean) +INFO - Jndi(name=global/classpath.ear/interceptors/ThirdSLSBean!org.superbiz.interceptors.ThirdSLSBeanLocal) --> Ejb(deployment-id=ThirdSLSBean) +INFO - Jndi(name=global/classpath.ear/interceptors/ThirdSLSBean) --> Ejb(deployment-id=ThirdSLSBean) +INFO - Jndi(name=SecondStatelessInterceptedBeanLocal) --> Ejb(deployment-id=SecondStatelessInterceptedBean) +INFO - Jndi(name=global/classpath.ear/interceptors/SecondStatelessInterceptedBean!org.superbiz.interceptors.SecondStatelessInterceptedLocal) --> Ejb(deployment-id=SecondStatelessInterceptedBean) +INFO - Jndi(name=global/classpath.ear/interceptors/SecondStatelessInterceptedBean) --> Ejb(deployment-id=SecondStatelessInterceptedBean) +INFO - Jndi(name=MethodLevelInterceptorOnlySLSBeanLocal) --> Ejb(deployment-id=MethodLevelInterceptorOnlySLSBean) +INFO - Jndi(name=global/classpath.ear/interceptors/MethodLevelInterceptorOnlySLSBean!org.superbiz.interceptors.MethodLevelInterceptorOnlyParent) --> Ejb(deployment-id=MethodLevelInterceptorOnlySLSBean) +INFO - Jndi(name=global/classpath.ear/interceptors/MethodLevelInterceptorOnlySLSBean) --> Ejb(deployment-id=MethodLevelInterceptorOnlySLSBean) +INFO - Created Ejb(deployment-id=ThirdSLSBean, ejb-name=ThirdSLSBean, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=SecondStatelessInterceptedBean, ejb-name=SecondStatelessInterceptedBean, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=FullyInterceptedBean, ejb-name=FullyInterceptedBean, container=Default Stateless Container) +INFO - Created Ejb(deployment-id=MethodLevelInterceptorOnlySLSBean, ejb-name=MethodLevelInterceptorOnlySLSBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=ThirdSLSBean, ejb-name=ThirdSLSBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=SecondStatelessInterceptedBean, ejb-name=SecondStatelessInterceptedBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=FullyInterceptedBean, ejb-name=FullyInterceptedBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=MethodLevelInterceptorOnlySLSBean, ejb-name=MethodLevelInterceptorOnlySLSBean, container=Default Stateless Container) +INFO - Deployed Application(path=/Users/dblevins/examples/interceptors/classpath.ear) +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.564 sec +Running org.superbiz.interceptors.MethodLevelInterceptorOnlyTest +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec +Running org.superbiz.interceptors.SecondStatelessInterceptedTest +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec +Running org.superbiz.interceptors.ThirdSLSBeanTest +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec + +Results : + +Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 +---- + +