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 [8/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/simple-cmp2/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-cmp2/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-cmp2/README.md (added)
+++ openejb/trunk/openejb/examples/simple-cmp2/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,261 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Simple CMP2 Entity 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ simple-cmp2 ---
+[INFO] Deleting /Users/dblevins/examples/simple-cmp2/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-cmp2 ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 2 resources
+[INFO]
+[INFO] --- maven-dependency-plugin:2.1:copy (copy) @ simple-cmp2 ---
+[INFO] Configured Artifact: org.apache.openejb:openejb-javaagent:4.0.0-beta-1:jar
+[INFO] Copying openejb-javaagent-4.0.0-beta-1.jar to /Users/dblevins/examples/simple-cmp2/target/openejb-javaagent-4.0.0-beta-1.jar
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ simple-cmp2 ---
+[INFO] Compiling 3 source files to /Users/dblevins/examples/simple-cmp2/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-cmp2 ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/simple-cmp2/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ simple-cmp2 ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/simple-cmp2/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.6:test (default-test) @ simple-cmp2 ---
+[INFO] Surefire report directory: /Users/dblevins/examples/simple-cmp2/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.cmp2.MoviesTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-cmp2/target
+INFO - openejb.base = /Users/dblevins/examples/simple-cmp2/target
+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=movieDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database)
+INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-cmp2/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-cmp2/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-cmp2/target/classpath.ear
+INFO - Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
+INFO - Auto-creating a container for bean MovieBean: Container(type=CMP_ENTITY, id=Default CMP Container)
+INFO - Configuring PersistenceUnit(name=cmp)
+INFO - Adjusting PersistenceUnit cmp <jta-data-source> to Resource ID 'movieDatabase' from 'null'
+INFO - Adjusting PersistenceUnit cmp <non-jta-data-source> to Resource ID 'movieDatabaseUnmanaged' from 'null'
+INFO - Enterprise application "/Users/dblevins/examples/simple-cmp2/target/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-cmp2/target/classpath.ear
+INFO - PersistenceUnit(name=cmp, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 165ms
+INFO - Jndi(name=MovieBeanLocalHome) --> Ejb(deployment-id=MovieBean)
+INFO - Jndi(name=global/classpath.ear/simple-cmp2/MovieBean!org.superbiz.cmp2.Movies) --> Ejb(deployment-id=MovieBean)
+INFO - Jndi(name=global/classpath.ear/simple-cmp2/MovieBean) --> Ejb(deployment-id=MovieBean)
+INFO - Created Ejb(deployment-id=MovieBean, ejb-name=MovieBean, container=Default CMP Container)
+INFO - Started Ejb(deployment-id=MovieBean, ejb-name=MovieBean, container=Default CMP Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-cmp2/target/classpath.ear)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.91 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ simple-cmp2 ---
+[INFO] Building jar: /Users/dblevins/examples/simple-cmp2/target/simple-cmp2-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-cmp2 ---
+[INFO] Installing /Users/dblevins/examples/simple-cmp2/target/simple-cmp2-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/simple-cmp2/1.0/simple-cmp2-1.0.jar
+[INFO] Installing /Users/dblevins/examples/simple-cmp2/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/simple-cmp2/1.0/simple-cmp2-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 6.010s
+[INFO] Finished at: Fri Oct 28 17:00:05 PDT 2011
+[INFO] Final Memory: 15M/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.cmp2;
+
+ /**
+ * @version $Revision$ $Date$
+ */
+ public interface Movie extends javax.ejb.EJBLocalObject {
+ java.lang.Integer getId();
+
+ void setId(java.lang.Integer id);
+
+ String getDirector();
+
+ void setDirector(String director);
+
+ String getTitle();
+
+ void setTitle(String title);
+
+ int getYear();
+
+ void setYear(int year);
+ }
+ /**
+ * 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.cmp2;
+
+ import javax.ejb.EntityBean;
+
+ public abstract class MovieBean implements EntityBean {
+
+ public MovieBean() {
+ }
+
+ public Integer ejbCreate(String director, String title, int year) {
+ this.setDirector(director);
+ this.setTitle(title);
+ this.setYear(year);
+ return null;
+ }
+
+ public abstract java.lang.Integer getId();
+
+ public abstract void setId(java.lang.Integer id);
+
+ public abstract String getDirector();
+
+ public abstract void setDirector(String director);
+
+ public abstract String getTitle();
+
+ public abstract void setTitle(String title);
+
+ public abstract int getYear();
+
+ public abstract void setYear(int year);
+
+
+ }
+ /**
+ * 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.cmp2;
+
+ import javax.ejb.CreateException;
+ import javax.ejb.FinderException;
+ import java.util.Collection;
+
+ /**
+ * @version $Revision$ $Date$
+ */
+ interface Movies extends javax.ejb.EJBLocalHome {
+ Movie create(String director, String title, int year) throws CreateException;
+
+ Movie findByPrimaryKey(Integer primarykey) throws FinderException;
+
+ Collection<Movie> findAll() throws FinderException;
+
+ Collection<Movie> findByDirector(String director) throws FinderException;
+ }
+ /**
+ * 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.cmp2;
+
+ import junit.framework.TestCase;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import java.util.Collection;
+ import java.util.Properties;
+
+ /**
+ * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $
+ */
+ public class MoviesTest extends TestCase {
+
+ public void test() throws Exception {
+ Properties p = new Properties();
+ p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ p.put("movieDatabase", "new://Resource?type=DataSource");
+ p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+
+ p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
+ p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+ p.put("movieDatabaseUnmanaged.JtaManaged", "false");
+
+ Context context = new InitialContext(p);
+
+ Movies movies = (Movies) context.lookup("MovieBeanLocalHome");
+
+ movies.create("Quentin Tarantino", "Reservoir Dogs", 1992);
+ movies.create("Joel Coen", "Fargo", 1996);
+ movies.create("Joel Coen", "The Big Lebowski", 1998);
+
+ Collection<Movie> list = movies.findAll();
+ assertEquals("Collection.size()", 3, list.size());
+
+ for (Movie movie : list) {
+ movies.remove(movie.getPrimaryKey());
+ }
+
+ assertEquals("Movies.findAll()", 0, movies.findAll().size());
+ }
+ }
Added: openejb/trunk/openejb/examples/simple-mdb-with-descriptor/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-mdb-with-descriptor/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-mdb-with-descriptor/README.md (added)
+++ openejb/trunk/openejb/examples/simple-mdb-with-descriptor/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,263 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Simple MDB Using Deployment Descriptor Example 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ simple-mdb-with-descriptor ---
+[INFO] Deleting /Users/dblevins/examples/simple-mdb-with-descriptor/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-mdb-with-descriptor ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ simple-mdb-with-descriptor ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/simple-mdb-with-descriptor/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-mdb-with-descriptor ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/simple-mdb-with-descriptor/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ simple-mdb-with-descriptor ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/simple-mdb-with-descriptor/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ simple-mdb-with-descriptor ---
+[INFO] Surefire report directory: /Users/dblevins/examples/simple-mdb-with-descriptor/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.mdb.ChatBeanTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-mdb-with-descriptor
+INFO - openejb.base = /Users/dblevins/examples/simple-mdb-with-descriptor
+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-mdb-with-descriptor/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-mdb-with-descriptor/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-mdb-with-descriptor
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default MDB Container, type=Container, provider-id=Default MDB Container)
+INFO - Auto-creating a container for bean ChatBean: Container(type=MESSAGE, id=Default MDB Container)
+INFO - Configuring Service(id=Default JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter)
+INFO - Configuring Service(id=Default JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory)
+INFO - Auto-creating a Resource with id 'Default JMS Connection Factory' of type 'javax.jms.ConnectionFactory for 'ChatBean'.
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdbdesc.ChatBean/connectionFactory' in bean ChatBean to Resource(id=Default JMS Connection Factory)
+INFO - Configuring Service(id=AnswerQueue, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'AnswerQueue' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean ChatBean to Resource(id=AnswerQueue)
+INFO - Configuring Service(id=ChatBean, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'ChatBean' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.mdb.ChatBeanTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdb.ChatBeanTest/connectionFactory' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=Default JMS Connection Factory)
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=AnswerQueue)
+INFO - Auto-linking resource-env-ref 'java:comp/env/ChatBean' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=ChatBean)
+INFO - Enterprise application "/Users/dblevins/examples/simple-mdb-with-descriptor" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-mdb-with-descriptor
+INFO - Jndi(name="java:global/EjbModule730637923/org.superbiz.mdb.ChatBeanTest!org.superbiz.mdb.ChatBeanTest")
+INFO - Jndi(name="java:global/EjbModule730637923/org.superbiz.mdb.ChatBeanTest")
+INFO - Created Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Started Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-mdb-with-descriptor)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.936 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ simple-mdb-with-descriptor ---
+[INFO] Building jar: /Users/dblevins/examples/simple-mdb-with-descriptor/target/simple-mdb-with-descriptor-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-mdb-with-descriptor ---
+[INFO] Installing /Users/dblevins/examples/simple-mdb-with-descriptor/target/simple-mdb-with-descriptor-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/simple-mdb-with-descriptor/1.0/simple-mdb-with-descriptor-1.0.jar
+[INFO] Installing /Users/dblevins/examples/simple-mdb-with-descriptor/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/simple-mdb-with-descriptor/1.0/simple-mdb-with-descriptor-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 5.233s
+[INFO] Finished at: Fri Oct 28 17:02:42 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.
+ */
+ //START SNIPPET: code
+ package org.superbiz.mdbdesc;
+
+ import javax.jms.Connection;
+ import javax.jms.ConnectionFactory;
+ import javax.jms.DeliveryMode;
+ import javax.jms.JMSException;
+ import javax.jms.Message;
+ import javax.jms.MessageListener;
+ import javax.jms.MessageProducer;
+ import javax.jms.Queue;
+ import javax.jms.Session;
+ import javax.jms.TextMessage;
+
+ public class ChatBean implements MessageListener {
+
+ private ConnectionFactory connectionFactory;
+
+ private Queue answerQueue;
+
+ public void onMessage(Message message) {
+ try {
+
+ final TextMessage textMessage = (TextMessage) message;
+ final String question = textMessage.getText();
+
+ if ("Hello World!".equals(question)) {
+
+ respond("Hello, Test Case!");
+
+ } else if ("How are you?".equals(question)) {
+
+ respond("I'm doing well.");
+
+ } else if ("Still spinning?".equals(question)) {
+
+ respond("Once every day, as usual.");
+
+ }
+ } catch (JMSException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private void respond(String text) throws JMSException {
+
+ Connection connection = null;
+ Session session = null;
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+
+ // Create a Session
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Create a MessageProducer from the Session to the Topic or Queue
+ MessageProducer producer = session.createProducer(answerQueue);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ // Create a message
+ TextMessage message = session.createTextMessage(text);
+
+ // Tell the producer to send the message
+ producer.send(message);
+ } finally {
+ // Clean up
+ if (session != null) session.close();
+ if (connection != null) connection.close();
+ }
+ }
+ }
+ //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.
+ */
+ //START SNIPPET: code
+ package org.superbiz.mdb;
+
+ import junit.framework.TestCase;
+
+ import javax.annotation.Resource;
+ import javax.ejb.embeddable.EJBContainer;
+ import javax.jms.Connection;
+ import javax.jms.ConnectionFactory;
+ import javax.jms.JMSException;
+ import javax.jms.MessageConsumer;
+ import javax.jms.MessageProducer;
+ import javax.jms.Queue;
+ import javax.jms.Session;
+ import javax.jms.TextMessage;
+
+ public class ChatBeanTest extends TestCase {
+
+ @Resource
+ private ConnectionFactory connectionFactory;
+
+ @Resource(name = "ChatBean")
+ private Queue questionQueue;
+
+ @Resource(name = "AnswerQueue")
+ private Queue answerQueue;
+
+ public void test() throws Exception {
+
+ EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+ final Connection connection = connectionFactory.createConnection();
+
+ connection.start();
+
+ final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer questions = session.createProducer(questionQueue);
+
+ final MessageConsumer answers = session.createConsumer(answerQueue);
+
+
+ sendText("Hello World!", questions, session);
+
+ assertEquals("Hello, Test Case!", receiveText(answers));
+
+
+ sendText("How are you?", questions, session);
+
+ assertEquals("I'm doing well.", receiveText(answers));
+
+
+ sendText("Still spinning?", questions, session);
+
+ assertEquals("Once every day, as usual.", receiveText(answers));
+
+ }
+
+ private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
+
+ questions.send(session.createTextMessage(text));
+
+ }
+
+ private String receiveText(MessageConsumer answers) throws JMSException {
+
+ return ((TextMessage) answers.receive(1000)).getText();
+
+ }
+
+ }
+ //END SNIPPET: code
Added: openejb/trunk/openejb/examples/simple-singleton/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-singleton/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-singleton/README.md (added)
+++ openejb/trunk/openejb/examples/simple-singleton/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,318 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Simple Singleton 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ simple-singleton ---
+[INFO] Deleting /Users/dblevins/examples/simple-singleton/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-singleton ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/simple-singleton/src/main/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ simple-singleton ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/simple-singleton/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-singleton ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/simple-singleton/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ simple-singleton ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/simple-singleton/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ simple-singleton ---
+[INFO] Surefire report directory: /Users/dblevins/examples/simple-singleton/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.registry.ComponentRegistryTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-singleton
+INFO - openejb.base = /Users/dblevins/examples/simple-singleton
+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-singleton/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-singleton/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-singleton
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+INFO - Auto-creating a container for bean ComponentRegistry: 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.registry.ComponentRegistryTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/simple-singleton" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-singleton
+INFO - Jndi(name="java:global/simple-singleton/ComponentRegistry!org.superbiz.registry.ComponentRegistry")
+INFO - Jndi(name="java:global/simple-singleton/ComponentRegistry")
+INFO - Jndi(name="java:global/simple-singleton/PropertyRegistry!org.superbiz.registry.PropertyRegistry")
+INFO - Jndi(name="java:global/simple-singleton/PropertyRegistry")
+INFO - Jndi(name="java:global/EjbModule709424757/org.superbiz.registry.ComponentRegistryTest!org.superbiz.registry.ComponentRegistryTest")
+INFO - Jndi(name="java:global/EjbModule709424757/org.superbiz.registry.ComponentRegistryTest")
+INFO - Created Ejb(deployment-id=org.superbiz.registry.ComponentRegistryTest, ejb-name=org.superbiz.registry.ComponentRegistryTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=PropertyRegistry, ejb-name=PropertyRegistry, container=Default Singleton Container)
+INFO - Created Ejb(deployment-id=ComponentRegistry, ejb-name=ComponentRegistry, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=org.superbiz.registry.ComponentRegistryTest, ejb-name=org.superbiz.registry.ComponentRegistryTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=PropertyRegistry, ejb-name=PropertyRegistry, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=ComponentRegistry, ejb-name=ComponentRegistry, container=Default Singleton Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-singleton)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.11 sec
+Running org.superbiz.registry.PropertiesRegistryTest
+INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec
+
+Results :
+
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ simple-singleton ---
+[INFO] Building jar: /Users/dblevins/examples/simple-singleton/target/simple-singleton-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-singleton ---
+[INFO] Installing /Users/dblevins/examples/simple-singleton/target/simple-singleton-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/simple-singleton/1.0/simple-singleton-1.0.jar
+[INFO] Installing /Users/dblevins/examples/simple-singleton/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/simple-singleton/1.0/simple-singleton-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.013s
+[INFO] Finished at: Fri Oct 28 17:10:34 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.registry;
+
+ //START SNIPPET: code
+
+ import javax.ejb.Lock;
+ import javax.ejb.Singleton;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.HashMap;
+ import java.util.Map;
+
+ import static javax.ejb.LockType.READ;
+ import static javax.ejb.LockType.WRITE;
+
+ @Singleton
+ @Lock(READ)
+ public class ComponentRegistry {
+
+ private final Map<Class, Object> components = new HashMap<Class, Object>();
+
+ public <T> T getComponent(Class<T> type) {
+ return (T) components.get(type);
+ }
+
+ public Collection<?> getComponents() {
+ return new ArrayList(components.values());
+ }
+
+ @Lock(WRITE)
+ public <T> T setComponent(Class<T> type, T value) {
+ return (T) components.put(type, value);
+ }
+
+ @Lock(WRITE)
+ public <T> T removeComponent(Class<T> type) {
+ return (T) components.remove(type);
+ }
+
+ }
+ //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.registry;
+
+ //START SNIPPET: code
+
+ import javax.annotation.PostConstruct;
+ import javax.annotation.PreDestroy;
+ import javax.ejb.ConcurrencyManagement;
+ import javax.ejb.Singleton;
+ import javax.ejb.Startup;
+ import java.util.Properties;
+
+ import static javax.ejb.ConcurrencyManagementType.BEAN;
+
+ @Singleton
+ @Startup
+ @ConcurrencyManagement(BEAN)
+ public class PropertyRegistry {
+
+ // Note the java.util.Properties object is a thread-safe
+ // collections that uses synchronization. If it didn't
+ // you would have to use some form of synchronization
+ // to ensure the PropertyRegistryBean is thread-safe.
+ private final Properties properties = new Properties();
+
+ // The @Startup method ensures that this method is
+ // called when the application starts up.
+ @PostConstruct
+ public void applicationStartup() {
+ properties.putAll(System.getProperties());
+ }
+
+ @PreDestroy
+ public void applicationShutdown() {
+ properties.clear();
+ }
+
+ public String getProperty(String key) {
+ return properties.getProperty(key);
+ }
+
+ public String setProperty(String key, String value) {
+ return (String) properties.setProperty(key, value);
+ }
+
+ public String removeProperty(String key) {
+ return (String) properties.remove(key);
+ }
+
+ }
+ //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.registry;
+
+ import junit.framework.TestCase;
+
+ import javax.ejb.embeddable.EJBContainer;
+ import javax.naming.Context;
+ import java.net.URI;
+ import java.util.Date;
+
+ //START SNIPPET: code
+ public class ComponentRegistryTest extends TestCase {
+
+ public void test() throws Exception {
+
+ final Context context = EJBContainer.createEJBContainer().getContext();
+
+ // Both references below will point to the exact same instance
+ ComponentRegistry one = (ComponentRegistry) context.lookup("java:global/simple-singleton/ComponentRegistry");
+
+ ComponentRegistry two = (ComponentRegistry) context.lookup("java:global/simple-singleton/ComponentRegistry");
+
+
+ // Let's prove both references point to the same instance
+
+
+ // Set a URL into 'one' and retrieve it from 'two'
+
+ URI expectedUri = new URI("foo://bar/baz");
+
+ one.setComponent(URI.class, expectedUri);
+
+ URI actualUri = two.getComponent(URI.class);
+
+ assertSame(expectedUri, actualUri);
+
+
+ // Set a Date into 'two' and retrieve it from 'one'
+
+ Date expectedDate = new Date();
+
+ two.setComponent(Date.class, expectedDate);
+
+ Date actualDate = one.getComponent(Date.class);
+
+ assertSame(expectedDate, actualDate);
+
+ }
+ }
+ //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.registry;
+
+ import junit.framework.TestCase;
+
+ import javax.ejb.embeddable.EJBContainer;
+ import javax.naming.Context;
+
+ public class PropertiesRegistryTest extends TestCase {
+
+ public void test() throws Exception {
+
+ Context context = EJBContainer.createEJBContainer().getContext();
+
+ PropertyRegistry one = (PropertyRegistry) context.lookup("java:global/simple-singleton/PropertyRegistry");
+
+ PropertyRegistry two = (PropertyRegistry) context.lookup("java:global/simple-singleton/PropertyRegistry");
+
+
+ one.setProperty("url", "http://superbiz.org");
+
+ String url = two.getProperty("url");
+
+ assertEquals("http://superbiz.org", url);
+
+
+ two.setProperty("version", "1.0.5");
+
+ String version = one.getProperty("version");
+
+ assertEquals("1.0.5", version);
+
+ }
+ }
Added: openejb/trunk/openejb/examples/simple-stateless-with-descriptor/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-with-descriptor/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-stateless-with-descriptor/README.md (added)
+++ openejb/trunk/openejb/examples/simple-stateless-with-descriptor/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,242 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Simple Stateless With Deployment Descriptor 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ simple-stateless-with-descriptor ---
+[INFO] Deleting /Users/dblevins/examples/simple-stateless-with-descriptor/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-stateless-with-descriptor ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ simple-stateless-with-descriptor ---
+[INFO] Compiling 3 source files to /Users/dblevins/examples/simple-stateless-with-descriptor/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-stateless-with-descriptor ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/simple-stateless-with-descriptor/src/test/resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ simple-stateless-with-descriptor ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/simple-stateless-with-descriptor/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ simple-stateless-with-descriptor ---
+[INFO] Surefire report directory: /Users/dblevins/examples/simple-stateless-with-descriptor/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.calculator.CalculatorTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.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.578 sec
+
+Results :
+
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ simple-stateless-with-descriptor ---
+[INFO] Building jar: /Users/dblevins/examples/simple-stateless-with-descriptor/target/simple-stateless-with-descriptor-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-stateless-with-descriptor ---
+[INFO] Installing /Users/dblevins/examples/simple-stateless-with-descriptor/target/simple-stateless-with-descriptor-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/simple-stateless-with-descriptor/1.0/simple-stateless-with-descriptor-1.0.jar
+[INFO] Installing /Users/dblevins/examples/simple-stateless-with-descriptor/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/simple-stateless-with-descriptor/1.0/simple-stateless-with-descriptor-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.718s
+[INFO] Finished at: Fri Oct 28 17:03:06 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.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
+ */
+ //START SNIPPET: code
+ 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;
+ }
+
+ }
+ //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.calculator;
+
+ /**
+ * This is an EJB 3 local business interface
+ * This interface is specified using the business-local tag in the deployment descriptor
+ */
+ //START SNIPPET: code
+ public interface CalculatorLocal {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+ }
+ //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.calculator;
+
+
+ /**
+ * This is an EJB 3 remote business interface
+ * This interface is specified using the business-local tag in the deployment descriptor
+ */
+ //START SNIPPET: code
+ public interface CalculatorRemote {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ }
+ //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.calculator;
+
+ import junit.framework.TestCase;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import java.util.Properties;
+
+ public class CalculatorTest extends TestCase {
+
+ //START SNIPPET: setup
+ 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);
+ }
+ //END SNIPPET: setup
+
+ /**
+ * Lookup the Calculator bean via its remote home interface
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: remote
+ 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));
+ }
+ //END SNIPPET: remote
+
+ /**
+ * Lookup the Calculator bean via its local home interface
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: local
+ 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));
+ }
+ //END SNIPPET: local
+
+ }
Added: openejb/trunk/openejb/examples/simple-webservice/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/README.md (added)
+++ openejb/trunk/openejb/examples/simple-webservice/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,394 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Simple Webservice 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ simple-webservice ---
+[INFO] Deleting /Users/dblevins/examples/simple-webservice/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-webservice ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 2 resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ simple-webservice ---
+[INFO] Compiling 4 source files to /Users/dblevins/examples/simple-webservice/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-webservice ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ simple-webservice ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/simple-webservice/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ simple-webservice ---
+[INFO] Surefire report directory: /Users/dblevins/examples/simple-webservice/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.calculator.CalculatorTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-webservice
+INFO - openejb.base = /Users/dblevins/examples/simple-webservice
+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-webservice/target/test-classes
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-webservice/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-webservice/target/test-classes
+INFO - Beginning load: /Users/dblevins/examples/simple-webservice/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-webservice/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-webservice/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-webservice/classpath.ear
+INFO - Jndi(name=CalculatorImplLocal) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/simple-webservice/CalculatorImpl!org.superbiz.calculator.CalculatorLocal) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/simple-webservice/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 - LocalClient(class=org.superbiz.calculator.CalculatorTest, module=test-classes)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-webservice/classpath.ear)
+INFO - Initializing network services
+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
+ ** Starting Services **
+ NAME IP PORT
+ httpejbd 127.0.0.1 4204
+ admin thread 127.0.0.1 4200
+ ejbd 127.0.0.1 4201
+ ejbd 127.0.0.1 4203
+-------
+Ready!
+Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.233 sec
+
+Results :
+
+Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ simple-webservice ---
+[INFO] Building jar: /Users/dblevins/examples/simple-webservice/target/simple-webservice-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-webservice ---
+[INFO] Installing /Users/dblevins/examples/simple-webservice/target/simple-webservice-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/simple-webservice/1.0/simple-webservice-1.0.jar
+[INFO] Installing /Users/dblevins/examples/simple-webservice/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/simple-webservice/1.0/simple-webservice-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 6.743s
+[INFO] Finished at: Fri Oct 28 16:59:36 PDT 2011
+[INFO] Final Memory: 17M/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.calculator;
+
+ import javax.ejb.Stateless;
+ import javax.jws.HandlerChain;
+ import javax.jws.WebService;
+ import javax.xml.ws.Holder;
+ import java.util.Date;
+
+ /**
+ * This is an EJB 3 style pojo stateless session bean
+ * Every stateless session bean implementation must be annotated
+ * using the annotation @Stateless
+ * This EJB has a 2 interfaces:
+ * <ul>
+ * <li>CalculatorWs a webservice interface</li>
+ * <li>CalculatorLocal a local interface</li>
+ * </ul>
+ */
+ //START SNIPPET: code
+ @Stateless
+ @WebService(
+ portName = "CalculatorPort",
+ serviceName = "CalculatorWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.calculator.CalculatorWs")
+ @HandlerChain(file = "handler.xml")
+ public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
+
+ public int sum(int add1, int add2) {
+ return add1 + add2;
+ }
+
+ public int multiply(int mul1, int mul2) {
+ return mul1 * mul2;
+ }
+
+ public int factorial(
+ int number,
+ Holder<String> userId,
+ Holder<String> returnCode,
+ Holder<Date> datetime) {
+
+ if (number == 0) {
+ returnCode.value = "Can not calculate factorial for zero.";
+ return -1;
+ }
+
+ returnCode.value = userId.value;
+ datetime.value = new Date();
+ return (int) factorial(number);
+ }
+
+ // return n!
+ // precondition: n >= 0 and n <= 20
+
+ private static long factorial(long n) {
+ if (n < 0) throw new RuntimeException("Underflow error in factorial");
+ else if (n > 20) throw new RuntimeException("Overflow error in factorial");
+ else if (n == 0) return 1;
+ else return n * factorial(n - 1);
+ }
+ }
+ //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.calculator;
+
+ import javax.ejb.Local;
+
+ @Local
+ public interface CalculatorLocal extends CalculatorWs {
+
+ }/**
+ * 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.calculator;
+
+ import javax.jws.WebParam;
+ import javax.jws.WebService;
+ import javax.jws.soap.SOAPBinding;
+ import javax.jws.soap.SOAPBinding.ParameterStyle;
+ import javax.jws.soap.SOAPBinding.Style;
+ import javax.jws.soap.SOAPBinding.Use;
+ import javax.xml.ws.Holder;
+ import java.util.Date;
+
+ //END SNIPPET: code
+
+ /**
+ * This is an EJB 3 webservice interface
+ * A webservice interface must be annotated with the @WebService
+ * annotation.
+ */
+ //START SNIPPET: code
+ @WebService(
+ name = "CalculatorWs",
+ targetNamespace = "http://superbiz.org/wsdl")
+ public interface CalculatorWs {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ // because of CXF bug, BARE must be used instead of default WRAPPED
+
+ @SOAPBinding(use = Use.LITERAL, parameterStyle = ParameterStyle.BARE, style = Style.DOCUMENT)
+ public int factorial(
+ int number,
+ @WebParam(name = "userid", header = true, mode = WebParam.Mode.IN) Holder<String> userId,
+ @WebParam(name = "returncode", header = true, mode = WebParam.Mode.OUT) Holder<String> returnCode,
+ @WebParam(name = "datetime", header = true, mode = WebParam.Mode.INOUT) Holder<Date> datetime);
+
+ }
+ //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.handler;
+
+ import javax.xml.namespace.QName;
+ import javax.xml.ws.handler.MessageContext;
+ import javax.xml.ws.handler.soap.SOAPHandler;
+ import javax.xml.ws.handler.soap.SOAPMessageContext;
+ import java.util.Collections;
+ import java.util.Set;
+
+ public class DummyInterceptor implements SOAPHandler<SOAPMessageContext> {
+ public DummyInterceptor() {
+ super();
+ }
+
+ public Set<QName> getHeaders() {
+ return Collections.emptySet();
+ }
+
+ public void close(MessageContext mc) {
+ }
+
+ public boolean handleFault(SOAPMessageContext mc) {
+ return true;
+ }
+
+ public boolean handleMessage(SOAPMessageContext mc) {
+ return true;
+ }
+ }/**
+ * 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.calculator;
+
+ import junit.framework.TestCase;
+ import org.apache.openejb.api.LocalClient;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import javax.xml.namespace.QName;
+ import javax.xml.ws.Holder;
+ import javax.xml.ws.Service;
+ import javax.xml.ws.WebServiceRef;
+ import java.net.URL;
+ import java.util.Date;
+ import java.util.Properties;
+
+ @LocalClient
+ public class CalculatorTest extends TestCase {
+
+ @WebServiceRef(
+ wsdlLocation = "http://127.0.0.1:4204/CalculatorImpl?wsdl"
+ )
+ private CalculatorWs calculatorWs;
+
+ //START SNIPPET: setup
+ private InitialContext initialContext;
+
+ // date used to invoke a web service with INOUT parameters
+ private static final Date date = new Date();
+
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ properties.setProperty("openejb.embedded.remotable", "true");
+
+ initialContext = new InitialContext(properties);
+ initialContext.bind("inject", this);
+
+ }
+ //END SNIPPET: setup
+
+ /**
+ * Create a webservice client using wsdl url
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: webservice
+ public void testCalculatorViaWsInterface() throws Exception {
+ Service calcService = Service.create(
+ new URL("http://127.0.0.1:4204/CalculatorImpl?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+ assertEquals(10, calc.sum(4, 6));
+ assertEquals(12, calc.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+
+ public void testWebServiceRefInjection() throws Exception {
+ assertEquals(10, calculatorWs.sum(4, 6));
+ assertEquals(12, calculatorWs.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calculatorWs.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+
+ public void testCalculatorViaRemoteInterface() throws Exception {
+ CalculatorLocal calc = (CalculatorLocal) initialContext.lookup("CalculatorImplLocal");
+ assertEquals(10, calc.sum(4, 6));
+ assertEquals(12, calc.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+ //END SNIPPET: webservice
+
+ }