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 2011/10/29 06:54:42 UTC
svn commit: r1190757 [3/15] - in /openejb/trunk/openejb/examples:
access-timeout-meta/src/main/java/org/superbiz/accesstimeout/
alternate-descriptors/ application-composer/ applicationexception/
applicationexception/src/test/java/org/superbiz/appexcept...
Added: openejb/trunk/openejb/examples/component-interfaces/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/component-interfaces/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/component-interfaces/README.md (added)
+++ openejb/trunk/openejb/examples/component-interfaces/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,595 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: EJB 2.1 Component Interfaces 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ component-interfaces ---
+[INFO] Deleting /Users/dblevins/examples/component-interfaces/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ component-interfaces ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/component-interfaces/src/main/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ component-interfaces ---
+[INFO] Compiling 7 source files to /Users/dblevins/examples/component-interfaces/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ component-interfaces ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/component-interfaces/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ component-interfaces ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/component-interfaces/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.6:test (default-test) @ component-interfaces ---
+[INFO] Surefire report directory: /Users/dblevins/examples/component-interfaces/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.FriendlyPersonTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/component-interfaces
+INFO - openejb.base = /Users/dblevins/examples/component-interfaces
+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/component-interfaces/target/classes
+INFO - Beginning load: /Users/dblevins/examples/component-interfaces/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/component-interfaces
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+INFO - Auto-creating a container for bean FriendlyPerson: 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.FriendlyPersonTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/component-interfaces" loaded.
+INFO - Assembling app: /Users/dblevins/examples/component-interfaces
+INFO - Jndi(name="java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonLocal")
+INFO - Jndi(name="java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonRemote")
+INFO - Jndi(name="java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonEjbLocalHome")
+INFO - Jndi(name="java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonEjbHome")
+INFO - Jndi(name="java:global/component-interfaces/FriendlyPerson")
+INFO - Jndi(name="java:global/EjbModule1952576819/org.superbiz.FriendlyPersonTest!org.superbiz.FriendlyPersonTest")
+INFO - Jndi(name="java:global/EjbModule1952576819/org.superbiz.FriendlyPersonTest")
+INFO - Created Ejb(deployment-id=FriendlyPerson, ejb-name=FriendlyPerson, container=Default Stateful Container)
+INFO - Created Ejb(deployment-id=org.superbiz.FriendlyPersonTest, ejb-name=org.superbiz.FriendlyPersonTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=FriendlyPerson, ejb-name=FriendlyPerson, container=Default Stateful Container)
+INFO - Started Ejb(deployment-id=org.superbiz.FriendlyPersonTest, ejb-name=org.superbiz.FriendlyPersonTest, container=Default Managed Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/component-interfaces)
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.324 sec
+
+Results :
+
+Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ component-interfaces ---
+[INFO] Building jar: /Users/dblevins/examples/component-interfaces/target/component-interfaces-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ component-interfaces ---
+[INFO] Installing /Users/dblevins/examples/component-interfaces/target/component-interfaces-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/component-interfaces/1.0/component-interfaces-1.0.jar
+[INFO] Installing /Users/dblevins/examples/component-interfaces/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/component-interfaces/1.0/component-interfaces-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.240s
+[INFO] Finished at: Fri Oct 28 16:59:20 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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;
+
+ import javax.ejb.Init;
+ import javax.ejb.Local;
+ import javax.ejb.LocalHome;
+ import javax.ejb.Remote;
+ import javax.ejb.RemoteHome;
+ import javax.ejb.Remove;
+ import javax.ejb.Stateful;
+ import java.text.MessageFormat;
+ import java.util.HashMap;
+ import java.util.Locale;
+ import java.util.Properties;
+
+ /**
+ * This is an EJB 3 style pojo stateful session bean
+ * it does not need to implement javax.ejb.SessionBean
+ *
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+ //START SNIPPET: code
+
+ // EJB 3.0 Style business interfaces
+ // Each of these interfaces are already annotated in the classes
+ // themselves with @Remote and @Local, so annotating them here
+ // in the bean class again is not really required.
+ @Remote({FriendlyPersonRemote.class})
+ @Local({FriendlyPersonLocal.class})
+
+ // EJB 2.1 Style component interfaces
+ // These interfaces, however, must be annotated here in the bean class.
+ // Use of @RemoteHome in the FriendlyPersonEjbHome class itself is not allowed.
+ // Use of @LocalHome in the FriendlyPersonEjbLocalHome class itself is also not allowed.
+ @RemoteHome(FriendlyPersonEjbHome.class)
+ @LocalHome(FriendlyPersonEjbLocalHome.class)
+
+ @Stateful
+ public class FriendlyPerson implements FriendlyPersonLocal, FriendlyPersonRemote {
+
+ private final HashMap<String, MessageFormat> greetings;
+ private final Properties languagePreferences;
+
+ private String defaultLanguage;
+
+ public FriendlyPerson() {
+ greetings = new HashMap();
+ languagePreferences = new Properties();
+ defaultLanguage = Locale.getDefault().getLanguage();
+
+ addGreeting("en", "Hello {0}!");
+ addGreeting("es", "Hola {0}!");
+ addGreeting("fr", "Bonjour {0}!");
+ addGreeting("pl", "Witaj {0}!");
+ }
+
+ /**
+ * This method corresponds to the FriendlyPersonEjbHome.create() method
+ * and the FriendlyPersonEjbLocalHome.create()
+ * <p/>
+ * If you do not have an EJBHome or EJBLocalHome interface, this method
+ * can be deleted.
+ */
+ @Init
+ public void create() {
+ }
+
+ /**
+ * This method corresponds to the following methods:
+ * - EJBObject.remove()
+ * - EJBHome.remove(ejbObject)
+ * - EJBLocalObject.remove()
+ * - EJBLocalHome.remove(ejbObject)
+ * <p/>
+ * If you do not have an EJBHome or EJBLocalHome interface, this method
+ * can be deleted.
+ */
+ @Remove
+ public void remove() {
+ }
+
+ public String greet(String friend) {
+ String language = languagePreferences.getProperty(friend, defaultLanguage);
+ return greet(language, friend);
+ }
+
+ public String greet(String language, String friend) {
+ MessageFormat greeting = greetings.get(language);
+ if (greeting == null) {
+ Locale locale = new Locale(language);
+ return "Sorry, I don't speak " + locale.getDisplayLanguage() + ".";
+ }
+
+ return greeting.format(new Object[]{friend});
+ }
+
+ public void addGreeting(String language, String message) {
+ greetings.put(language, new MessageFormat(message));
+ }
+
+ public void setLanguagePreferences(String friend, String language) {
+ languagePreferences.put(friend, language);
+ }
+
+ public String getDefaultLanguage() {
+ return defaultLanguage;
+ }
+
+ public void setDefaultLanguage(String defaultLanguage) {
+ this.defaultLanguage = defaultLanguage;
+ }
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ //START SNIPPET: code
+
+ import javax.ejb.CreateException;
+ import javax.ejb.EJBHome;
+ import java.rmi.RemoteException;
+
+ public interface FriendlyPersonEjbHome extends EJBHome {
+ FriendlyPersonEjbObject create() throws CreateException, RemoteException;
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ //START SNIPPET: code
+
+ import javax.ejb.CreateException;
+ import javax.ejb.EJBLocalHome;
+ import java.rmi.RemoteException;
+
+ public interface FriendlyPersonEjbLocalHome extends EJBLocalHome {
+ FriendlyPersonEjbLocalObject create() throws CreateException, RemoteException;
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ import javax.ejb.EJBLocalObject;
+
+ public interface FriendlyPersonEjbLocalObject extends EJBLocalObject {
+ String greet(String friend);
+
+ String greet(String language, String friend);
+
+ void addGreeting(String language, String message);
+
+ void setLanguagePreferences(String friend, String language);
+
+ String getDefaultLanguage();
+
+ void setDefaultLanguage(String defaultLanguage);
+
+ }
+ /**
+ * 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;
+
+ //START SNIPPET: code
+
+ import javax.ejb.EJBObject;
+ import java.rmi.RemoteException;
+
+ public interface FriendlyPersonEjbObject extends EJBObject {
+ String greet(String friend) throws RemoteException;
+
+ String greet(String language, String friend) throws RemoteException;
+
+ void addGreeting(String language, String message) throws RemoteException;
+
+ void setLanguagePreferences(String friend, String language) throws RemoteException;
+
+ String getDefaultLanguage() throws RemoteException;
+
+ void setDefaultLanguage(String defaultLanguage) throws RemoteException;
+
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ //START SNIPPET: code
+
+ import javax.ejb.Local;
+
+ @Local
+ public interface FriendlyPersonLocal {
+ String greet(String friend);
+
+ String greet(String language, String friend);
+
+ void addGreeting(String language, String message);
+
+ void setLanguagePreferences(String friend, String language);
+
+ String getDefaultLanguage();
+
+ void setDefaultLanguage(String defaultLanguage);
+
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ import javax.ejb.Remote;
+
+ //START SNIPPET: code
+ @Remote
+ public interface FriendlyPersonRemote {
+ String greet(String friend);
+
+ String greet(String language, String friend);
+
+ void addGreeting(String language, String message);
+
+ void setLanguagePreferences(String friend, String language);
+
+ String getDefaultLanguage();
+
+ void setDefaultLanguage(String defaultLanguage);
+
+ }
+ //END SNIPPET: code
+ /**
+ * 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;
+
+ import junit.framework.TestCase;
+
+ import javax.ejb.embeddable.EJBContainer;
+ import javax.naming.Context;
+ import java.util.Locale;
+
+ /**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $
+ */
+ public class FriendlyPersonTest extends TestCase {
+
+ private Context context;
+
+ protected void setUp() throws Exception {
+ context = EJBContainer.createEJBContainer().getContext();
+ }
+
+ /**
+ * Here we lookup and test the FriendlyPerson bean via its EJB 2.1 EJBHome and EJBObject interfaces
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: remotehome
+ public void testEjbHomeAndEjbObject() throws Exception {
+ Object object = context.lookup("java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonEjbHome");
+ FriendlyPersonEjbHome home = (FriendlyPersonEjbHome) object;
+ FriendlyPersonEjbObject friendlyPerson = home.create();
+
+ friendlyPerson.setDefaultLanguage("en");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
+
+ friendlyPerson.setLanguagePreferences("Amelia", "es");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
+
+ // Amelia took some French, let's see if she remembers
+ assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr", "Amelia"));
+
+ // Dave should take some Polish and if he had, he could say Hi in Polish
+ assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
+
+ // Let's see if I speak Portuguese
+ assertEquals("Sorry, I don't speak " + new Locale("pt").getDisplayLanguage() + ".", friendlyPerson.greet("pt", "David"));
+
+ // Ok, well I've been meaning to learn, so...
+ friendlyPerson.addGreeting("pt", "Ola {0}!");
+
+ assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
+ }
+ //END SNIPPET: remotehome
+
+
+ /**
+ * Here we lookup and test the FriendlyPerson bean via its EJB 2.1 EJBLocalHome and EJBLocalObject interfaces
+ *
+ * @throws Exception
+ */
+ public void testEjbLocalHomeAndEjbLocalObject() throws Exception {
+ Object object = context.lookup("java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonEjbLocalHome");
+ FriendlyPersonEjbLocalHome home = (FriendlyPersonEjbLocalHome) object;
+ FriendlyPersonEjbLocalObject friendlyPerson = home.create();
+
+ friendlyPerson.setDefaultLanguage("en");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
+
+ friendlyPerson.setLanguagePreferences("Amelia", "es");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
+
+ // Amelia took some French, let's see if she remembers
+ assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr", "Amelia"));
+
+ // Dave should take some Polish and if he had, he could say Hi in Polish
+ assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
+
+ // Let's see if I speak Portuguese
+ assertEquals("Sorry, I don't speak " + new Locale("pt").getDisplayLanguage() + ".", friendlyPerson.greet("pt", "David"));
+
+ // Ok, well I've been meaning to learn, so...
+ friendlyPerson.addGreeting("pt", "Ola {0}!");
+
+ assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
+ }
+
+ /**
+ * Here we lookup and test the FriendlyPerson bean via its EJB 3.0 business remote interface
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: remote
+ public void testBusinessRemote() throws Exception {
+ Object object = context.lookup("java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonRemote");
+
+ FriendlyPersonRemote friendlyPerson = (FriendlyPersonRemote) object;
+
+ friendlyPerson.setDefaultLanguage("en");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
+
+ friendlyPerson.setLanguagePreferences("Amelia", "es");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
+
+ // Amelia took some French, let's see if she remembers
+ assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr", "Amelia"));
+
+ // Dave should take some Polish and if he had, he could say Hi in Polish
+ assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
+
+ // Let's see if I speak Portuguese
+ assertEquals("Sorry, I don't speak " + new Locale("pt").getDisplayLanguage() + ".", friendlyPerson.greet("pt", "David"));
+
+ // Ok, well I've been meaning to learn, so...
+ friendlyPerson.addGreeting("pt", "Ola {0}!");
+
+ assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
+ }
+ //START SNIPPET: remote
+
+ /**
+ * Here we lookup and test the FriendlyPerson bean via its EJB 3.0 business local interface
+ *
+ * @throws Exception
+ */
+ public void testBusinessLocal() throws Exception {
+ Object object = context.lookup("java:global/component-interfaces/FriendlyPerson!org.superbiz.FriendlyPersonLocal");
+
+ FriendlyPersonLocal friendlyPerson = (FriendlyPersonLocal) object;
+
+ friendlyPerson.setDefaultLanguage("en");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hello Amelia!", friendlyPerson.greet("Amelia"));
+
+ friendlyPerson.setLanguagePreferences("Amelia", "es");
+
+ assertEquals("Hello David!", friendlyPerson.greet("David"));
+ assertEquals("Hola Amelia!", friendlyPerson.greet("Amelia"));
+
+ // Amelia took some French, let's see if she remembers
+ assertEquals("Bonjour Amelia!", friendlyPerson.greet("fr", "Amelia"));
+
+ // Dave should take some Polish and if he had, he could say Hi in Polish
+ assertEquals("Witaj Dave!", friendlyPerson.greet("pl", "Dave"));
+
+ // Let's see if I speak Portuguese
+ assertEquals("Sorry, I don't speak " + new Locale("pt").getDisplayLanguage() + ".", friendlyPerson.greet("pt", "David"));
+
+ // Ok, well I've been meaning to learn, so...
+ friendlyPerson.addGreeting("pt", "Ola {0}!");
+
+ assertEquals("Ola David!", friendlyPerson.greet("pt", "David"));
+ }
+
+
+ }
Added: openejb/trunk/openejb/examples/custom-injection/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/custom-injection/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/custom-injection/README.md (added)
+++ openejb/trunk/openejb/examples/custom-injection/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,324 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Expanded support for Env Entries 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ custom-injection ---
+[INFO] Deleting /Users/dblevins/examples/custom-injection/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ custom-injection ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ custom-injection ---
+[INFO] Compiling 4 source files to /Users/dblevins/examples/custom-injection/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ custom-injection ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/custom-injection/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ custom-injection ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/custom-injection/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ custom-injection ---
+[INFO] Surefire report directory: /Users/dblevins/examples/custom-injection/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.enventries.StratocasterTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/custom-injection
+INFO - openejb.base = /Users/dblevins/examples/custom-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 - Found EjbModule in classpath: /Users/dblevins/examples/custom-injection/target/classes
+INFO - Beginning load: /Users/dblevins/examples/custom-injection/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/custom-injection
+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 Stratocaster: 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.enventries.StratocasterTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/custom-injection" loaded.
+INFO - Assembling app: /Users/dblevins/examples/custom-injection
+INFO - Jndi(name="java:global/custom-injection/Stratocaster!org.superbiz.enventries.Stratocaster")
+INFO - Jndi(name="java:global/custom-injection/Stratocaster")
+INFO - Jndi(name="java:global/EjbModule1821050251/org.superbiz.enventries.StratocasterTest!org.superbiz.enventries.StratocasterTest")
+INFO - Jndi(name="java:global/EjbModule1821050251/org.superbiz.enventries.StratocasterTest")
+INFO - Created Ejb(deployment-id=Stratocaster, ejb-name=Stratocaster, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=org.superbiz.enventries.StratocasterTest, ejb-name=org.superbiz.enventries.StratocasterTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=Stratocaster, ejb-name=Stratocaster, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=org.superbiz.enventries.StratocasterTest, ejb-name=org.superbiz.enventries.StratocasterTest, container=Default Managed Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/custom-injection)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.109 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ custom-injection ---
+[INFO] Building jar: /Users/dblevins/examples/custom-injection/target/custom-injection-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ custom-injection ---
+[INFO] Installing /Users/dblevins/examples/custom-injection/target/custom-injection-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/custom-injection/1.0/custom-injection-1.0.jar
+[INFO] Installing /Users/dblevins/examples/custom-injection/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/custom-injection/1.0/custom-injection-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.030s
+[INFO] Finished at: Fri Oct 28 17:08:08 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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.enventries;
+
+
+ //START SNIPPET: code
+
+ import java.beans.PropertyEditorManager;
+
+ public enum Pickup {
+
+ HUMBUCKER,
+ SINGLE_COIL;
+
+ // Here's the little magic where we register the PickupEditor
+ // which knows how to create this object from a string.
+ // You can add any of your own Property Editors in the same way.
+ static {
+ PropertyEditorManager.registerEditor(Pickup.class, PickupEditor.class);
+ }
+ }
+ //END SNIPPET: code
+ /**
+ * 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.enventries;
+
+ /**
+ * With a java.beans.PropertyEditor, you can go way beyond the built-in
+ * types that OpenEJB supports and can extend dependency injection to
+ * just about anywhere.
+ * <p/>
+ * In the world of electric guitars, two types of pickups are used: humbucking, and single-coil.
+ * Guitarists often refer to their guitars as HSS, meaning a guitar with 1 humbucker and
+ * 2 single coil pickups, and so on. This little PropertyEditor supports that shorthand notation.
+ *
+ * @version $Revision$ $Date$
+ */
+ //START SNIPPET: code
+ public class PickupEditor extends java.beans.PropertyEditorSupport {
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ text = text.trim();
+
+ if (text.equalsIgnoreCase("H")) setValue(Pickup.HUMBUCKER);
+ else if (text.equalsIgnoreCase("S")) setValue(Pickup.SINGLE_COIL);
+ else throw new IllegalStateException("H and S are the only supported Pickup aliases");
+ }
+ }
+ //END SNIPPET: code
+ /**
+ * 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.enventries;
+
+ import javax.annotation.Resource;
+ import javax.ejb.Stateless;
+ import java.io.File;
+ import java.util.Date;
+ import java.util.List;
+ import java.util.Map;
+
+ /**
+ * In addition to the standard env-entry types (String, Integer, Long, Short, Byte, Boolean, Double, Float, Character)
+ * OpenEJB supports many other types.
+ */
+ //START SNIPPET: code
+ @Stateless
+ public class Stratocaster {
+
+
+ @Resource(name = "pickups")
+ private List<Pickup> pickups;
+
+ @Resource(name = "style")
+ private Style style;
+
+ @Resource(name = "dateCreated")
+ private Date dateCreated;
+
+ @Resource(name = "guitarStringGuages")
+ private Map<String, Float> guitarStringGuages;
+
+ @Resource(name = "certificateOfAuthenticity")
+ private File certificateOfAuthenticity;
+
+ public Date getDateCreated() {
+ return dateCreated;
+ }
+
+ /**
+ * Gets the guage of the electric guitar strings
+ * used in this guitar.
+ *
+ * @param string
+ * @return
+ */
+ public float getStringGuage(String string) {
+ return guitarStringGuages.get(string);
+ }
+
+ public List<Pickup> getPickups() {
+ return pickups;
+ }
+
+ public Style getStyle() {
+ return style;
+ }
+
+ public File getCertificateOfAuthenticity() {
+ return certificateOfAuthenticity;
+ }
+ }
+ //END SNIPPET: code
+ /**
+ * 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.enventries;
+
+ /**
+ * @version $Revision$ $Date$
+ */
+ //START SNIPPET: code
+ public enum Style {
+
+ STANDARD,
+ DELUX,
+ VINTAGE;
+
+ }
+ //END SNIPPET: code
+ /**
+ * 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.enventries;
+
+ import junit.framework.TestCase;
+
+ import javax.ejb.EJB;
+ import javax.ejb.embeddable.EJBContainer;
+ import java.io.File;
+ import java.text.DateFormat;
+ import java.util.Date;
+ import java.util.List;
+ import java.util.Locale;
+
+ import static java.util.Arrays.asList;
+
+ /**
+ * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $
+ */
+ //START SNIPPET: code
+ public class StratocasterTest extends TestCase {
+
+ @EJB
+ private Stratocaster strat;
+
+ public void test() throws Exception {
+ EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+ Date date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).parse("Mar 1, 1962");
+ assertEquals("Strat.getDateCreated()", date, strat.getDateCreated());
+
+ List<Pickup> pickups = asList(Pickup.SINGLE_COIL, Pickup.SINGLE_COIL, Pickup.SINGLE_COIL);
+ assertEquals("Strat.getPickups()", pickups, strat.getPickups());
+
+ assertEquals("Strat.getStyle()", Style.VINTAGE, strat.getStyle());
+
+ assertEquals("Strat.getStringGuage(\"E1\")", 0.052F, strat.getStringGuage("E1"));
+ assertEquals("Strat.getStringGuage(\"A\")", 0.042F, strat.getStringGuage("A"));
+ assertEquals("Strat.getStringGuage(\"D\")", 0.030F, strat.getStringGuage("D"));
+ assertEquals("Strat.getStringGuage(\"G\")", 0.017F, strat.getStringGuage("G"));
+ assertEquals("Strat.getStringGuage(\"B\")", 0.013F, strat.getStringGuage("B"));
+ assertEquals("Strat.getStringGuage(\"E\")", 0.010F, strat.getStringGuage("E"));
+
+ File file = new File("/tmp/strat-certificate.txt");
+ assertEquals("Strat.getCertificateOfAuthenticity()", file, strat.getCertificateOfAuthenticity());
+
+
+ }
+ }
+ //END SNIPPET: code
Added: openejb/trunk/openejb/examples/decorators/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/decorators/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/decorators/README.md (added)
+++ openejb/trunk/openejb/examples/decorators/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,496 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Decorators 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ decorators ---
+[INFO] Deleting /Users/dblevins/examples/decorators/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ decorators ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ decorators ---
+[INFO] Compiling 5 source files to /Users/dblevins/examples/decorators/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ decorators ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 0 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ decorators ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/decorators/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ decorators ---
+[INFO] Surefire report directory: /Users/dblevins/examples/decorators/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.cdi.decorators.CalculatorTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/decorators
+INFO - openejb.base = /Users/dblevins/examples/decorators
+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/decorators/target/classes
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/decorators/target/test-classes
+INFO - Beginning load: /Users/dblevins/examples/decorators/target/classes
+INFO - Beginning load: /Users/dblevins/examples/decorators/target/test-classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/decorators
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean decorators.Comp: Container(type=MANAGED, id=Default Managed Container)
+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 - Enterprise application "/Users/dblevins/examples/decorators" loaded.
+INFO - Assembling app: /Users/dblevins/examples/decorators
+INFO - Jndi(name="java:global/decorators/decorators.Comp!org.apache.openejb.BeanContext$Comp")
+INFO - Jndi(name="java:global/decorators/decorators.Comp")
+INFO - Jndi(name="java:global/decorators/CalculatorBean!org.superbiz.cdi.decorators.Calculator")
+INFO - Jndi(name="java:global/decorators/CalculatorBean")
+INFO - Jndi(name="java:global/decorators/ManagerBean!org.superbiz.cdi.decorators.CalculatorTest$ManagerBean")
+INFO - Jndi(name="java:global/decorators/ManagerBean")
+INFO - Jndi(name="java:global/EjbModule889074013/org.superbiz.cdi.decorators.CalculatorTest!org.superbiz.cdi.decorators.CalculatorTest")
+INFO - Jndi(name="java:global/EjbModule889074013/org.superbiz.cdi.decorators.CalculatorTest")
+INFO - Created Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=decorators.Comp, ejb-name=decorators.Comp, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=ManagerBean, ejb-name=ManagerBean, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=org.superbiz.cdi.decorators.CalculatorTest, ejb-name=org.superbiz.cdi.decorators.CalculatorTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=decorators.Comp, ejb-name=decorators.Comp, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=ManagerBean, ejb-name=ManagerBean, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=org.superbiz.cdi.decorators.CalculatorTest, ejb-name=org.superbiz.cdi.decorators.CalculatorTest, container=Default Managed Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/decorators)
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+Oct 28, 2011 5:09:01 PM org.apache.webbeans.decorator.DelegateHandler invoke
+SEVERE: Exception in calling method : [subtract] in decorator class : [org.superbiz.cdi.decorators.CalculatorSecurity]. Look in the log for target checked exception.
+org.superbiz.cdi.decorators.AccessDeniedException: guest
+ at org.superbiz.cdi.decorators.CalculatorSecurity.subtract(CalculatorSecurity.java:43)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ at java.lang.reflect.Method.invoke(Method.java:597)
+ at org.apache.webbeans.decorator.DelegateHandler.invoke(DelegateHandler.java:98)
+ at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:127)
+ at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:45)
+ at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:66)
+ at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:72)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ at java.lang.reflect.Method.invoke(Method.java:597)
+ at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
+ at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
+ at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:130)
+ at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:226)
+ at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:178)
+ at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:255)
+ at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:235)
+ at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
+ at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:284)
+ at $Proxy44.subtract(Unknown Source)
+ at org.superbiz.cdi.decorators.CalculatorTest.testSubtract(CalculatorTest.java:59)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ at java.lang.reflect.Method.invoke(Method.java:597)
+ at junit.framework.TestCase.runTest(TestCase.java:168)
+ at junit.framework.TestCase.runBare(TestCase.java:134)
+ at junit.framework.TestResult$1.protect(TestResult.java:110)
+ at junit.framework.TestResult.runProtected(TestResult.java:128)
+ at junit.framework.TestResult.run(TestResult.java:113)
+ at junit.framework.TestCase.run(TestCase.java:124)
+ at junit.framework.TestSuite.runTest(TestSuite.java:232)
+ at junit.framework.TestSuite.run(TestSuite.java:227)
+ at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
+ at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
+ at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
+ at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
+ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ at java.lang.reflect.Method.invoke(Method.java:597)
+ at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
+ at $Proxy0.invoke(Unknown Source)
+ at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
+ at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
+ at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.343 sec
+
+Results :
+
+Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ decorators ---
+[INFO] Building jar: /Users/dblevins/examples/decorators/target/decorators-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ decorators ---
+[INFO] Installing /Users/dblevins/examples/decorators/target/decorators-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/decorators/1.0/decorators-1.0.jar
+[INFO] Installing /Users/dblevins/examples/decorators/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/decorators/1.0/decorators-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.429s
+[INFO] Finished at: Fri Oct 28 17:09:02 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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.cdi.decorators;
+
+ import javax.ejb.ApplicationException;
+
+ /**
+ * @version $Revision$ $Date$
+ */
+ @ApplicationException
+ public class AccessDeniedException extends RuntimeException {
+ public AccessDeniedException(String s) {
+ super(s);
+ }
+ }
+ /**
+ * 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.cdi.decorators;
+
+ /**
+ * @version $Revision$ $Date$
+ */
+ public interface Calculator {
+
+ public int add(int a, int b);
+
+ public int subtract(int a, int b);
+
+ public int multiply(int a, int b);
+
+ public int divide(int a, int b);
+
+ public int remainder(int a, int b);
+ }
+ /**
+ * 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.cdi.decorators;
+
+ import javax.annotation.Resource;
+ import javax.ejb.SessionContext;
+ import javax.ejb.Stateless;
+ import javax.enterprise.inject.Produces;
+
+ @Stateless
+ public class CalculatorBean implements Calculator {
+
+ @Produces
+ @Resource
+ private SessionContext sessionContext;
+
+ 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;
+ }
+
+ }
+ /**
+ * 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.cdi.decorators;
+
+ import javax.decorator.Decorator;
+ import javax.decorator.Delegate;
+ import javax.ejb.ApplicationException;
+ import javax.inject.Inject;
+ import java.util.logging.Logger;
+
+ @Decorator
+ public class CalculatorLogging implements Calculator {
+
+ private Logger logger = Logger.getLogger("Calculator");
+
+ @Inject
+ @Delegate
+ private Calculator calculator;
+
+ @Override
+ public int add(int a, int b) {
+ logger.fine(String.format("add(%s, %s)", a, b));
+ return calculator.add(a, b);
+ }
+
+ @Override
+ public int subtract(int a, int b) {
+ return calculator.subtract(a, b);
+ }
+
+ @Override
+ public int multiply(int a, int b) {
+ logger.finest(String.format("multiply(%s, %s)", a, b));
+ return calculator.multiply(a, b);
+ }
+
+ @Override
+ public int divide(int a, int b) {
+ return calculator.divide(a, b);
+ }
+
+ @Override
+ public int remainder(int a, int b) {
+ logger.info(String.format("remainder(%s, %s)", a, b));
+ return calculator.remainder(a, b);
+ }
+ }
+ /**
+ * 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.cdi.decorators;
+
+ import javax.annotation.Resource;
+ import javax.decorator.Decorator;
+ import javax.decorator.Delegate;
+ import javax.ejb.SessionContext;
+ import javax.inject.Inject;
+
+ @Decorator
+ public class CalculatorSecurity implements Calculator {
+
+ @Inject
+ @Delegate
+ private Calculator calculator;
+
+ @Inject
+ private SessionContext sessionContext;
+
+ @Override
+ public int add(int a, int b) {
+ return calculator.add(a, b);
+ }
+
+ @Override
+ public int subtract(int a, int b) {
+ // Caller must pass a security check to call subtract
+ if (!sessionContext.isCallerInRole("Manager")) throw new AccessDeniedException(sessionContext.getCallerPrincipal().getName());
+
+ return calculator.subtract(a, b);
+ }
+
+ @Override
+ public int multiply(int a, int b) {
+ return calculator.multiply(a, b);
+ }
+
+ @Override
+ public int divide(int a, int b) {
+ return calculator.divide(a, b);
+ }
+
+ @Override
+ public int remainder(int a, int b) {
+ return calculator.remainder(a, b);
+ }
+
+ }
+ /**
+ * 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.cdi.decorators;
+
+ import junit.framework.TestCase;
+
+ import javax.annotation.security.RunAs;
+ import javax.ejb.EJB;
+ import javax.ejb.Stateless;
+ import javax.ejb.embeddable.EJBContainer;
+ import java.util.concurrent.Callable;
+
+ public class CalculatorTest extends TestCase {
+
+ @EJB
+ private Calculator calculator;
+
+ @EJB
+ private ManagerBean manager;
+
+ /**
+ * Bootstrap the Embedded EJB Container
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ EJBContainer.createEJBContainer().getContext().bind("inject", this);
+ }
+
+ /**
+ * Test Add method
+ */
+ public void testAdd() {
+
+ assertEquals(10, calculator.add(4, 6));
+
+ }
+
+ /**
+ * Test Subtract method
+ */
+ public void testSubtract() {
+
+ try {
+ calculator.subtract(4, 6);
+
+ fail("AccessDeniedException should have been thrown for unauthenticated access");
+ } catch (AccessDeniedException expected) {
+ // pass
+ }
+
+ final int result = manager.call(new Callable<Integer>() {
+ public Integer call() {
+ return calculator.subtract(4, 6);
+ }
+ });
+
+ assertEquals(-2, result);
+
+ }
+
+ /**
+ * Test Multiply method
+ */
+ public void testMultiply() {
+
+ assertEquals(24, calculator.multiply(4, 6));
+
+ }
+
+ /**
+ * Test Divide method
+ */
+ public void testDivide() {
+
+ assertEquals(2, calculator.divide(12, 6));
+
+ }
+
+ /**
+ * Test Remainder method
+ */
+ public void testRemainder() {
+
+ assertEquals(4, calculator.remainder(46, 6));
+
+ }
+
+ @Stateless
+ @RunAs("Manager")
+ public static class ManagerBean {
+
+ public <V> V call(Callable<V> callable) {
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }
+ }
Added: openejb/trunk/openejb/examples/dynamic-implementation/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/dynamic-implementation/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/dynamic-implementation/README.md (added)
+++ openejb/trunk/openejb/examples/dynamic-implementation/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,217 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Dynamic Implementation 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ dynamic-implementation ---
+[INFO] Deleting /Users/dblevins/examples/dynamic-implementation/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ dynamic-implementation ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/dynamic-implementation/src/main/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dynamic-implementation ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/dynamic-implementation/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ dynamic-implementation ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/dynamic-implementation/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dynamic-implementation ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/dynamic-implementation/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ dynamic-implementation ---
+[INFO] Surefire report directory: /Users/dblevins/examples/dynamic-implementation/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.dynamic.SocialTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/dynamic-implementation
+INFO - openejb.base = /Users/dblevins/examples/dynamic-implementation
+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/dynamic-implementation/target/classes
+INFO - Beginning load: /Users/dblevins/examples/dynamic-implementation/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/dynamic-implementation
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+INFO - Auto-creating a container for bean SocialBean: 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.dynamic.SocialTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/dynamic-implementation" loaded.
+INFO - Assembling app: /Users/dblevins/examples/dynamic-implementation
+INFO - Jndi(name="java:global/dynamic-implementation/SocialBean!org.superbiz.dynamic.SocialBean")
+INFO - Jndi(name="java:global/dynamic-implementation/SocialBean")
+INFO - Jndi(name="java:global/EjbModule853068360/org.superbiz.dynamic.SocialTest!org.superbiz.dynamic.SocialTest")
+INFO - Jndi(name="java:global/EjbModule853068360/org.superbiz.dynamic.SocialTest")
+INFO - Created Ejb(deployment-id=org.superbiz.dynamic.SocialTest, ejb-name=org.superbiz.dynamic.SocialTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=SocialBean, ejb-name=SocialBean, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=org.superbiz.dynamic.SocialTest, ejb-name=org.superbiz.dynamic.SocialTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=SocialBean, ejb-name=SocialBean, container=Default Singleton Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/dynamic-implementation)
+INFO - Undeploying app: /Users/dblevins/examples/dynamic-implementation
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.012 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ dynamic-implementation ---
+[INFO] Building jar: /Users/dblevins/examples/dynamic-implementation/target/dynamic-implementation-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ dynamic-implementation ---
+[INFO] Installing /Users/dblevins/examples/dynamic-implementation/target/dynamic-implementation-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/dynamic-implementation/1.0/dynamic-implementation-1.0.jar
+[INFO] Installing /Users/dblevins/examples/dynamic-implementation/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/dynamic-implementation/1.0/dynamic-implementation-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 3.841s
+[INFO] Finished at: Fri Oct 28 17:05:26 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+ /*
+ * 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.dynamic;
+
+ import org.apache.openejb.api.Proxy;
+
+ import javax.ejb.Singleton;
+ import javax.interceptor.Interceptors;
+
+ /**
+ * @author rmannibucau
+ */
+ @Singleton
+ @Proxy(SocialHandler.class)
+ @Interceptors(SocialInterceptor.class)
+ public interface SocialBean {
+ public String facebookStatus();
+ public String twitterStatus();
+ public String status();
+ }
+ /*
+ * 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.dynamic;
+
+ import java.lang.reflect.InvocationHandler;
+ import java.lang.reflect.Method;
+
+ /**
+ * @author rmannibucau
+ */
+ public class SocialHandler implements InvocationHandler {
+ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ String mtd = method.getName();
+ if (mtd.toLowerCase().contains("facebook")) {
+ return "You think you have a life!";
+ } else if (mtd.toLowerCase().contains("twitter")) {
+ return "Wow, you eat pop corn!";
+ }
+ return "Hey, you have no virtual friend!";
+ }
+ }
+ package org.superbiz.dynamic;
+
+ import javax.interceptor.AroundInvoke;
+ import javax.interceptor.InvocationContext;
+
+ /**
+ * @author rmannibucau
+ */
+ public class SocialInterceptor {
+ @AroundInvoke public Object around(InvocationContext context) throws Exception {
+ String mtd = context.getMethod().getName();
+ String address;
+ if (mtd.toLowerCase().contains("facebook")) {
+ address = "http://www.facebook.com";
+ } else if (mtd.toLowerCase().contains("twitter")) {
+ address = "http://twitter.com";
+ } else {
+ address ="no website for you";
+ }
+
+ System.out.println("go on " + address);
+ return context.proceed();
+ }
+ }
+ /*
+ * 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.dynamic;
+
+ import org.junit.AfterClass;
+ import org.junit.BeforeClass;
+ import org.junit.Test;
+
+ import javax.ejb.embeddable.EJBContainer;
+
+ import static junit.framework.Assert.assertTrue;
+
+ /**
+ * @author rmannibucau
+ */
+ public class SocialTest {
+ private static SocialBean social;
+ private static EJBContainer container;
+
+ @BeforeClass public static void init() throws Exception {
+ container = EJBContainer.createEJBContainer();
+ social = (SocialBean) container.getContext().lookup("java:global/dynamic-implementation/SocialBean");
+ }
+
+ @AfterClass public static void close() {
+ container.close();
+ }
+
+ @Test public void simple() {
+ assertTrue(social.facebookStatus().contains("think"));
+ assertTrue(social.twitterStatus().contains("eat"));
+ assertTrue(social.status().contains("virtual"));
+ }
+ }