http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/simple-stateful.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-stateful.adoc b/src/main/jbake/content/examples/simple-stateful.adoc new file mode 100755 index 0000000..cc2b7d8 --- /dev/null +++ b/src/main/jbake/content/examples/simple-stateful.adoc @@ -0,0 +1,160 @@ += Simple Stateful +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-stateful can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-stateful + + +This example demonstrates a simple deployment of a Stateful session bean. + + +NOTE: "As its name suggests, a stateful session bean is similar to an interactive session. A stateful session bean is not shared; + +it can have only one client, in the same way that an interactive session can have only one user. +When the client terminates, its stateful session bean appears to terminate and is no longer associated with the client." + +The `Counter` class is a Stateful session bean that maintains a state in a form of a `count` integer field. +It exposes three methods: `count()`, `increment()` and `reset()` to manipulate and view its state. + +Typically, Stateful and Stateless beans implement Local and/or Remote interfaces to determine which methods should +be exposed. In this case, the bean is using a no-interface view, which means that all public methods are exposed +as a local view. + +== Counter + + +[source,java] +---- +package org.superbiz.counter; + +import javax.ejb.Stateful; + +/** + * This is an EJB 3 style pojo stateful session bean + * Every stateful session bean implementation must be annotated + * using the annotation @Stateful + * This EJB has 2 business interfaces: CounterRemote, a remote business + * interface, and CounterLocal, a local business interface + * <p/> + * Per EJB3 rules when the @Remote or @Local annotation isn't present + * in the bean class (this class), all interfaces are considered + * local unless explicitly annotated otherwise. If you look + * in the CounterRemote interface, you'll notice it uses the @Remote + * annotation while the CounterLocal interface is not annotated relying + * on the EJB3 default rules to make it a local interface. + */ +//START SNIPPET: code +@Stateful +public class Counter { + + private int count = 0; + + public int count() { + return count; + } + + public int increment() { + return ++count; + } + + public int reset() { + return (count = 0); + } +} +---- + + +== CounterTest + +The `Counter` class is tested by obtaining a `Context` object and performing a JNDI lookup on it, to retrieve +an instance of the `Counter` bean. After some state manipulation, a new instance is fetched from the container +and we can see that it's a new instance. + + +[source,java] +---- +package org.superbiz.counter; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; + +public class CounterTest extends TestCase { + + //START SNIPPET: local + public void test() throws Exception { + + final Context context = EJBContainer.createEJBContainer().getContext(); + + Counter counterA = (Counter) context.lookup("java:global/simple-stateful/Counter"); + + assertEquals(0, counterA.count()); + assertEquals(0, counterA.reset()); + assertEquals(1, counterA.increment()); + assertEquals(2, counterA.increment()); + assertEquals(0, counterA.reset()); + + counterA.increment(); + counterA.increment(); + counterA.increment(); + counterA.increment(); + + assertEquals(4, counterA.count()); + + // Get a new counter + Counter counterB = (Counter) context.lookup("java:global/simple-stateful/Counter"); + + // The new bean instance starts out at 0 + assertEquals(0, counterB.count()); + } + //END SNIPPET: local +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.counter.CounterTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/simple-stateful +INFO - openejb.base = /Users/dblevins/examples/simple-stateful +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/simple-stateful/target/classes +INFO - Beginning load: /Users/dblevins/examples/simple-stateful/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/simple-stateful +INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) +INFO - Auto-creating a container for bean Counter: 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.counter.CounterTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Enterprise application "/Users/dblevins/examples/simple-stateful" loaded. +INFO - Assembling app: /Users/dblevins/examples/simple-stateful +INFO - Jndi(name="java:global/simple-stateful/Counter!org.superbiz.counter.Counter") +INFO - Jndi(name="java:global/simple-stateful/Counter") +INFO - Jndi(name="java:global/EjbModule309142400/org.superbiz.counter.CounterTest!org.superbiz.counter.CounterTest") +INFO - Jndi(name="java:global/EjbModule309142400/org.superbiz.counter.CounterTest") +INFO - Created Ejb(deployment-id=Counter, ejb-name=Counter, container=Default Stateful Container) +INFO - Created Ejb(deployment-id=org.superbiz.counter.CounterTest, ejb-name=org.superbiz.counter.CounterTest, container=Default Managed Container) +INFO - Started Ejb(deployment-id=Counter, ejb-name=Counter, container=Default Stateful Container) +INFO - Started Ejb(deployment-id=org.superbiz.counter.CounterTest, ejb-name=org.superbiz.counter.CounterTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/simple-stateful) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.098 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/simple-stateless-callbacks.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-stateless-callbacks.adoc b/src/main/jbake/content/examples/simple-stateless-callbacks.adoc new file mode 100755 index 0000000..62bda15 --- /dev/null +++ b/src/main/jbake/content/examples/simple-stateless-callbacks.adoc @@ -0,0 +1,260 @@ += Simple Stateless with callback methods +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-stateless-callbacks can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-stateless-callbacks + + +This example shows how to create a stateless session bean that uses the @PostConstruct, @PreDestroy and @AroundInvoke annotations. + +== CalculatorBean + + +[source,java] +---- +package org.superbiz.stateless.basic; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Stateless; +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +@Stateless +public class CalculatorBean { + + @PostConstruct + public void postConstruct() { + ExecutionChannel.getInstance().notifyObservers("postConstruct"); + } + + @PreDestroy + public void preDestroy() { + ExecutionChannel.getInstance().notifyObservers("preDestroy"); + } + + @AroundInvoke + public Object intercept(InvocationContext ctx) throws Exception { + ExecutionChannel.getInstance().notifyObservers(ctx.getMethod().getName()); + return ctx.proceed(); + } + + public int add(int a, int b) { + return a + b; + } + + public int subtract(int a, int b) { + return a - b; + } + + public int multiply(int a, int b) { + return a * b; + } + + public int divide(int a, int b) { + return a / b; + } + + public int remainder(int a, int b) { + return a % b; + } + +} +---- + + +== ExecutionChannel + + +[source,java] +---- +package org.superbiz.counter; + +import java.util.ArrayList; +import java.util.List; + +public class ExecutionChannel { + private static final ExecutionChannel INSTANCE = new ExecutionChannel(); + + private final List<ExecutionObserver> observers = new ArrayList<ExecutionObserver>(); + + public static ExecutionChannel getInstance() { + return INSTANCE; + } + + public void addObserver(ExecutionObserver observer) { + this.observers.add(observer); + } + + public void notifyObservers(Object value) { + for (ExecutionObserver observer : this.observers) { + observer.onExecution(value); + } + } +} +---- + + +== ExecutionObserver + + +[source,java] +---- +package org.superbiz.counter; + +public interface ExecutionObserver { + + void onExecution(Object value); + +} +---- + + + +== CalculatorTest + + +[source,java] +---- +package org.superbiz.stateless.basic; + +import org.junit.Assert; +import org.junit.Test; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class CalculatorTest implements ExecutionObserver { + private static final String JNDI = "java:global/simple-stateless-callbacks/CalculatorBean"; + + private List<Object> received = new ArrayList<Object>(); + + public Context getContext() throws NamingException { + final Properties p = new Properties(); + p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + return new InitialContext(p); + + } + + @Test + public void test() throws Exception { + ExecutionChannel.getInstance().addObserver(this); + + final EJBContainer container = EJBContainer.createEJBContainer(); + + { + final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI); + + Assert.assertEquals(10, calculator.add(4, 6)); + + //the bean is constructed only when it is used for the first time + Assert.assertEquals("postConstruct", this.received.remove(0)); + Assert.assertEquals("add", this.received.remove(0)); + + Assert.assertEquals(-2, calculator.subtract(4, 6)); + Assert.assertEquals("subtract", this.received.remove(0)); + + Assert.assertEquals(24, calculator.multiply(4, 6)); + Assert.assertEquals("multiply", this.received.remove(0)); + + Assert.assertEquals(2, calculator.divide(12, 6)); + Assert.assertEquals("divide", this.received.remove(0)); + + Assert.assertEquals(4, calculator.remainder(46, 6)); + Assert.assertEquals("remainder", this.received.remove(0)); + } + + { + final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI); + + Assert.assertEquals(10, calculator.add(4, 6)); + Assert.assertEquals("add", this.received.remove(0)); + + } + + container.close(); + Assert.assertEquals("preDestroy", this.received.remove(0)); + Assert.assertTrue(this.received.isEmpty()); + } + + @Override + public void onExecution(Object value) { + System.out.println("Test step -> " + value); + this.received.add(value); + } +} +---- + + += Running + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.stateless.basic.CalculatorTest +INFO - ******************************************************************************** +INFO - OpenEJB http://tomee.apache.org/ +INFO - Startup: Sat Jul 21 09:23:38 EDT 2012 +INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved. +INFO - Version: 4.1.0 +INFO - Build date: 20120721 +INFO - Build time: 04:06 +INFO - ******************************************************************************** +INFO - openejb.home = /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks +INFO - openejb.base = /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks +INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@527736bd +INFO - Succeeded in installing singleton service +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. +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 - Creating TransactionManager(id=Default Transaction Manager) +INFO - Creating SecurityService(id=Default Security Service) +INFO - Beginning load: /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks/target/classes +INFO - Configuring enterprise application: /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks +INFO - Auto-deploying ejb CalculatorBean: EjbDeployment(deployment-id=CalculatorBean) +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean CalculatorBean: Container(type=STATELESS, id=Default Stateless Container) +INFO - Creating Container(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.stateless.basic.CalculatorTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Creating Container(id=Default Managed Container) +INFO - Using directory /tmp for stateful session passivation +INFO - Enterprise application "/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks" loaded. +INFO - Assembling app: /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks +INFO - Jndi(name="java:global/simple-stateless-callbacks/CalculatorBean!org.superbiz.stateless.basic.CalculatorBean") +INFO - Jndi(name="java:global/simple-stateless-callbacks/CalculatorBean") +INFO - Existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@527736bd +INFO - OpenWebBeans Container is starting... +INFO - Adding OpenWebBeansPlugin : [CdiPlugin] +INFO - All injection points are validated successfully. +INFO - OpenWebBeans Container has started, it took 111 ms. +INFO - Created Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container) +INFO - Deployed Application(path=/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks) +Test step -> postConstruct +Test step -> add +Test step -> subtract +Test step -> multiply +Test step -> divide +Test step -> remainder +Test step -> add +INFO - Undeploying app: /home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks +Test step -> preDestroy +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.884 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/simple-stateless-with-descriptor.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-stateless-with-descriptor.adoc b/src/main/jbake/content/examples/simple-stateless-with-descriptor.adoc new file mode 100755 index 0000000..d91bf04 --- /dev/null +++ b/src/main/jbake/content/examples/simple-stateless-with-descriptor.adoc @@ -0,0 +1,205 @@ += Simple Stateless with Descriptor +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-stateless-with-descriptor can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-stateless-with-descriptor + + +This test is similar to simple-stateless, with two major differences. In this case all the classes are regular POJOs without annotations. +The EJB-specific metadata is provided via an XML descriptor. The second difference is the explicite use of Local and Remote interfaces. + +== CalculatorImpl + + +[source,java] +---- +package org.superbiz.calculator; + +/** + * This is an EJB 3 stateless session bean, configured using an EJB 3 + * deployment descriptor as opposed to using annotations. + * This EJB has 2 business interfaces: CalculatorRemote, a remote business + * interface, and CalculatorLocal, a local business interface + */ +public class CalculatorImpl implements CalculatorRemote, CalculatorLocal { + + public int sum(int add1, int add2) { + return add1 + add2; + } + + public int multiply(int mul1, int mul2) { + return mul1 * mul2; + } +} +---- + + +== CalculatorLocal + + +[source,java] +---- +package org.superbiz.calculator; + +/** + * This is an EJB 3 local business interface + * This interface is specified using the business-local tag in the deployment descriptor + */ +public interface CalculatorLocal { + + public int sum(int add1, int add2); + + public int multiply(int mul1, int mul2); +} +---- + + +== CalculatorRemote + + +[source,java] +---- +package org.superbiz.calculator; + + +/** + * This is an EJB 3 remote business interface + * This interface is specified using the business-local tag in the deployment descriptor + */ +public interface CalculatorRemote { + + public int sum(int add1, int add2); + + public int multiply(int mul1, int mul2); +} +---- + + +== ejb-jar.xml + +The XML descriptor defines the EJB class and both local and remote interfaces. + + +[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"> + <enterprise-beans> + <session> + <ejb-name>CalculatorImpl</ejb-name> + <business-local>org.superbiz.calculator.CalculatorLocal</business-local> + <business-remote>org.superbiz.calculator.CalculatorRemote</business-remote> + <ejb-class>org.superbiz.calculator.CalculatorImpl</ejb-class> + <session-type>Stateless</session-type> + <transaction-type>Container</transaction-type> + </session> + </enterprise-beans> +</ejb-jar> +---- + + + + +== CalculatorTest + +Two tests obtain a Local and Remote interface to the bean instance. This time an `InitialContext` object is directly created, +as opposed to getting the context from `EJBContainer`, as we did in the previous example. + + +[source,java] +---- +package org.superbiz.calculator; + +import junit.framework.TestCase; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + +public class CalculatorTest extends TestCase { + + private InitialContext initialContext; + + protected void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + + initialContext = new InitialContext(properties); + } + + /** + * Lookup the Calculator bean via its remote home interface + * + * @throws Exception + */ + public void testCalculatorViaRemoteInterface() throws Exception { + Object object = initialContext.lookup("CalculatorImplRemote"); + + assertNotNull(object); + assertTrue(object instanceof CalculatorRemote); + CalculatorRemote calc = (CalculatorRemote) object; + assertEquals(10, calc.sum(4, 6)); + assertEquals(12, calc.multiply(3, 4)); + } + + /** + * Lookup the Calculator bean via its local home interface + * + * @throws Exception + */ + public void testCalculatorViaLocalInterface() throws Exception { + Object object = initialContext.lookup("CalculatorImplLocal"); + + assertNotNull(object); + assertTrue(object instanceof CalculatorLocal); + CalculatorLocal calc = (CalculatorLocal) object; + assertEquals(10, calc.sum(4, 6)); + assertEquals(12, calc.multiply(3, 4)); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.calculator.CalculatorTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/simple-stateless-with-descriptor +INFO - openejb.base = /Users/dblevins/examples/simple-stateless-with-descriptor +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/simple-stateless-with-descriptor/target/classes +INFO - Beginning load: /Users/dblevins/examples/simple-stateless-with-descriptor/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/simple-stateless-with-descriptor/classpath.ear +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean CalculatorImpl: Container(type=STATELESS, id=Default Stateless Container) +INFO - Enterprise application "/Users/dblevins/examples/simple-stateless-with-descriptor/classpath.ear" loaded. +INFO - Assembling app: /Users/dblevins/examples/simple-stateless-with-descriptor/classpath.ear +INFO - Jndi(name=CalculatorImplLocal) --> Ejb(deployment-id=CalculatorImpl) +INFO - Jndi(name=global/classpath.ear/simple-stateless-with-descriptor/CalculatorImpl!org.superbiz.calculator.CalculatorLocal) --> Ejb(deployment-id=CalculatorImpl) +INFO - Jndi(name=CalculatorImplRemote) --> Ejb(deployment-id=CalculatorImpl) +INFO - Jndi(name=global/classpath.ear/simple-stateless-with-descriptor/CalculatorImpl!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImpl) +INFO - Jndi(name=global/classpath.ear/simple-stateless-with-descriptor/CalculatorImpl) --> Ejb(deployment-id=CalculatorImpl) +INFO - Created Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container) +INFO - Deployed Application(path=/Users/dblevins/examples/simple-stateless-with-descriptor/classpath.ear) +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.475 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/simple-stateless.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-stateless.adoc b/src/main/jbake/content/examples/simple-stateless.adoc new file mode 100755 index 0000000..0845b5e --- /dev/null +++ b/src/main/jbake/content/examples/simple-stateless.adoc @@ -0,0 +1,221 @@ += Simple Stateless +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-stateless can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-stateless + + + +NOTE: "Stateless session beans are session beans whose instances have no conversational state. + +This means that all bean instances are equivalent when they are not involved in servicing +a client-invoked method. The term 'stateless' signifies that an instance has no state for a +specific client." + +What this means is quite simply that stateless beans are shared. They do in fact have state +as you can assign values to the variables, etc. in the bean instance. The only catch is there +are a pool of identical instances and you are not guaranteed to get the exact same instance on +every call. For each call, you get whatever instance happens to be available. This is identical +to checking out a book from the library or renting a movie from the video store. You are essentially +checking out or renting a new bean instance on each method call. + +== CalculatorBean + + +[source,java] +---- +package org.superbiz.stateless.basic; + +import javax.ejb.Stateless; + +@Stateless +public class CalculatorBean { + + public int add(int a, int b) { + return a + b; + } + + public int subtract(int a, int b) { + return a - b; + } + + public int multiply(int a, int b) { + return a * b; + } + + public int divide(int a, int b) { + return a / b; + } + + public int remainder(int a, int b) { + return a % b; + } +} +---- + + +== CalculatorTest + +Our `CalculatorBean` can be easily tested using the `EJBContainer` API in EJB 3.1 + + +[source,java] +---- +package org.superbiz.stateless.basic; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.NamingException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class CalculatorTest { + + private static EJBContainer ejbContainer; + + private CalculatorBean calculator; + + @BeforeClass + public static void startTheContainer() { + ejbContainer = EJBContainer.createEJBContainer(); + } + + @Before + public void lookupABean() throws NamingException { + Object object = ejbContainer.getContext().lookup("java:global/simple-stateless/CalculatorBean"); + + assertTrue(object instanceof CalculatorBean); + + calculator = (CalculatorBean) object; + } + + @AfterClass + public static void stopTheContainer() { + if (ejbContainer != null) { + ejbContainer.close(); + } + } + + /** + * Test Add method + */ + @Test + public void testAdd() { + + assertEquals(10, calculator.add(4, 6)); + + } + + /** + * Test Subtract method + */ + @Test + public void testSubtract() { + + assertEquals(-2, calculator.subtract(4, 6)); + + } + + /** + * Test Multiply method + */ + @Test + public void testMultiply() { + + assertEquals(24, calculator.multiply(4, 6)); + + } + + /** + * Test Divide method + */ + @Test + public void testDivide() { + + assertEquals(2, calculator.divide(12, 6)); + + } + + /** + * Test Remainder method + */ + @Test + public void testRemainder() { + + assertEquals(4, calculator.remainder(46, 6)); + + } + +} +---- + + += Running + + +Running the example should generate output similar to the following + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.stateless.basic.CalculatorTest +Infos - ******************************************************************************** +Infos - OpenEJB http://tomee.apache.org/ +Infos - Startup: Tue Aug 14 13:28:12 CEST 2012 +Infos - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved. +Infos - Version: 4.1.0 +Infos - Build date: 20120814 +Infos - Build time: 01:06 +Infos - ******************************************************************************** +Infos - openejb.home = /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless +Infos - openejb.base = /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless +Infos - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@33bb11 +Infos - Succeeded in installing singleton service +Infos - Using 'javax.ejb.embeddable.EJBContainer=true' +Infos - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. +Infos - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) +Infos - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) +Infos - Creating TransactionManager(id=Default Transaction Manager) +Infos - Creating SecurityService(id=Default Security Service) +Infos - Beginning load: /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless/target/classes +Infos - Configuring enterprise application: /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless +Infos - Auto-deploying ejb CalculatorBean: EjbDeployment(deployment-id=CalculatorBean) +Infos - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +Infos - Auto-creating a container for bean CalculatorBean: Container(type=STATELESS, id=Default Stateless Container) +Infos - Creating Container(id=Default Stateless Container) +Infos - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +Infos - Auto-creating a container for bean org.superbiz.stateless.basic.CalculatorTest: Container(type=MANAGED, id=Default Managed Container) +Infos - Creating Container(id=Default Managed Container) +Infos - Using directory /tmp for stateful session passivation +Infos - Enterprise application "/home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless" loaded. +Infos - Assembling app: /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless +Infos - Jndi(name="java:global/simple-stateless/CalculatorBean!org.superbiz.stateless.basic.CalculatorBean") +Infos - Jndi(name="java:global/simple-stateless/CalculatorBean") +Infos - Existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@33bb11 +Infos - OpenWebBeans Container is starting... +Infos - Adding OpenWebBeansPlugin : [CdiPlugin] +Infos - All injection points are validated successfully. +Infos - OpenWebBeans Container has started, it took 135 ms. +Infos - Created Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container) +Infos - Started Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container) +Infos - Deployed Application(path=/home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless) +Infos - Undeploying app: /home/a185558/Development/Apache/openejb-trunk/examples/simple-stateless +Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.068 sec + +Results : + +Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/simple-webservice-without-interface.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-webservice-without-interface.adoc b/src/main/jbake/content/examples/simple-webservice-without-interface.adoc new file mode 100755 index 0000000..fc17728 --- /dev/null +++ b/src/main/jbake/content/examples/simple-webservice-without-interface.adoc @@ -0,0 +1,110 @@ += Simple Webservice Without Interface +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-webservice-without-interface can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-webservice-without-interface + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== Calculator + + +[source,java] +---- +package org.superbiz.calculator; + +import javax.ejb.Stateless; +import javax.jws.WebService; + +@Stateless +@WebService( + portName = "CalculatorPort", + serviceName = "CalculatorWsService", + targetNamespace = "http://superbiz.org/wsdl") +public class Calculator { + public int sum(int add1, int add2) { + return add1 + add2; + } + + public int multiply(int mul1, int mul2) { + return mul1 * mul2; + } +} +---- + + +== ejb-jar.xml + + +[source,xml] +---- +<ejb-jar/> +---- + + +== CalculatorTest + + +[source,java] +---- +package org.superbiz.calculator; + +import org.apache.commons.io.IOUtils; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.NamingException; +import java.net.URL; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + +public class CalculatorTest { + private static EJBContainer container; + + @BeforeClass + public static void setUp() throws Exception { + final Properties properties = new Properties(); + properties.setProperty("openejb.embedded.remotable", "true"); + + container = EJBContainer.createEJBContainer(properties); + } + + @Before + public void inject() throws NamingException { + if (container != null) { + container.getContext().bind("inject", this); + } + } + + @AfterClass + public static void close() { + if (container != null) { + container.close(); + } + } + + @Test + public void wsdlExists() throws Exception { + final URL url = new URL("http://127.0.0.1:4204/Calculator?wsdl"); + assertTrue(IOUtils.readLines(url.openStream()).size() > 0); + assertTrue(IOUtils.readLines(url.openStream()).toString().contains("CalculatorWsService")); + } +} +---- + + +== ejb-jar.xml + + +[source,xml] +---- +<ejb-jar/> +---- + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/simple-webservice.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/simple-webservice.adoc b/src/main/jbake/content/examples/simple-webservice.adoc new file mode 100755 index 0000000..172fd4a --- /dev/null +++ b/src/main/jbake/content/examples/simple-webservice.adoc @@ -0,0 +1,386 @@ += JAX-WS @WebService example +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example simple-webservice can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-webservice + + +Creating Web Services with JAX-WS is quite easy. Little has to be done aside from annotating a class with `@WebService`. For +the purposes of this example we will also annotate our component with `@Stateless` which takes some of the configuration out of +the process and gives us some nice options such as transactions and security. + +== @WebService + +The following is all that is required. No external xml files are needed. This class placed in a jar or war and deployed into a compliant Java EE server like TomEE is enough to have the Calculator class discovered and deployed and the webservice online. + + +[source,java] +---- +import javax.ejb.Stateless; +import javax.jws.WebService; + +@Stateless +@WebService( + portName = "CalculatorPort", + serviceName = "CalculatorService", + targetNamespace = "http://superbiz.org/wsdl", + endpointInterface = "org.superbiz.calculator.ws.CalculatorWs") +public class Calculator implements CalculatorWs { + + public int sum(int add1, int add2) { + return add1 + add2; + } + + public int multiply(int mul1, int mul2) { + return mul1 * mul2; + } +} +---- + + +== @WebService Endpoint Interface + +Having an endpoint interface is not required, but it can make testing and using the web service from other Java clients far easier. + + +[source,java] +---- +import javax.jws.WebService; + +@WebService(targetNamespace = "http://superbiz.org/wsdl") +public interface CalculatorWs { + + public int sum(int add1, int add2); + + public int multiply(int mul1, int mul2); +} +---- + + +== Calculator WSDL + +The wsdl for our service is autmatically created for us and available at `http://127.0.0.1:4204/Calculator?wsdl`. In TomEE or Tomcat this would be at `http://127.0.0.1:8080/simple-webservice/Calculator?wsdl` + + +[source,xml] +---- +<?xml version="1.0" encoding="UTF-8"?> +<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="CalculatorService" + targetNamespace="http://superbiz.org/wsdl" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:tns="http://superbiz.org/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <wsdl:types> + <xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" + targetNamespace="http://superbiz.org/wsdl" xmlns:tns="http://superbiz.org/wsdl" + xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:element name="multiply" type="tns:multiply"/> + <xsd:complexType name="multiply"> + <xsd:sequence> + <xsd:element name="arg0" type="xsd:int"/> + <xsd:element name="arg1" type="xsd:int"/> + </xsd:sequence> + </xsd:complexType> + <xsd:element name="multiplyResponse" type="tns:multiplyResponse"/> + <xsd:complexType name="multiplyResponse"> + <xsd:sequence> + <xsd:element name="return" type="xsd:int"/> + </xsd:sequence> + </xsd:complexType> + <xsd:element name="sum" type="tns:sum"/> + <xsd:complexType name="sum"> + <xsd:sequence> + <xsd:element name="arg0" type="xsd:int"/> + <xsd:element name="arg1" type="xsd:int"/> + </xsd:sequence> + </xsd:complexType> + <xsd:element name="sumResponse" type="tns:sumResponse"/> + <xsd:complexType name="sumResponse"> + <xsd:sequence> + <xsd:element name="return" type="xsd:int"/> + </xsd:sequence> + </xsd:complexType> + </xsd:schema> + </wsdl:types> + <wsdl:message name="multiplyResponse"> + <wsdl:part element="tns:multiplyResponse" name="parameters"/> + </wsdl:message> + <wsdl:message name="sumResponse"> + <wsdl:part element="tns:sumResponse" name="parameters"/> + </wsdl:message> + <wsdl:message name="sum"> + <wsdl:part element="tns:sum" name="parameters"/> + </wsdl:message> + <wsdl:message name="multiply"> + <wsdl:part element="tns:multiply" name="parameters"/> + </wsdl:message> + <wsdl:portType name="CalculatorWs"> + <wsdl:operation name="multiply"> + <wsdl:input message="tns:multiply" name="multiply"/> + <wsdl:output message="tns:multiplyResponse" name="multiplyResponse"/> + </wsdl:operation> + <wsdl:operation name="sum"> + <wsdl:input message="tns:sum" name="sum"/> + <wsdl:output message="tns:sumResponse" name="sumResponse"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:binding name="CalculatorServiceSoapBinding" type="tns:CalculatorWs"> + <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="multiply"> + <soap:operation soapAction="" style="document"/> + <wsdl:input name="multiply"> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output name="multiplyResponse"> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + <wsdl:operation name="sum"> + <soap:operation soapAction="" style="document"/> + <wsdl:input name="sum"> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output name="sumResponse"> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + <wsdl:service name="CalculatorService"> + <wsdl:port binding="tns:CalculatorServiceSoapBinding" name="CalculatorPort"> + <soap:address location="http://127.0.0.1:4204/Calculator?wsdl"/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> +---- + + +== Accessing the @WebService with javax.xml.ws.Service + +In our testcase we see how to create a client for our `Calculator` service via the `javax.xml.ws.Service` class and leveraging our `CalculatorWs` endpoint interface. + +With this we can get an implementation of the interfacce generated dynamically for us that can be used to send compliant SOAP messages to our service. + + +[source,java] +---- +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.ejb.embeddable.EJBContainer; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import java.net.URL; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class CalculatorTest { + + @BeforeClass + public static void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty("openejb.embedded.remotable", "true"); + //properties.setProperty("httpejbd.print", "true"); + //properties.setProperty("httpejbd.indent.xml", "true"); + EJBContainer.createEJBContainer(properties); + } + + @Test + public void test() throws Exception { + Service calculatorService = Service.create( + new URL("http://127.0.0.1:4204/Calculator?wsdl"), + new QName("http://superbiz.org/wsdl", "CalculatorService")); + + assertNotNull(calculatorService); + + CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class); + assertEquals(10, calculator.sum(4, 6)); + assertEquals(12, calculator.multiply(3, 4)); + } +} +---- + + +For easy testing we'll use the Embeddable EJBContainer API part of EJB 3.1 to boot CXF in our testcase. This will deploy our application in the embedded container and bring the web service online so we can invoke it. + += Running + +Running the example can be done from maven with a simple 'mvn clean install' command run from the 'simple-webservice' directory. + +When run you should see output similar to the following. + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.calculator.ws.CalculatorTest +INFO - ******************************************************************************** +INFO - OpenEJB http://tomee.apache.org/ +INFO - Startup: Sat Feb 18 19:11:50 PST 2012 +INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved. +INFO - Version: 4.0.0-beta-3 +INFO - Build date: 20120218 +INFO - Build time: 03:32 +INFO - ******************************************************************************** +INFO - openejb.home = /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice +INFO - openejb.base = /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice +INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@16bdb503 +INFO - succeeded in installing singleton service +INFO - Using 'javax.ejb.embeddable.EJBContainer=true' +INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. +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 - Creating TransactionManager(id=Default Transaction Manager) +INFO - Creating SecurityService(id=Default Security Service) +INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice/target/classes +INFO - Using 'openejb.embedded=true' +INFO - Configuring enterprise application: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice +INFO - Auto-deploying ejb Calculator: EjbDeployment(deployment-id=Calculator) +INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) +INFO - Auto-creating a container for bean Calculator: Container(type=STATELESS, id=Default Stateless Container) +INFO - Creating Container(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.calculator.ws.CalculatorTest: Container(type=MANAGED, id=Default Managed Container) +INFO - Creating Container(id=Default Managed Container) +INFO - Using directory /var/folders/bd/f9ntqy1m8xj_fs006s6crtjh0000gn/T for stateful session passivation +INFO - Enterprise application "/Users/dblevins/work/all/trunk/openejb/examples/simple-webservice" loaded. +INFO - Assembling app: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice +INFO - ignoreXmlConfiguration == true +INFO - ignoreXmlConfiguration == true +INFO - existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@16bdb503 +INFO - OpenWebBeans Container is starting... +INFO - Adding OpenWebBeansPlugin : [CdiPlugin] +INFO - All injection points were validated successfully. +INFO - OpenWebBeans Container has started, it took [62] ms. +INFO - Created Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Stateless Container) +INFO - Started Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Stateless Container) +INFO - Deployed Application(path=/Users/dblevins/work/all/trunk/openejb/examples/simple-webservice) +INFO - Initializing network services +INFO - can't find log4j MDC class +INFO - Creating ServerService(id=httpejbd) +INFO - Creating ServerService(id=cxf) +INFO - Creating ServerService(id=admin) +INFO - Creating ServerService(id=ejbd) +INFO - Creating ServerService(id=ejbds) +INFO - Initializing network services +INFO - ** Starting Services ** +INFO - NAME IP PORT +INFO - httpejbd 127.0.0.1 4204 +INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from class org.superbiz.calculator.ws.CalculatorWs +INFO - Setting the server's publish address to be http://nopath:80 +INFO - Webservice(wsdl=http://127.0.0.1:4204/Calculator, qname={http://superbiz.org/wsdl}CalculatorService) --> Ejb(id=Calculator) +INFO - admin thread 127.0.0.1 4200 +INFO - ejbd 127.0.0.1 4201 +INFO - ejbd 127.0.0.1 4203 +INFO - ------- +INFO - Ready! +INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl +INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl +INFO - Default SAAJ universe not set +INFO - TX NotSupported: Suspended transaction null +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.584 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + + +== Inspecting the messages + +The above test case will result in the following SOAP messages being sent between the clien and server. + +=== sum(int, int) + +Request SOAP message: + + +[source,xml] +---- +<?xml version="1.0" encoding="UTF-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Body> + <ns1:sum xmlns:ns1="http://superbiz.org/wsdl"> + <arg0>4</arg0> + <arg1>6</arg1> + </ns1:sum> + </soap:Body> +</soap:Envelope> +---- + + +Response SOAP message: + + +[source,xml] +---- +<?xml version="1.0" encoding="UTF-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Body> + <ns1:sumResponse xmlns:ns1="http://superbiz.org/wsdl"> + <return>10</return> + </ns1:sumResponse> + </soap:Body> +</soap:Envelope> +---- + + +=== multiply(int, int) + +Request SOAP message: + + +[source,xml] +---- +<?xml version="1.0" encoding="UTF-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Body> + <ns1:multiply xmlns:ns1="http://superbiz.org/wsdl"> + <arg0>3</arg0> + <arg1>4</arg1> + </ns1:multiply> + </soap:Body> +</soap:Envelope> +---- + + +Response SOAP message: + + +[source,xml] +---- +<?xml version="1.0" encoding="UTF-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> + <soap:Body> + <ns1:multiplyResponse xmlns:ns1="http://superbiz.org/wsdl"> + <return>12</return> + </ns1:multiplyResponse> + </soap:Body> +</soap:Envelope> +---- + + +== Inside the jar + +With so much going on it can make things look more complex than they are. It can be hard to believe that so much can happen with such little code. That's the benefit of having an app server. + +If we look at the jar built by maven, we'll see the application itself is quite small: + + $ jar tvf target/simple-webservice-1.1.0-SNAPSHOT.jar + 0 Sat Feb 18 19:17:06 PST 2012 META-INF/ + 127 Sat Feb 18 19:17:04 PST 2012 META-INF/MANIFEST.MF + 0 Sat Feb 18 19:17:02 PST 2012 org/ + 0 Sat Feb 18 19:17:02 PST 2012 org/superbiz/ + 0 Sat Feb 18 19:17:02 PST 2012 org/superbiz/calculator/ + 0 Sat Feb 18 19:17:02 PST 2012 org/superbiz/calculator/ws/ + 855 Sat Feb 18 19:17:02 PST 2012 org/superbiz/calculator/ws/Calculator.class + 288 Sat Feb 18 19:17:02 PST 2012 org/superbiz/calculator/ws/CalculatorWs.class + +This single jar could be deployed any any compliant Java EE implementation. In TomEE you'd simply place it in the `tomee.home/webapps/` directory. No war file necessary. If you did want to create a war, you'd simply place the jar in the `WEB-INF/lib/` directory of the war. + +The server already contains the right libraries to run the code, such as Apache CXF, so no need to include anything extra beyond your own application code. + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/spring-data-proxy-meta.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/spring-data-proxy-meta.adoc b/src/main/jbake/content/examples/spring-data-proxy-meta.adoc new file mode 100755 index 0000000..f71dfc8 --- /dev/null +++ b/src/main/jbake/content/examples/spring-data-proxy-meta.adoc @@ -0,0 +1,20 @@ += spring-data-proxy-meta +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example spring-data-proxy-meta can be browsed at https://github.com/apache/tomee/tree/master/examples/spring-data-proxy-meta + += Spring Data With Meta sample # + +This example simply simplifies the usage of spring-data sample +providing a meta annotation @SpringRepository to do all the dynamic procy EJB job. + +It replaces @Proxy and @Stateless annotations. + +Isn't it more comfortable? + +To do it we defined a meta annotation "Metatype" and used it. + +The proxy implementation is the same than for spring-data sample. http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/spring-data-proxy.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/spring-data-proxy.adoc b/src/main/jbake/content/examples/spring-data-proxy.adoc new file mode 100755 index 0000000..59437f7 --- /dev/null +++ b/src/main/jbake/content/examples/spring-data-proxy.adoc @@ -0,0 +1,22 @@ += spring-data-proxy +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example spring-data-proxy can be browsed at https://github.com/apache/tomee/tree/master/examples/spring-data-proxy + += Spring Data sample # + +This example uses OpenEJB hooks to replace an EJB implementation by a proxy +to uses Spring Data in your preferred container. + +It is pretty simple: simply provide to OpenEJB an InvocationHandler using delegating to spring data +and that's it! + +It is what is done in org.superbiz.dynamic.SpringDataProxy. + +It contains a little trick: even if it is not annotated "implementingInterfaceClass" attribute +is injected by OpenEJB to get the interface. + +Then we simply create the Spring Data repository and delegate to it. http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/struts.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/struts.adoc b/src/main/jbake/content/examples/struts.adoc new file mode 100755 index 0000000..4de6de7 --- /dev/null +++ b/src/main/jbake/content/examples/struts.adoc @@ -0,0 +1,439 @@ += Struts +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example struts can be browsed at https://github.com/apache/tomee/tree/master/examples/struts + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== AddUser + + +[source,java] +---- +package org.superbiz.struts; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + + +public class AddUser { + + private int id; + private String firstName; + private String lastName; + private String errorMessage; + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String execute() { + + try { + UserService service = null; + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, + "org.apache.openejb.core.LocalInitialContextFactory"); + Context ctx = new InitialContext(props); + service = (UserService) ctx.lookup("UserServiceImplLocal"); + service.add(new User(id, firstName, lastName)); + } catch (Exception e) { + this.errorMessage = e.getMessage(); + return "failure"; + } + + return "success"; + } +} +---- + + +== AddUserForm + + +[source,java] +---- +package org.superbiz.struts; + +import com.opensymphony.xwork2.ActionSupport; + + +public class AddUserForm extends ActionSupport { +} +---- + + +== FindUser + + +[source,java] +---- +package org.superbiz.struts; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + +public class FindUser { + + private int id; + private String errorMessage; + private User user; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String execute() { + + try { + UserService service = null; + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, + "org.apache.openejb.core.LocalInitialContextFactory"); + Context ctx = new InitialContext(props); + service = (UserService) ctx.lookup("UserServiceImplLocal"); + this.user = service.find(id); + } catch (Exception e) { + this.errorMessage = e.getMessage(); + return "failure"; + } + + return "success"; + } +} +---- + + +== FindUserForm + + +[source,java] +---- +package org.superbiz.struts; + +import com.opensymphony.xwork2.ActionSupport; + + +public class FindUserForm extends ActionSupport { +} +---- + + +== ListAllUsers + + +[source,java] +---- +package org.superbiz.struts; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.List; +import java.util.Properties; + +public class ListAllUsers { + + private int id; + private String errorMessage; + private List<User> users; + + public List<User> getUsers() { + return users; + } + + public void setUsers(List<User> users) { + this.users = users; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String execute() { + + try { + UserService service = null; + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, + "org.apache.openejb.core.LocalInitialContextFactory"); + Context ctx = new InitialContext(props); + service = (UserService) ctx.lookup("UserServiceImplLocal"); + this.users = service.findAll(); + } catch (Exception e) { + this.errorMessage = e.getMessage(); + return "failure"; + } + + return "success"; + } +} +---- + + +== User + + +[source,java] +---- +package org.superbiz.struts; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +@Entity +@Table(name = "USER") +public class User implements Serializable { + private long id; + private String firstName; + private String lastName; + + public User(long id, String firstName, String lastName) { + super(); + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public User() { + } + + @Id + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} +---- + + +== UserService + + +[source,java] +---- +package org.superbiz.struts; + +import java.util.List; + +public interface UserService { + public void add(User user); + + public User find(int id); + + public List<User> findAll(); +} +---- + + +== UserServiceImpl + + +[source,java] +---- +package org.superbiz.struts; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Stateless +public class UserServiceImpl implements UserService { + + @PersistenceContext(unitName = "user") + private EntityManager manager; + + public void add(User user) { + manager.persist(user); + } + + public User find(int id) { + return manager.find(User.class, id); + } + + public List<User> findAll() { + return manager.createQuery("select u from User u").getResultList(); + } +} +---- + + +== persistence.xml + + +[source,xml] +---- +</persistence-unit> + + --> +</persistence> + +## struts.xml + +<struts> + <constant name="struts.devMode" value="true"></constant> + <package name="default" namespace="/" extends="struts-default"> + <action name="addUserForm" class="org.superbiz.struts.AddUserForm"> + <result>/addUserForm.jsp</result> + </action> + <action name="addUser" class="org.superbiz.struts.AddUser"> + <result name="success">/addedUser.jsp</result> + <result name='failure'>/addUserForm.jsp</result> + </action> + <action name="findUserForm" class="org.superbiz.struts.FindUserForm"> + <result>/findUserForm.jsp</result> + </action> + <action name="findUser" class="org.superbiz.struts.FindUser"> + <result name='success'>/displayUser.jsp</result> + <result name='failure'>/findUserForm.jsp</result> + </action> + <action name="listAllUsers" class="org.superbiz.struts.ListAllUsers"> + <result>/displayUsers.jsp</result> + </action> + + </package> +</struts> + +## decorators.xml + +<decorators defaultdir="/decorators"> + <decorator name="main" page="layout.jsp"> + <pattern>/*</pattern> + </decorator> +</decorators> + +## web.xml + +<web-app 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/web-app_2_5.xsd" + version="2.5"> + <display-name>Learn EJB3 and Struts2</display-name> + <filter> + <filter-name>struts2</filter-name> + <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> + <init-param> + <param-name>actionPackages</param-name> + <param-value>com.lq</param-value> + </init-param> + </filter> + <filter> + <filter-name>struts-cleanup</filter-name> + <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> + </filter> + <filter> + <filter-name>sitemesh</filter-name> + <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> + </filter> + <filter-mapping> + <filter-name>struts-cleanup</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <filter-mapping> + <filter-name>sitemesh</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <filter-mapping> + <filter-name>struts2</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> + <jsp-config> + <jsp-property-group> + <description>JSP configuration of all the JSP's</description> + <url-pattern>*.jsp</url-pattern> + <include-prelude>/prelude.jspf</include-prelude> + </jsp-property-group> + </jsp-config> +</web-app> + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/telephone-stateful.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/telephone-stateful.adoc b/src/main/jbake/content/examples/telephone-stateful.adoc new file mode 100755 index 0000000..ac38237 --- /dev/null +++ b/src/main/jbake/content/examples/telephone-stateful.adoc @@ -0,0 +1,248 @@ += Telephone Stateful +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example telephone-stateful can be browsed at https://github.com/apache/tomee/tree/master/examples/telephone-stateful + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +This example shows how to use OpenEJB's remoting capabilities in an embedded scenario. + +The basic recipe is the same for a standard embedded scenario but with these added +ingreditents: + + * `openejb.embedded.remotable` property + * `openejb-ejbd` jar + +While creating the InitialContext, pass in the openejb.embedded.remotable property with +the value of "true". When this is seen by the LocalInitialContextFactory, it will boot up +the Server ServiceManager in the VM which will in turn look for ServerServices in the +classpath. + +Provided you have the openejb-ejbd jar in your classpath along with it's dependencies +(openejb-server, openejb-client, openejb-core), then those services will be brought online +and remote clients will be able to connect into your vm and invoke beans. + +If you want to add more ServerServices such as the http version of the ejbd protocol you'd +simply add the openejb-httpejbd jar to your classpath. A number of ServerServices are +available currently: + + * openejb-ejbd + * openejb-http + * openejb-telnet + * openejb-derbynet + * openejb-hsql + * openejb-activemq + + +== Telephone + + +[source,java] +---- +package org.superbiz.telephone; + +public interface Telephone { + + void speak(String words); + + String listen(); +} +---- + + +== TelephoneBean + + +[source,java] +---- +package org.superbiz.telephone; + +import javax.ejb.Remote; +import javax.ejb.Stateful; +import java.util.ArrayList; +import java.util.List; + +@Remote +@Stateful +public class TelephoneBean implements Telephone { + + private static final String[] answers = { + "How nice.", + "Oh, of course.", + "Interesting.", + "Really?", + "No.", + "Definitely.", + "I wondered about that.", + "Good idea.", + "You don't say!", + }; + + private List<String> conversation = new ArrayList<String>(); + + public void speak(String words) { + conversation.add(words); + } + + public String listen() { + if (conversation.size() == 0) { + return "Nothing has been said"; + } + + String lastThingSaid = conversation.get(conversation.size() - 1); + return answers[Math.abs(lastThingSaid.hashCode()) % answers.length]; + } +} +---- + + +== TelephoneTest + + +[source,java] +---- +package org.superbiz.telephone; + +import junit.framework.TestCase; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Properties; + +/** + * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $ + */ +public class TelephoneTest extends TestCase { + + protected void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + properties.setProperty("openejb.embedded.remotable", "true"); + // Uncomment these properties to change the defaults + //properties.setProperty("ejbd.port", "4202"); + //properties.setProperty("ejbd.bind", "localhost"); + //properties.setProperty("ejbd.threads", "200"); + //properties.setProperty("ejbd.disabled", "false"); + //properties.setProperty("ejbd.only_from", "127.0.0.1,192.168.1.1"); + + new InitialContext(properties); + } + + /** + * Lookup the Telephone bean via its remote interface but using the LocalInitialContextFactory + * + * @throws Exception + */ + public void testTalkOverLocalNetwork() throws Exception { + + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + InitialContext localContext = new InitialContext(properties); + + Telephone telephone = (Telephone) localContext.lookup("TelephoneBeanRemote"); + + telephone.speak("Did you know I am talking directly through the embedded container?"); + + assertEquals("Interesting.", telephone.listen()); + + + telephone.speak("Yep, I'm using the bean's remote interface but since the ejb container is embedded " + + "in the same vm I'm just using the LocalInitialContextFactory."); + + assertEquals("Really?", telephone.listen()); + + + telephone.speak("Right, you really only have to use the RemoteInitialContextFactory if you're in a different vm."); + + assertEquals("Oh, of course.", telephone.listen()); + } + + /** + * Lookup the Telephone bean via its remote interface using the RemoteInitialContextFactory + * + * @throws Exception + */ + public void testTalkOverRemoteNetwork() throws Exception { + Properties properties = new Properties(); + properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); + properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201"); + InitialContext remoteContext = new InitialContext(properties); + + Telephone telephone = (Telephone) remoteContext.lookup("TelephoneBeanRemote"); + + telephone.speak("Is this a local call?"); + + assertEquals("No.", telephone.listen()); + + + telephone.speak("This would be a lot cooler if I was connecting from another VM then, huh?"); + + assertEquals("I wondered about that.", telephone.listen()); + + + telephone.speak("I suppose I should hangup and call back over the LocalInitialContextFactory."); + + assertEquals("Good idea.", telephone.listen()); + + + telephone.speak("I'll remember this though in case I ever have to call you accross a network."); + + assertEquals("Definitely.", telephone.listen()); + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.telephone.TelephoneTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/telephone-stateful +INFO - openejb.base = /Users/dblevins/examples/telephone-stateful +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/telephone-stateful/target/classes +INFO - Beginning load: /Users/dblevins/examples/telephone-stateful/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/telephone-stateful/classpath.ear +INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) +INFO - Auto-creating a container for bean TelephoneBean: Container(type=STATEFUL, id=Default Stateful Container) +INFO - Enterprise application "/Users/dblevins/examples/telephone-stateful/classpath.ear" loaded. +INFO - Assembling app: /Users/dblevins/examples/telephone-stateful/classpath.ear +INFO - Jndi(name=TelephoneBeanRemote) --> Ejb(deployment-id=TelephoneBean) +INFO - Jndi(name=global/classpath.ear/telephone-stateful/TelephoneBean!org.superbiz.telephone.Telephone) --> Ejb(deployment-id=TelephoneBean) +INFO - Jndi(name=global/classpath.ear/telephone-stateful/TelephoneBean) --> Ejb(deployment-id=TelephoneBean) +INFO - Created Ejb(deployment-id=TelephoneBean, ejb-name=TelephoneBean, container=Default Stateful Container) +INFO - Started Ejb(deployment-id=TelephoneBean, ejb-name=TelephoneBean, container=Default Stateful Container) +INFO - Deployed Application(path=/Users/dblevins/examples/telephone-stateful/classpath.ear) +INFO - Initializing network services +INFO - Creating ServerService(id=admin) +INFO - Creating ServerService(id=ejbd) +INFO - Creating ServerService(id=ejbds) +INFO - Initializing network services + ** Starting Services ** + NAME IP PORT + admin thread 127.0.0.1 4200 + ejbd 127.0.0.1 4201 + ejbd 127.0.0.1 4203 +------- +Ready! +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.448 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 +---- + + http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/972cc356/src/main/jbake/content/examples/testcase-injection.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/testcase-injection.adoc b/src/main/jbake/content/examples/testcase-injection.adoc new file mode 100755 index 0000000..bc6e704 --- /dev/null +++ b/src/main/jbake/content/examples/testcase-injection.adoc @@ -0,0 +1,240 @@ += Testcase Injection +:jbake-date: 2016-09-06 +:jbake-type: page +:jbake-tomeepdf: +:jbake-status: published + +Example testcase-injection can be browsed at https://github.com/apache/tomee/tree/master/examples/testcase-injection + + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +== Movie + + +[source,java] +---- +package org.superbiz.testinjection; + +import javax.persistence.Entity; + +@Entity +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.testinjection; + +import javax.ejb.Stateful; +import javax.ejb.TransactionAttribute; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.Query; +import java.util.List; + +import static javax.ejb.TransactionAttributeType.MANDATORY; + +//START SNIPPET: code +@Stateful +@TransactionAttribute(MANDATORY) +public class Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) + 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(); + } +} +---- + + +== persistence.xml + + +[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.testinjection.Movie</class> + + <properties> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> + </properties> + </persistence-unit> +</persistence> +---- + + +== MoviesTest + + +[source,java] +---- +package org.superbiz.testinjection; + +import junit.framework.TestCase; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.UserTransaction; +import java.util.List; +import java.util.Properties; + +//START SNIPPET: code +public class MoviesTest extends TestCase { + + @EJB + private Movies movies; + + @Resource + private UserTransaction userTransaction; + + @PersistenceContext + private EntityManager entityManager; + + public void setUp() 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"); + + EJBContainer.createEJBContainer(p).getContext().bind("inject", this); + } + + public void test() throws Exception { + + userTransaction.begin(); + + try { + entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + entityManager.persist(new Movie("Joel Coen", "Fargo", 1996)); + entityManager.persist(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()); + } finally { + userTransaction.commit(); + } + + } +} +---- + + += Running + + + +[source] +---- +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running org.superbiz.testinjection.MoviesTest +Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 +http://tomee.apache.org/ +INFO - openejb.home = /Users/dblevins/examples/testcase-injection +INFO - openejb.base = /Users/dblevins/examples/testcase-injection +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/testcase-injection/target/classes +INFO - Beginning load: /Users/dblevins/examples/testcase-injection/target/classes +INFO - Configuring enterprise application: /Users/dblevins/examples/testcase-injection +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 - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) +INFO - Auto-creating a container for bean org.superbiz.testinjection.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/testcase-injection" loaded. +INFO - Assembling app: /Users/dblevins/examples/testcase-injection +INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 408ms +INFO - Jndi(name="java:global/testcase-injection/Movies!org.superbiz.testinjection.Movies") +INFO - Jndi(name="java:global/testcase-injection/Movies") +INFO - Jndi(name="java:global/EjbModule1583515396/org.superbiz.testinjection.MoviesTest!org.superbiz.testinjection.MoviesTest") +INFO - Jndi(name="java:global/EjbModule1583515396/org.superbiz.testinjection.MoviesTest") +INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) +INFO - Created Ejb(deployment-id=org.superbiz.testinjection.MoviesTest, ejb-name=org.superbiz.testinjection.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.testinjection.MoviesTest, ejb-name=org.superbiz.testinjection.MoviesTest, container=Default Managed Container) +INFO - Deployed Application(path=/Users/dblevins/examples/testcase-injection) +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.24 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +---- + +