You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/11/29 19:41:26 UTC
svn commit: r1040222 - in
/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs: ./
src/main/java/org/superbiz/ejblookup/ src/main/java/org/superbiz/injection/
src/test/java/org/superbiz/ejblookup/ src/test/java/org/superbiz/injection/
Author: dblevins
Date: Mon Nov 29 18:41:26 2010
New Revision: 1040222
URL: http://svn.apache.org/viewvc?rev=1040222&view=rev
Log:
OPENEJB-1406: Example: Lookup of EJBs
trimmed down version of the injection-of-ejbs example
Added:
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/
- copied from r1040199, openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/build.xml
- copied unchanged from r1040203, openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/build.xml
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/pom.xml
- copied, changed from r1040203, openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/pom.xml
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java (with props)
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java (with props)
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java (with props)
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java (with props)
Removed:
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/injection/
openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/injection/
Copied: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/pom.xml (from r1040203, openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/pom.xml)
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/pom.xml?p2=openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/pom.xml&p1=openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/pom.xml&r1=1040203&r2=1040222&rev=1040222&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/injection-of-ejbs/pom.xml (original)
+++ openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/pom.xml Mon Nov 29 18:41:26 2010
@@ -22,10 +22,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.superbiz</groupId>
- <artifactId>injection-of-ejbs</artifactId>
+ <artifactId>lookup-of-ejbs</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
- <name>OpenEJB :: Examples :: @EJB Injection</name>
+ <name>OpenEJB :: Examples :: @EJB Lookup</name>
<properties>
<!--
- http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding
Added: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java?rev=1040222&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java (added)
+++ openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java Mon Nov 29 18:41:26 2010
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.ejblookup;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+//START SNIPPET: code
+@Stateless
+@EJB(beanInterface = Friend.class, beanName = "RedBean", name = "myFriend")
+public class BlueBean implements Friend {
+
+ public String sayHello() {
+ return "Blue says, Hello!";
+ }
+
+ public String helloToFriend() {
+ try {
+ Friend friend = (Friend) new InitialContext().lookup("java:comp/env/myFriend");
+ return "My friend " + friend.sayHello();
+ } catch (NamingException e) {
+ throw new EJBException(e);
+ }
+ }
+}
+//END SNIPPET: code
Propchange: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/BlueBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java?rev=1040222&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java (added)
+++ openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java Mon Nov 29 18:41:26 2010
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.ejblookup;
+
+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
+ * if the bean does not implement any other interfaces
+ */
+//START SNIPPET: code
+@Local
+public interface Friend {
+
+ public String sayHello();
+ public String helloToFriend();
+
+}
+//END SNIPPET: code
Propchange: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/Friend.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java?rev=1040222&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java (added)
+++ openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java Mon Nov 29 18:41:26 2010
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.ejblookup;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+//START SNIPPET: code
+@Stateless
+@EJB(beanInterface = Friend.class, beanName = "BlueBean", name = "myFriend")
+public class RedBean implements Friend {
+
+ public String sayHello() {
+ return "Red says, Hello!";
+ }
+
+ public String helloToFriend() {
+ try {
+ Friend friend = (Friend) new InitialContext().lookup("java:comp/env/myFriend");
+ return "My friend " + friend.sayHello();
+ } catch (NamingException e) {
+ throw new EJBException(e);
+ }
+ }
+}
+//END SNIPPET: code
\ No newline at end of file
Propchange: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/main/java/org/superbiz/ejblookup/RedBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java?rev=1040222&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java (added)
+++ openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java Mon Nov 29 18:41:26 2010
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.ejblookup;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+//START SNIPPET: code
+public class EjbDependencyTest extends TestCase {
+
+ private InitialContext initialContext;
+
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+ initialContext = new InitialContext(properties);
+ }
+
+ public void testRed() throws Exception {
+
+ Friend red = (Friend) initialContext.lookup("RedBeanLocal");
+
+ assertNotNull(red);
+ assertEquals("Red says, Hello!", red.sayHello());
+ assertEquals("My friend Blue says, Hello!", red.helloToFriend());
+
+ }
+
+ public void testBlue() throws Exception {
+
+ Friend blue = (Friend) initialContext.lookup("BlueBeanLocal");
+
+ assertNotNull(blue);
+ assertEquals("Blue says, Hello!", blue.sayHello());
+ assertEquals("My friend Red says, Hello!", blue.helloToFriend());
+
+ }
+
+}
+//END SNIPPET: code
Propchange: openejb/branches/openejb-3.1.x/examples/lookup-of-ejbs/src/test/java/org/superbiz/ejblookup/EjbDependencyTest.java
------------------------------------------------------------------------------
svn:eol-style = native