You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/03/01 04:41:14 UTC
svn commit: r513120 [1/2] - in /incubator/openejb/trunk/openejb3: ./
assembly/openejb-standalone/src/main/resources/
container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/
container/openejb-core/src/main/java/org/apache/openejb/conf...
Author: dain
Date: Wed Feb 28 19:41:12 2007
New Revision: 513120
URL: http://svn.apache.org/viewvc?view=rev&rev=513120
Log:
Added support for 1.5 outbound connectors
Added default jms connection factory
Modified:
incubator/openejb/trunk/openejb3/assembly/openejb-standalone/src/main/resources/openejb.conf
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/FacilitiesInfo.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeploy.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProviderDescriptor.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/schema/service-jar.xsd
incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/RedeployTest.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/AnnotatedFieldInjectionStatefulBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/FieldInjectionStatefulBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/SetterInjectionStatefulBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/AnnotatedFieldInjectionStatelessBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/FieldInjectionStatelessBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/SetterInjectionStatelessBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulFieldInjectionTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulSetterInjectionTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessAnnotatedFieldInjectionTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessFieldInjectionTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessJndiEncTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessPojoContextLookupTests.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessSetterInjectionTests.java
incubator/openejb/trunk/openejb3/pom.xml
Modified: incubator/openejb/trunk/openejb3/assembly/openejb-standalone/src/main/resources/openejb.conf
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/assembly/openejb-standalone/src/main/resources/openejb.conf?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/assembly/openejb-standalone/src/main/resources/openejb.conf (original)
+++ incubator/openejb/trunk/openejb3/assembly/openejb-standalone/src/main/resources/openejb.conf Wed Feb 28 19:41:12 2007
@@ -214,6 +214,16 @@
</Connector>
-->
+
+<Resource id="Default JMS Resource Adapter">
+ # Broker address
+ ServerUrl vm://localhost
+</Resource>
+
+<Connector id="Default JMS Connection Factory">
+ ResourceAdapter Default JMS Resource Adapter
+</Connector>
+
<!--
#
# A registry listing of all the jars
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Wed Feb 28 19:41:12 2007
@@ -25,6 +25,8 @@
import org.apache.openejb.OpenEJB;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.UndeployException;
+import org.apache.openejb.resource.jdbc.JdbcManagedConnectionFactory;
+import org.apache.openejb.resource.GeronimoConnectionManagerFactory;
import org.apache.openejb.core.ConnectorReference;
import org.apache.openejb.core.CoreContainerSystem;
import org.apache.openejb.core.CoreDeploymentInfo;
@@ -44,6 +46,10 @@
import org.apache.openejb.util.proxy.ProxyManager;
import org.apache.xbean.recipe.ObjectRecipe;
import org.apache.xbean.recipe.StaticRecipe;
+import org.apache.xbean.recipe.Option;
+import org.apache.geronimo.connector.work.GeronimoWorkManager;
+import org.apache.geronimo.connector.GeronimoBootstrapContext;
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -51,6 +57,10 @@
import javax.persistence.EntityManagerFactory;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.work.WorkManager;
import javax.transaction.TransactionManager;
import javax.transaction.TransactionSynchronizationRegistry;
import java.io.File;
@@ -68,6 +78,9 @@
import java.util.TreeMap;
import java.util.Collection;
+import edu.emory.mathcs.backport.java.util.concurrent.Executor;
+import edu.emory.mathcs.backport.java.util.concurrent.Executors;
+
public class Assembler extends AssemblerTool implements org.apache.openejb.spi.Assembler {
public static final Logger logger = Logger.getInstance("OpenEJB.startup", Assembler.class.getPackage().getName());
@@ -262,6 +275,10 @@
createConnectionManager(connectionManagerInfo);
}
+ for (ResourceInfo resourceInfo : configInfo.facilities.resources) {
+ createResource(resourceInfo);
+ }
+
for (ConnectorInfo connectorInfo : configInfo.facilities.connectors) {
createConnector(connectorInfo);
}
@@ -619,24 +636,52 @@
}
public void createConnector(ConnectorInfo serviceInfo) throws OpenEJBException {
-
-
ObjectRecipe serviceRecipe = new ObjectRecipe(serviceInfo.className, serviceInfo.factoryMethod, serviceInfo.constructorArgs.toArray(new String[0]), null);
serviceRecipe.setAllProperties(serviceInfo.properties);
+ serviceRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
+
+ Object resourceAdapterId = serviceRecipe.getProperty("ResourceAdapter");
+ if (resourceAdapterId instanceof String) {
+ Object resourceAdapter = null;
+ try {
+ resourceAdapter = containerSystem.getJNDIContext().lookup("java:openejb/resourceAdapter/" + resourceAdapterId);
+ } catch (NamingException e) {
+ // handled below
+ }
+
+ if (resourceAdapter == null) {
+ throw new OpenEJBException("No existing resource adapter defined with id '" + resourceAdapterId + "'.");
+ }
+ if (!(resourceAdapter instanceof ResourceAdapter)) {
+ throw new OpenEJBException("Resource adapter defined with id '" + resourceAdapterId + "' is not an instance of ResourceAdapter, " +
+ "but is an instance of " + resourceAdapter.getClass());
+ }
+ serviceRecipe.setProperty("ResourceAdapter", resourceAdapter);
+ }
Object service = serviceRecipe.create();
Class interfce = serviceInterfaces.get(serviceInfo.serviceType);
checkImplementation(interfce, service.getClass(), serviceInfo.serviceType, serviceInfo.id);
- ConnectionManager connectionManager = SystemInstance.get().getComponent(ConnectionManager.class);
+ ConnectionManager connectionManager;
+ if ((ManagedConnectionFactory) service instanceof JdbcManagedConnectionFactory) {
+ connectionManager = SystemInstance.get().getComponent(ConnectionManager.class);
+ } else {
+ GeronimoConnectionManagerFactory connectionManagerFactory = new GeronimoConnectionManagerFactory();
+ connectionManagerFactory.setTransactionManager(transactionManager);
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader == null) classLoader = getClass().getClassLoader();
+ if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader();
+ connectionManagerFactory.setClassLoader(classLoader);
+ connectionManager = connectionManagerFactory.create();
+ }
+
if (connectionManager == null) {
throw new RuntimeException("Invalid connection manager specified for connector identity = " + serviceInfo.id);
}
- ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
-
- ConnectorReference reference = new ConnectorReference(connectionManager, managedConnectionFactory);
+ ConnectorReference reference = new ConnectorReference(connectionManager, (ManagedConnectionFactory) service);
try {
containerSystem.getJNDIContext().bind("java:openejb/" + serviceInfo.serviceType + "/" + serviceInfo.id, reference);
@@ -646,6 +691,64 @@
// Update the config tree
config.facilities.connectors.add(serviceInfo);
+ }
+
+ public void createResource(ResourceInfo serviceInfo) throws OpenEJBException {
+ // resource adapters only work with a geronimo transaction manager
+ if (!(transactionManager instanceof GeronimoTransactionManager)) {
+ throw new OpenEJBException("The use of a resource adapter requires a Geronimo transaction manager");
+ }
+ GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
+
+ // create the service
+ ObjectRecipe serviceRecipe = new ObjectRecipe(serviceInfo.className, serviceInfo.factoryMethod, serviceInfo.constructorArgs.toArray(new String[0]), null);
+ serviceRecipe.setAllProperties(serviceInfo.properties);
+ serviceRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
+ Object service = serviceRecipe.create();
+
+ // check the interface
+ Class interfce = serviceInterfaces.get(serviceInfo.serviceType);
+ checkImplementation(interfce, service.getClass(), serviceInfo.serviceType, serviceInfo.id);
+ ResourceAdapter resourceAdapter = (ResourceAdapter) service;
+
+ // create a thead pool
+ int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
+ if (threadPoolSize <= 0) throw new IllegalArgumentException("threadPoolSizes <= 0: " + threadPoolSize);
+ Executor threadPool = Executors.newFixedThreadPool(threadPoolSize);
+
+ // create a work manager which the resource adapter can use to dispatch messages or perform tasks
+ WorkManager workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, geronimoTransactionManager);
+
+ // wrap the work mananger and transaction manager in a bootstrap context (connector spec thing)
+ BootstrapContext bootstrapContext = new GeronimoBootstrapContext(workManager, geronimoTransactionManager);
+
+ // start the resource adapter
+ try {
+ resourceAdapter.start(bootstrapContext);
+ } catch (ResourceAdapterInternalException e) {
+ throw new OpenEJBException(e);
+ }
+
+ try {
+ containerSystem.getJNDIContext().bind("java:openejb/resourceAdapter/" + serviceInfo.id, resourceAdapter);
+ } catch (NamingException e) {
+ throw new OpenEJBException("Cannot bind resource adapter with id " + serviceInfo.id, e);
+ }
+
+ // Update the config tree
+ config.facilities.resources.add(serviceInfo);
+ }
+
+ private int getIntProperty(Properties properties, String propertyName, int defaultValue) {
+ String propertyValue = properties.getProperty(propertyName);
+ if (propertyValue == null) {
+ return defaultValue;
+ }
+ try {
+ return Integer.parseInt(propertyValue);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(propertyName + " is not an integer " + propertyValue);
+ }
}
public void createConnectionManager(ConnectionManagerInfo serviceInfo) throws OpenEJBException {
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java Wed Feb 28 19:41:12 2007
@@ -41,6 +41,7 @@
serviceInterfaces.put("TransactionManager", TransactionManager.class);
serviceInterfaces.put("ConnectionManager", javax.resource.spi.ConnectionManager.class);
serviceInterfaces.put("Connector", javax.resource.spi.ManagedConnectionFactory.class);
+ serviceInterfaces.put("Resource", javax.resource.spi.ResourceAdapter.class);
serviceInterfaces.put("Container", org.apache.openejb.Container.class);
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/FacilitiesInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/FacilitiesInfo.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/FacilitiesInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/FacilitiesInfo.java Wed Feb 28 19:41:12 2007
@@ -23,6 +23,7 @@
public ProxyFactoryInfo intraVmServer;
public final List<JndiContextInfo> remoteJndiContexts = new ArrayList<JndiContextInfo>();
+ public final List<ResourceInfo> resources = new ArrayList<ResourceInfo>();
public final List<ConnectorInfo> connectors = new ArrayList<ConnectorInfo>();
public final List<ConnectionManagerInfo> connectionManagers = new ArrayList<ConnectionManagerInfo>();
public TransactionServiceInfo transactionService;
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java Wed Feb 28 19:41:12 2007
@@ -16,8 +16,5 @@
*/
package org.apache.openejb.assembler.classic;
-public class ResourceInfo extends InfoObject {
-
- public String resourceID;
- public java.util.Properties properties;
+public class ResourceInfo extends ServiceInfo {
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeploy.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeploy.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeploy.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoDeploy.java Wed Feb 28 19:41:12 2007
@@ -17,12 +17,11 @@
*/
package org.apache.openejb.config;
-import java.util.List;
-
import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.config.sys.ServiceProvider;
import org.apache.openejb.assembler.classic.ConnectorInfo;
import org.apache.openejb.assembler.classic.ContainerInfo;
+import org.apache.openejb.assembler.classic.ResourceInfo;
+import org.apache.openejb.config.sys.Connector;
import org.apache.openejb.jee.ResourceRef;
import org.apache.openejb.jee.jpa.unit.Persistence;
import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
@@ -32,10 +31,25 @@
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.Messages;
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
public class AutoDeploy implements DynamicDeployer {
public static Messages messages = new Messages("org.apache.openejb.util.resources");
public static Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.util.resources");
+ private static final String DEFAULT_CONNECTOR_ID = "Default Unmanaged JDBC Database";
+ private static Map<String,String> defaultConnectorIds = new HashMap<String,String>();
+
+ static {
+ defaultConnectorIds.put("javax.sql.DataSource", DEFAULT_CONNECTOR_ID);
+ defaultConnectorIds.put("javax.jms.ConnectionFactory", "Default JMS Connection Factory");
+ defaultConnectorIds.put("javax.jms.QueueConnectionFactory", "Default JMS Connection Factory");
+ defaultConnectorIds.put("javax.jms.TopicConnectionFactory", "Default JMS Connection Factory");
+ }
+
private final ConfigurationFactory configFactory;
private boolean autoCreateContainers = true;
private boolean autoCreateConnectors = true;
@@ -137,8 +151,7 @@
ResourceLink link = ejbDeployment.getResourceLink(ref.getResRefName());
if (link == null) {
String resRefName = ref.getResRefName();
-
- String id = getDataSourceId(ejbDeployment.getDeploymentId(), resRefName);
+ String id = getConnectorId(ejbDeployment.getDeploymentId(), resRefName, ref.getResType());
logger.warning("Auto-linking res-ref-name '" + resRefName + "' in bean " + ejbDeployment.getDeploymentId() + " to Connector(id=" + id + ")");
link = new ResourceLink();
@@ -146,7 +159,7 @@
link.setResRefName(resRefName);
ejbDeployment.addResourceLink(link);
} else {
- String id = getDataSourceId(ejbDeployment.getDeploymentId(), link.getResId());
+ String id = getConnectorId(ejbDeployment.getDeploymentId(), link.getResId(), ref.getResType());
link.setResId(id);
link.setResRefName(ref.getResRefName());
}
@@ -163,11 +176,11 @@
Persistence persistence = persistenceModule.getPersistence();
for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
- String jtaDataSourceId = getDataSourceId(persistenceUnit.getName(), persistenceUnit.getJtaDataSource());
+ String jtaDataSourceId = getConnectorId(persistenceUnit.getName(), persistenceUnit.getJtaDataSource(), DataSource.class.getName());
if (jtaDataSourceId != null) {
persistenceUnit.setJtaDataSource("java:openejb/Connector/" + jtaDataSourceId);
}
- String nonJtaDataSourceId = getDataSourceId(persistenceUnit.getName(), persistenceUnit.getNonJtaDataSource());
+ String nonJtaDataSourceId = getConnectorId(persistenceUnit.getName(), persistenceUnit.getNonJtaDataSource(), DataSource.class.getName());
if (nonJtaDataSourceId != null) {
persistenceUnit.setNonJtaDataSource("java:openejb/Connector/" + nonJtaDataSourceId);
}
@@ -176,26 +189,56 @@
return persistenceModule;
}
- private String getDataSourceId(String beanName, String dataSource) throws OpenEJBException {
- if(dataSource == null){
+ private String getResourceId(String resourceId) throws OpenEJBException {
+ if(resourceId == null){
+ return null;
+ }
+
+ // try to lookup the resource in the container system
+ List<String> resourceIds = configFactory.getResourceIds();
+ if (resourceIds.contains(resourceId)) {
+ return resourceId;
+ }
+
+ // throw an exception or log an error
+ String message = "No existing resource adapter found while attempting to Auto-link unmapped resource adapter '" + resourceId + "'.";
+ if (!autoCreateConnectors){
+ throw new OpenEJBException(message);
+ }
+ logger.error(message);
+
+ // if there is a provider with the specified name. use it
+ if (!ServiceUtils.hasServiceProvider(resourceId)) {
+ throw new OpenEJBException("No existing resource adapter defined with id '" + resourceId + "'.");
+ }
+
+ // auto create the resource adapter
+ ResourceInfo resourceInfo = configFactory.configureService(ResourceInfo.class, resourceId, null, resourceId, null);
+ configFactory.install(resourceInfo);
+ return resourceInfo.id;
+ }
+
+ private String getConnectorId(String beanName, String connectorId, String type) throws OpenEJBException {
+ if(connectorId == null){
return null;
}
- if (dataSource.startsWith("java:comp/env")) {
- dataSource = dataSource.substring("java:comp/env".length());
+
+ if (connectorId.startsWith("java:comp/env")) {
+ connectorId = connectorId.substring("java:comp/env".length());
}
- List<String> connectorMap = configFactory.getConnectorIds();
- if (connectorMap.contains(dataSource)) {
- return dataSource;
+ List<String> connectorIds = configFactory.getConnectorIds(type);
+ if (connectorIds.contains(connectorId)) {
+ return connectorId;
}
- String name = dataSource.replaceFirst(".*/", "");
- if (connectorMap.contains(name)) {
+ String name = connectorId.replaceFirst(".*/", "");
+ if (connectorIds.contains(name)) {
return name;
}
// throw an exception or log an error
- String message = "No existing datasource found while attempting to Auto-link unmapped datasource '" + dataSource + "' for '" + beanName + "'. Looked for Datasource(id=" + dataSource + ") and Datasource(id=" + name + ")";
+ String message = "No existing connector found while attempting to Auto-link unmapped connector '" + connectorId + "' of type '" + type + "' for '" + beanName + "'. Looked for Conector(id=" + connectorId + ") and Connector(id=" + name + ")";
if (!autoCreateConnectors){
throw new OpenEJBException(message);
}
@@ -204,22 +247,43 @@
// if there is a provider with the specified name. use it
if (ServiceUtils.hasServiceProvider(name)) {
ConnectorInfo connectorInfo = configFactory.configureService(ConnectorInfo.class, name, null, name, null);
- configFactory.install(connectorInfo);
- return connectorInfo.id;
+ return installConnector(connectorInfo);
}
// if there is only one connector, use it
- // todo this check needs to be type specific to support JDBC and JMS
- if (connectorMap.size() > 0) {
- return connectorMap.get(0);
+ if (connectorIds.size() > 0) {
+ return connectorIds.get(0);
}
// Just use the default conector
- // todo again this needs to be type specific
- ConnectorInfo connectorInfo = configFactory.configureService(ConnectorInfo.class);
- logger.warning("Auto-creating a datasource with res-id " + connectorInfo.id + " for '" + beanName + "'. THERE IS LITTLE CHANCE THIS WILL WORK!");
+ Service service = getDefaultConnector(type);
+ ConnectorInfo connectorInfo = configFactory.configureService(service, ConnectorInfo.class);
+ logger.warning("Auto-creating a connector with id '" + connectorInfo.id + "' of type '" + type + " for '" + beanName + "'. THERE IS LITTLE CHANCE THIS WILL WORK!");
+ return installConnector(connectorInfo);
+ }
+
+ private String installConnector(ConnectorInfo connectorInfo) throws OpenEJBException {
+ String resourceAdapterId = connectorInfo.properties.getProperty("ResourceAdapter");
+ if (resourceAdapterId != null) {
+ String newResourceId = getResourceId(resourceAdapterId);
+ if (resourceAdapterId != newResourceId) {
+ connectorInfo.properties.setProperty("ResourceAdapter", newResourceId);
+ }
+ }
+
configFactory.install(connectorInfo);
return connectorInfo.id;
+ }
+
+ private Service getDefaultConnector(String type) {
+ String providerId = defaultConnectorIds.get(type);
+ if (providerId == null) {
+ providerId = DEFAULT_CONNECTOR_ID;
+ }
+ Service service = new Connector();
+ service.setProvider(providerId);
+ service.setId(providerId);
+ return service;
}
private String getUsableContainer(Class<? extends ContainerInfo> containerInfoType) {
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Wed Feb 28 19:41:12 2007
@@ -54,6 +54,7 @@
import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.assembler.classic.ResourceInfo;
import org.apache.openejb.config.sys.ConnectionManager;
import org.apache.openejb.config.sys.Connector;
import org.apache.openejb.config.sys.Container;
@@ -63,6 +64,7 @@
import org.apache.openejb.config.sys.SecurityService;
import org.apache.openejb.config.sys.ServiceProvider;
import org.apache.openejb.config.sys.TransactionManager;
+import org.apache.openejb.config.sys.Resource;
import org.apache.openejb.jee.ApplicationClient;
import org.apache.openejb.jee.jpa.EntityMappings;
import org.apache.openejb.jee.jpa.JpaJaxbUtil;
@@ -173,6 +175,15 @@
}
}
+ protected void install(ResourceInfo serviceInfo) throws OpenEJBException {
+ if (sys != null) {
+ sys.facilities.resources.add(serviceInfo);
+ } else if (!offline) {
+ Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
+ assembler.createResource(serviceInfo);
+ }
+ }
+
protected void install(ConnectorInfo serviceInfo) throws OpenEJBException {
if (sys != null) {
sys.facilities.connectors.add(serviceInfo);
@@ -205,8 +216,12 @@
sys.facilities.transactionService = configureService(openejb.getTransactionService(), TransactionServiceInfo.class);
- for (Connector connector : openejb.getConnector()) {
+ for (Resource resource : openejb.getResource()) {
+ ResourceInfo resourceInfo = configureService(resource, ResourceInfo.class);
+ sys.facilities.resources.add(resourceInfo);
+ }
+ for (Connector connector : openejb.getConnector()) {
ConnectorInfo connectorInfo = configureService(connector, ConnectorInfo.class);
sys.facilities.connectors.add(connectorInfo);
}
@@ -434,7 +449,7 @@
}
- private <T extends ServiceInfo>T configureService(Service service, Class<? extends T> type) throws OpenEJBException {
+ public <T extends ServiceInfo>T configureService(Service service, Class<? extends T> type) throws OpenEJBException {
if (service == null) {
return configureService(type);
}
@@ -452,14 +467,6 @@
* 3. If providerId is null, attempt to load the specified provider using the 'serviceId' as the 'providerId'
* 4. If this fails, check the hardcoded defaults for a default providerId using the supplied 'type'
* 5. If this fails, throw NoSuchProviderException
- *
- * @param type required
- * @param serviceId required
- * @param declaredProperties optional
- * @param providerId optional
- * @param serviceType optional
- * @return
- * @throws OpenEJBException
*/
public <T extends ServiceInfo>T configureService(Class<? extends T> type, String serviceId, Properties declaredProperties, String providerId, String serviceType) throws OpenEJBException {
if (type == null) throw new NullPointerException("type");
@@ -617,28 +624,92 @@
}
+ protected List<String> getResourceIds() {
+ List<String> resourceIds = new ArrayList<String>();
+
+ OpenEjbConfiguration runningConfig = getRunningConfig();
+ for (ResourceInfo connectorInfo : runningConfig.facilities.resources) {
+ resourceIds.add(connectorInfo.id);
+ }
+
+ if (sys != null) {
+ for (ResourceInfo connectorInfo : sys.facilities.resources) {
+ resourceIds.add(connectorInfo.id);
+ }
+
+ // The only time we'd have one of these is if we were building
+ // the above sys instance
+ if (openejb != null) {
+ for (Resource connector : openejb.getResource()) {
+ resourceIds.add(connector.getId());
+ }
+ }
+ }
+ return resourceIds;
+ }
+
protected List<String> getConnectorIds() {
+ return getConnectorIds(null);
+ }
+
+ protected List<String> getConnectorIds(String type) {
List<String> connectorIds = new ArrayList<String>();
OpenEjbConfiguration runningConfig = getRunningConfig();
for (ConnectorInfo connectorInfo : runningConfig.facilities.connectors) {
- connectorIds.add(connectorInfo.id);
+ if (isConnectionType(connectorInfo.properties, type)) {
+ connectorIds.add(connectorInfo.id);
+ }
}
if (sys != null) {
for (ConnectorInfo connectorInfo : sys.facilities.connectors) {
- connectorIds.add(connectorInfo.id);
+ if (isConnectionType(connectorInfo.properties, type)) {
+ connectorIds.add(connectorInfo.id);
+ }
}
// The only time we'd have one of these is if we were building
// the above sys instance
if (openejb != null) {
for (Connector connector : openejb.getConnector()) {
- connectorIds.add(connector.getId());
+ if (isConnectionType(connector, type)) {
+ connectorIds.add(connector.getId());
+ }
}
}
}
return connectorIds;
+ }
+
+ private static boolean isConnectionType(Properties properties, String type) {
+ if (type == null) return true;
+
+ String connectionInterfaces = properties.getProperty("ConnectionInterface");
+ if (connectionInterfaces == null) return false;
+
+ for (String connectionInterface : connectionInterfaces.split(" *, *")) {
+ if (connectionInterface.equals(type)) return true;
+ }
+ return false;
+ }
+
+ private static boolean isConnectionType(Connector connector, String type) {
+ if (type == null) return true;
+
+ Properties properties = new Properties();
+ if (connector.getContent() != null) {
+ String content = connector.getContent();
+ ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes());
+
+ try {
+ properties.load(in);
+ } catch (IOException ex) {
+ }
+
+ }
+
+ return isConnectionType(properties, type);
}
protected List<String> getContainerIds() {
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProviderDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProviderDescriptor.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProviderDescriptor.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProviderDescriptor.java Wed Feb 28 19:41:12 2007
@@ -159,7 +159,7 @@
{
StringValidator typeValidator = new StringValidator();
typeValidator.setWhiteSpace("preserve");
- typeValidator.setPattern("Container|Proxy|Security|Transaction|Connector|ConnectionManager|JNDI");
+ typeValidator.setPattern("Container|Proxy|Security|Transaction|Resource|Connector|ConnectionManager|JNDI");
fieldValidator.setValidator(typeValidator);
}
desc.setValidator(fieldValidator);
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java Wed Feb 28 19:41:12 2007
@@ -150,6 +150,11 @@
public GenericConnectionManager create() {
PoolingSupport poolingSupport = createPoolingSupport();
+
+ ClassLoader classLoader = this.classLoader;
+ if (classLoader == null) Thread.currentThread().getContextClassLoader();
+ if (classLoader == null) classLoader = getClass().getClassLoader();
+ if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader();
GenericConnectionManager connectionManager = new GenericConnectionManager(
createTransactionSupport(),
poolingSupport,
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml Wed Feb 28 19:41:12 2007
@@ -254,6 +254,8 @@
Password
Unmanaged false
+
+ ConnectionInterface javax.sql.DataSource
</ServiceProvider>
<ServiceProvider
@@ -283,6 +285,33 @@
Password
Unmanaged true
+
+ ConnectionInterface javax.sql.DataSource
+ </ServiceProvider>
+
+ <!--
+ # ================================================
+ # Default JMS
+ # ================================================
+ -->
+ <ServiceProvider
+ id="Default JMS Resource Adapter"
+ provider-type="Resource"
+ class-name="org.apache.activemq.ra.ActiveMQResourceAdapter">
+
+ # Broker address
+ #ServerUrl tcp://localhost:61616
+ ServerUrl vm://localhost
+ </ServiceProvider>
+
+ <ServiceProvider
+ id="Default JMS Connection Factory"
+ provider-type="Connector"
+ class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory">
+
+ ResourceAdapter Default JMS Resource Adapter
+
+ ConnectionInterface javax.jms.ConnectionFactory, javax.jms.QueueConnectionFactory, javax.jms.TopicConnectionFactory
</ServiceProvider>
<!--
@@ -295,12 +324,5 @@
provider-type="ConnectionManager"
constructor="transactionManager"
class-name="org.apache.openejb.resource.SharedLocalConnectionManager"/>
-
- <!--<ServiceProvider
- id="Default Local TX ConnectionManager"
- provider-type="ConnectionManager"
- class-name="org.apache.openejb.resource.GeronimoConnectionManagerFactory"
- factory-name="create"/>-->
-
</ServiceJar>
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf Wed Feb 28 19:41:12 2007
@@ -204,6 +204,15 @@
</Connector>
-->
+<Resource id="Default JMS Resource Adapter">
+ # Broker address
+ ServerUrl vm://localhost
+</Resource>
+
+<Connector id="Default JMS Connection Factory">
+ ResourceAdapter Default JMS Resource Adapter
+</Connector>
+
<!--
#
# A registry listing of all the jars
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/schema/service-jar.xsd
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/schema/service-jar.xsd?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/schema/service-jar.xsd (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/schema/service-jar.xsd Wed Feb 28 19:41:12 2007
@@ -86,7 +86,7 @@
<!-- ProviderTypes -->
<xsd:simpleType name="ProviderTypes">
<xsd:restriction base="xsd:string">
- <xsd:pattern value="Container|Proxy|Security|Transaction|Connector|ConnectionManager|JNDI"/>
+ <xsd:pattern value="Container|Proxy|Security|Transaction|Resource|Connector|ConnectionManager|JNDI"/>
</xsd:restriction>
</xsd:simpleType>
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/RedeployTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/RedeployTest.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/RedeployTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/RedeployTest.java Wed Feb 28 19:41:12 2007
@@ -18,6 +18,8 @@
import junit.framework.TestCase;
import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.sys.Connector;
+import org.apache.openejb.config.sys.Resource;
import org.apache.openejb.client.LocalInitialContextFactory;
import org.apache.openejb.test.stateful.AnnotatedFieldInjectionStatefulBean;
import org.apache.openejb.test.stateless.EncStatelessHome;
@@ -49,11 +51,28 @@
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createConnectionManager(config.configureService(ConnectionManagerInfo.class));
+
+ // managed JDBC
assembler.createConnector(config.configureService(ConnectorInfo.class));
- ConnectorInfo connectorInfo = config.configureService(ConnectorInfo.class);
- connectorInfo.id = "Default Unmanaged JDBC Database";
- assembler.createConnector(connectorInfo);
+ // unmanaged JDBC
+ Connector connector = new Connector();
+ connector.setId("Default Unmanaged JDBC Database");
+ connector.setProvider("Default Unmanaged JDBC Database");
+ assembler.createConnector(config.configureService(connector, ConnectorInfo.class));
+
+ // JMS
+ Resource resource = new Resource();
+ resource.setId("Default JMS Resource Adapter");
+ resource.setProvider("Default JMS Resource Adapter");
+ assembler.createResource(config.configureService(resource, ResourceInfo.class));
+
+ connector = new Connector();
+ connector.setId("Default JMS Connection Factory");
+ connector.setProvider("Default JMS Connection Factory");
+ assembler.createConnector(config.configureService(connector, ConnectorInfo.class));
+
+ // containers
assembler.createContainer(config.configureService(BmpEntityContainerInfo.class));
assembler.createContainer(config.configureService(CmpEntityContainerInfo.class));
assembler.createContainer(config.configureService(StatefulSessionContainerInfo.class));
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java Wed Feb 28 19:41:12 2007
@@ -31,10 +31,17 @@
import javax.ejb.EJBException;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
-import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import java.rmi.RemoteException;
/**
@@ -371,12 +378,49 @@
}
}
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ Object obj = ejbContext.lookup("jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ejbContext.lookup("TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ejbContext.lookup("QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
+ }
+
public void lookupPersistenceUnit() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+ EntityManagerFactory emf = (EntityManagerFactory)ejbContext.lookup("persistence/TestUnit");
Assert.assertNotNull("The EntityManagerFactory is null", emf );
} catch (Exception e){
@@ -390,9 +434,7 @@
public void lookupPersistenceContext() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+ EntityManager em = (EntityManager)ejbContext.lookup("persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java Wed Feb 28 19:41:12 2007
@@ -25,6 +25,14 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -412,6 +420,7 @@
throw new TestFailureException(afe);
}
}
+
public void lookupResource() throws TestFailureException{
try{
try{
@@ -426,6 +435,47 @@
} catch (AssertionFailedError afe){
throw new TestFailureException(afe);
}
+ }
+
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ InitialContext ctx = new InitialContext();
+ Assert.assertNotNull("The InitialContext is null", ctx);
+ Object obj = ctx.lookup("java:comp/env/jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
}
public void lookupPersistenceUnit() throws TestFailureException{
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java Wed Feb 28 19:41:12 2007
@@ -37,6 +37,7 @@
public void lookupStatefulBusinessRemote() throws TestFailureException, RemoteException;
public void lookupResource() throws TestFailureException, RemoteException;
+ public void lookupJMSConnectionFactory() throws TestFailureException, RemoteException;
public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
public void lookupPersistenceContext() throws TestFailureException, RemoteException;
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java Wed Feb 28 19:41:12 2007
@@ -31,10 +31,17 @@
import javax.ejb.EJBException;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
-import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import java.rmi.RemoteException;
import java.util.StringTokenizer;
@@ -348,12 +355,49 @@
}
}
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ Object obj = ejbContext.lookup("jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ejbContext.lookup("TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ejbContext.lookup("QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
+ }
+
public void lookupPersistenceUnit() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+ EntityManagerFactory emf = (EntityManagerFactory)ejbContext.lookup("persistence/TestUnit");
Assert.assertNotNull("The EntityManagerFactory is null", emf );
} catch (Exception e){
@@ -367,9 +411,7 @@
public void lookupPersistenceContext() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+ EntityManager em = (EntityManager)ejbContext.lookup("persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java Wed Feb 28 19:41:12 2007
@@ -23,6 +23,14 @@
import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -396,6 +404,47 @@
} catch (AssertionFailedError afe) {
throw new TestFailureException(afe);
}
+ }
+
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ InitialContext ctx = new InitialContext();
+ Assert.assertNotNull("The InitialContext is null", ctx);
+ Object obj = ctx.lookup("java:comp/env/jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
}
public void lookupPersistenceUnit() throws TestFailureException{
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java Wed Feb 28 19:41:12 2007
@@ -26,6 +26,14 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -405,6 +413,47 @@
} catch (AssertionFailedError afe){
throw new TestFailureException(afe);
}
+ }
+
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ InitialContext ctx = new InitialContext();
+ Assert.assertNotNull("The InitialContext is null", ctx);
+ Object obj = ctx.lookup("java:comp/env/jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
}
public void lookupPersistenceUnit() throws TestFailureException{
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java Wed Feb 28 19:41:12 2007
@@ -37,6 +37,7 @@
public void lookupStatefulBusinessRemote() throws TestFailureException, RemoteException;
public void lookupResource() throws TestFailureException, RemoteException;
+ public void lookupJMSConnectionFactory() throws TestFailureException, RemoteException;
public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
public void lookupPersistenceContext() throws TestFailureException, RemoteException;
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/AnnotatedFieldInjectionStatefulBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/AnnotatedFieldInjectionStatefulBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/AnnotatedFieldInjectionStatefulBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/AnnotatedFieldInjectionStatefulBean.java Wed Feb 28 19:41:12 2007
@@ -33,6 +33,13 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
+import javax.jms.ConnectionFactory;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.JMSException;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -69,6 +76,12 @@
private Character chaaracter = 'D';
@Resource
private DataSource daataSource;
+ @Resource
+ private ConnectionFactory coonnectionFactory;
+ @Resource
+ private QueueConnectionFactory queueCoonnectionFactory;
+ @Resource
+ private TopicConnectionFactory topicCoonnectionFactory;
@PersistenceUnit(unitName = "openjpa-test-unit")
private EntityManagerFactory emf;
@PersistenceContext(unitName = "openjpa-test-unit")
@@ -248,6 +261,31 @@
} catch (AssertionFailedError afe) {
throw new TestFailureException(afe);
}
+ }
+
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ testJmsConnection(coonnectionFactory.createConnection());
+ testJmsConnection(queueCoonnectionFactory.createConnection());
+ testJmsConnection(topicCoonnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(javax.jms.Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
}
public void lookupPersistenceUnit() throws TestFailureException {
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java Wed Feb 28 19:41:12 2007
@@ -31,11 +31,18 @@
import javax.ejb.SessionContext;
import javax.ejb.SessionSynchronization;
import javax.ejb.CreateException;
-import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
-import javax.transaction.UserTransaction;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
+import javax.naming.InitialContext;
import java.rmi.RemoteException;
/**
@@ -341,12 +348,49 @@
}
}
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ Object obj = ejbContext.lookup("jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ejbContext.lookup("TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ejbContext.lookup("QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
+ }
+
public void lookupPersistenceUnit() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+ EntityManagerFactory emf = (EntityManagerFactory)ejbContext.lookup("persistence/TestUnit");
Assert.assertNotNull("The EntityManagerFactory is null", emf );
} catch (Exception e){
@@ -360,9 +404,7 @@
public void lookupPersistenceContext() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+ EntityManager em = (EntityManager)ejbContext.lookup("persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java Wed Feb 28 19:41:12 2007
@@ -27,10 +27,17 @@
import javax.ejb.EJBContext;
import javax.ejb.SessionContext;
import javax.sql.DataSource;
-import javax.naming.InitialContext;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
-import javax.transaction.UserTransaction;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
+import javax.naming.InitialContext;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -314,12 +321,49 @@
}
}
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ Object obj = ejbContext.lookup("jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ejbContext.lookup("TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ejbContext.lookup("QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
+ }
+
public void lookupPersistenceUnit() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+ EntityManagerFactory emf = (EntityManagerFactory)ejbContext.lookup("persistence/TestUnit");
Assert.assertNotNull("The EntityManagerFactory is null", emf );
} catch (Exception e){
@@ -333,9 +377,7 @@
public void lookupPersistenceContext() throws TestFailureException{
try{
try{
- InitialContext ctx = new InitialContext();
- Assert.assertNotNull("The InitialContext is null", ctx);
- EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+ EntityManager em = (EntityManager)ejbContext.lookup("persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java Wed Feb 28 19:41:12 2007
@@ -28,6 +28,14 @@
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import javax.transaction.UserTransaction;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
@@ -390,6 +398,47 @@
} catch (AssertionFailedError afe){
throw new TestFailureException(afe);
}
+ }
+
+ public void lookupJMSConnectionFactory() throws TestFailureException{
+ try{
+ try{
+ InitialContext ctx = new InitialContext();
+ Assert.assertNotNull("The InitialContext is null", ctx);
+ Object obj = ctx.lookup("java:comp/env/jms");
+ Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+ ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+ testJmsConnection(connectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/TopicCF");
+ Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+ TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+ testJmsConnection(topicConnectionFactory.createConnection());
+
+ obj = ctx.lookup("java:comp/env/QueueCF");
+ Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+ Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+ QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+ testJmsConnection(queueConnectionFactory.createConnection());
+ } catch (Exception e){
+ e.printStackTrace();
+ Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ } catch (AssertionFailedError afe){
+ throw new TestFailureException(afe);
+ }
+ }
+
+ private void testJmsConnection(Connection connection) throws JMSException {
+ Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ Topic topic = session.createTopic("test");
+ MessageProducer producer = session.createProducer(topic);
+ producer.send(session.createMessage());
+ producer.close();
+ session.close();
+ connection.close();
}
public void lookupPersistenceUnit() throws TestFailureException{
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java?view=diff&rev=513120&r1=513119&r2=513120
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java Wed Feb 28 19:41:12 2007
@@ -37,6 +37,7 @@
public void lookupStatefulBusinessRemote() throws TestFailureException, RemoteException;
public void lookupResource() throws TestFailureException, RemoteException;
+ public void lookupJMSConnectionFactory() throws TestFailureException, RemoteException;
public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
public void lookupPersistenceContext() throws TestFailureException, RemoteException;
public void lookupSessionContext() throws TestFailureException,RemoteException;