summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/host-openejb/src
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-12 21:54:50 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-12 21:54:50 +0000
commitd232b6a46e4225ff35a0123a5f5597da7592fc38 (patch)
tree0c607d86a472ccbdd5587eb3ae53f535b6aa36f2 /branches/sca-equinox/modules/host-openejb/src
parent2e48ecc0ea43d7b859c578080c72e4c739717487 (diff)
Creating a branch for the equinox work.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694816 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/host-openejb/src')
-rw-r--r--branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBRuntimeModuleActivator.java52
-rw-r--r--branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java127
-rw-r--r--branches/sca-equinox/modules/host-openejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator19
-rw-r--r--branches/sca-equinox/modules/host-openejb/src/test/java/org/apache/tuscany/sca/host/openejb/OpenEJBServerTestCase.java86
4 files changed, 284 insertions, 0 deletions
diff --git a/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBRuntimeModuleActivator.java b/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBRuntimeModuleActivator.java
new file mode 100644
index 0000000000..70bba08789
--- /dev/null
+++ b/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBRuntimeModuleActivator.java
@@ -0,0 +1,52 @@
+/*
+ * 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.apache.tuscany.sca.host.openejb;
+
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.host.ejb.EJBHostExtensionPoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OpenEJBRuntimeModuleActivator implements ModuleActivator {
+ private static final Logger logger = Logger.getLogger(OpenEJBRuntimeModuleActivator.class.getName());
+
+ private OpenEJBServer server;
+
+ public void start(ExtensionPointRegistry extensionPointRegistry) {
+
+ // Register our EJB host
+ EJBHostExtensionPoint ejbHosts =
+ extensionPointRegistry.getExtensionPoint(EJBHostExtensionPoint.class);
+
+ server = new OpenEJBServer();
+ ejbHosts.addEJBHost(server);
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ if (server != null) {
+ server.stop();
+ }
+ }
+
+}
diff --git a/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java b/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java
new file mode 100644
index 0000000000..0da02c284d
--- /dev/null
+++ b/branches/sca-equinox/modules/host-openejb/src/main/java/org/apache/tuscany/sca/host/openejb/OpenEJBServer.java
@@ -0,0 +1,127 @@
+package org.apache.tuscany.sca.host.openejb;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.ServerFederation;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.ServiceDaemon;
+import org.apache.openejb.server.ServiceException;
+import org.apache.openejb.server.ejbd.EjbServer;
+import org.apache.tuscany.sca.host.ejb.EJBHost;
+import org.apache.tuscany.sca.host.ejb.EJBRegistrationException;
+import org.apache.tuscany.sca.host.ejb.EJBSessionBean;
+
+/**
+ * OpenEJB-based EJB host implementation.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class OpenEJBServer implements EJBHost {
+
+ private boolean started;
+ private EjbServer ejbServer;
+ private ServiceDaemon serviceDaemon;
+ private ConfigurationFactory config;
+ private Assembler assembler;
+
+ public void addSessionBean(String ejbName, EJBSessionBean sessionBean) throws EJBRegistrationException {
+ if (!started) {
+ start();
+ }
+
+ try {
+ StatelessBean bean = new StatelessBean(ejbName, sessionBean.getImplementationClass());
+ bean.addBusinessRemote(sessionBean.getRemoteInterface().getName());
+ bean.addPostConstruct("init");
+ bean.addPreDestroy("destroy");
+
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(bean);
+
+ assembler.createApplication(config.configureApplication(ejbJar));
+
+ } catch (NamingException e) {
+ throw new EJBRegistrationException(e);
+ } catch (IOException e) {
+ throw new EJBRegistrationException(e);
+ } catch (OpenEJBException e) {
+ throw new EJBRegistrationException(e);
+ }
+ }
+
+ public EJBSessionBean getSessionBean(String ejbName) throws EJBRegistrationException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public EJBSessionBean removeSessionBean(String ejbName) throws EJBRegistrationException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Start the OpenEJB server.
+ *
+ * @throws EJBRegistrationException
+ */
+ private void start() throws EJBRegistrationException {
+ try {
+ Properties properties = new Properties();
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
+ properties.put(Context.PROVIDER_URL, "ejbd://localhost:2888");
+ SystemInstance.init(properties);
+
+ ejbServer = new EjbServer();
+ SystemInstance.get().setComponent(EjbServer.class, ejbServer);
+ OpenEJB.init(properties, new ServerFederation());
+ ejbServer.init(properties);
+
+ serviceDaemon = new ServiceDaemon(ejbServer, 2888, "localhost");
+ serviceDaemon.start();
+
+ config = new ConfigurationFactory();
+ assembler = (Assembler)SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
+
+ // containers
+ StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
+ statelessContainerInfo.properties.setProperty("TimeOut", "10");
+ statelessContainerInfo.properties.setProperty("PoolSize", "0");
+ statelessContainerInfo.properties.setProperty("StrictPooling", "false");
+ assembler.createContainer(statelessContainerInfo);
+
+ } catch (OpenEJBException e) {
+ throw new EJBRegistrationException(e);
+ } catch (Exception e) {
+ throw new EJBRegistrationException(e);
+ }
+
+ started = true;
+ }
+
+ /**
+ * Stop the OpenEJB server.
+ */
+ void stop() {
+ if (started) {
+ try {
+ serviceDaemon.stop();
+ } catch (ServiceException e) {
+ throw new EJBRegistrationException(e);
+ }
+ }
+ SystemInstance.get().removeComponent(EjbServer.class);
+ OpenEJB.destroy();
+ }
+
+}
diff --git a/branches/sca-equinox/modules/host-openejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/branches/sca-equinox/modules/host-openejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..9247f40913
--- /dev/null
+++ b/branches/sca-equinox/modules/host-openejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the ModuleActivator
+org.apache.tuscany.sca.host.openejb.OpenEJBRuntimeModuleActivator
diff --git a/branches/sca-equinox/modules/host-openejb/src/test/java/org/apache/tuscany/sca/host/openejb/OpenEJBServerTestCase.java b/branches/sca-equinox/modules/host-openejb/src/test/java/org/apache/tuscany/sca/host/openejb/OpenEJBServerTestCase.java
new file mode 100644
index 0000000000..7d2301a770
--- /dev/null
+++ b/branches/sca-equinox/modules/host-openejb/src/test/java/org/apache/tuscany/sca/host/openejb/OpenEJBServerTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * 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.apache.tuscany.sca.host.openejb;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.ejb.EJBSessionBean;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OpenEJBServerTestCase extends TestCase {
+
+ public interface TestRemote {
+ String test(String s);
+ }
+
+ public static class TestImpl implements TestRemote {
+
+ public TestImpl() {
+ }
+
+ public String test(String s) {
+ return s.toUpperCase();
+ }
+
+ public void init() {
+ }
+
+ public void destroy() {
+ }
+ }
+
+ private OpenEJBServer server;
+
+ @Override
+ protected void setUp() throws Exception {
+ server = new OpenEJBServer();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ server.stop();
+ }
+
+ /**
+ * Verifies registration and invocation of a session bean
+ */
+ public void testStatelessSessionBean() throws Exception {
+ server.addSessionBean("TestBean", new EJBSessionBean(TestImpl.class, TestRemote.class));
+
+ Properties properties = new Properties(System.getProperties());
+ //properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
+ properties.put(Context.PROVIDER_URL, "ejbd://localhost:2888");
+ InitialContext ctx = new InitialContext(properties);
+ Object object = ctx.lookup("TestBeanRemote");
+ assertTrue(object instanceof TestRemote);
+
+ TestRemote testRemote = (TestRemote)object;
+ String s = testRemote.test("test");
+ assertEquals("TEST", s);
+ }
+
+}