tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r681831 - in /openejb/trunk/openejb3/container: openejb-core/src/main/java/org/apache/openejb/config/ openejb-core/src/main/java/org/apache/openejb/config/sys/ openejb-core/src/test/java/org/apache/openejb/core/mdb/ openejb-jee/src/main/jav...
Date Fri, 01 Aug 2008 21:22:07 GMT
Author: dblevins
Date: Fri Aug  1 14:22:06 2008
New Revision: 681831

URL: http://svn.apache.org/viewvc?rev=681831&view=rev
Log:
Fixed the handling of deployed connector modules and the related creation of resource adapters and mdb containers and the processing of the mdb activation config.  Code no longer tries to force everything into JMS style thinking.

Relates to: OPENEJB-862: Usage of Quartz quarts-ra.rar


Added:
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/JmsMdbContainerTest.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProvider.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ActivationSpec.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/Connector.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/InboundResource.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageAdapter.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageListener.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/RequiredConfigProperty.java
    openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceAdapter.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java Fri Aug  1 14:22:06 2008
@@ -32,6 +32,9 @@
 import org.apache.openejb.assembler.classic.HandlerChainInfo;
 import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.sys.Resource;
+import org.apache.openejb.config.sys.ServiceProvider;
+import org.apache.openejb.config.sys.Container;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Messages;
@@ -89,11 +92,23 @@
         AppInfo appInfo = new AppInfo();
 
         //
+        //  J2EE Connectors
+        //
+        buildConnectorModules(appModule, appInfo);
+
+        //
         //  Persistence Units
         //
         buildPersistenceModules(appModule, appInfo);
 
 
+        List<String> containerIds = configFactory.getContainerIds();
+        for (ConnectorInfo connectorInfo : appInfo.connectors) {
+            for (MdbContainerInfo containerInfo : connectorInfo.inbound) {
+                containerIds.add(containerInfo.id);
+            }
+        }
+
         //
         //  EJB Jars
         //
@@ -107,7 +122,8 @@
                 for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
                     EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
 
-                    if (!configFactory.getContainerIds().contains(d.getContainerId()) && !skipMdb(bean)) {
+
+                    if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                         String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName());
                         logger.fatal(msg);
                         throw new OpenEJBException(msg);
@@ -157,11 +173,6 @@
         buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
 
         //
-        //  J2EE Connectors
-        //
-        buildConnectorModules(appModule, appInfo);
-
-        //
         //  Webapps
         //
         buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
@@ -245,7 +256,9 @@
         }
     }
 
-    private void buildConnectorModules(AppModule appModule, AppInfo appInfo) {
+    private void buildConnectorModules(AppModule appModule, AppInfo appInfo) throws OpenEJBException {
+        String appId = appModule.getModuleId();
+
         for (ConnectorModule connectorModule : appModule.getResourceModules()) {
             //
             // DEVELOPERS NOTE:  if you change the id generation code here, you must change
@@ -267,30 +280,30 @@
                 try {
                     connectorInfo.libs.add(file.getCanonicalPath());
                 } catch (IOException e) {
-                    throw new IllegalArgumentException("Invalid application lib path " + file.getAbsolutePath());                    
+                    throw new IllegalArgumentException("Invalid application lib path " + file.getAbsolutePath());
                 }
             }
 
             ResourceAdapter resourceAdapter = connector.getResourceAdapter();
             if (resourceAdapter.getResourceAdapterClass() != null) {
-                ResourceInfo resourceInfo = new ResourceInfo();
-                resourceInfo.service = "Resource";
-                if (resourceAdapter.getId() != null) {
-                    resourceInfo.id = resourceAdapter.getId();
-                } else {
-                    resourceInfo.id = connectorModule.getModuleId() + "RA";
-                }
-                resourceInfo.className = resourceAdapter.getResourceAdapterClass();
-                resourceInfo.properties = new Properties();
+                String id = getId(connectorModule);
+                String className = resourceAdapter.getResourceAdapterClass();
+
+                ServiceProvider provider = new ServiceProvider(className, id, "Resource");
+                provider.getTypes().add(className);
+
+                ServiceUtils.registerServiceProvider(appId, provider);
+
+                Resource resource = new Resource(id, className, appId + "#" + id);
+
                 for (ConfigProperty property : resourceAdapter.getConfigProperty()) {
                     String name = property.getConfigPropertyName();
                     String value = property.getConfigPropertyValue();
                     if (value != null) {
-                        resourceInfo.properties.setProperty(name, value);
+                        resource.getProperties().setProperty(name, value);
                     }
                 }
-                resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
-                connectorInfo.resourceAdapter = resourceInfo;
+                connectorInfo.resourceAdapter = configFactory.configureService(resource, ResourceInfo.class);
             }
 
             OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
@@ -308,28 +321,29 @@
                         break;
                 }
                 for (ConnectionDefinition connection : outbound.getConnectionDefinition()) {
-                    ResourceInfo resourceInfo = new ResourceInfo();
-                    resourceInfo.service = "Resource";
-                    if (connection.getId() != null) {
-                        resourceInfo.id = connection.getId();
-                    } else if (outbound.getConnectionDefinition().size() == 1) {
-                        resourceInfo.id = connectorModule.getModuleId();
-                    } else {
-                        resourceInfo.id = connectorModule.getModuleId() + "-" + connection.getConnectionFactoryInterface();
-                    }
-                    resourceInfo.className = connection.getManagedConnectionFactoryClass();
-                    resourceInfo.types.add(connection.getConnectionFactoryInterface());
-                    resourceInfo.properties = new Properties();
+
+                    String id = getId(connection, outbound, connectorModule);
+                    String className = connection.getManagedConnectionFactoryClass();
+                    String type = connection.getConnectionFactoryInterface();
+
+                    ServiceProvider provider = new ServiceProvider(className, id, "Resource");
+                    provider.getTypes().add(type);
+
+                    ServiceUtils.registerServiceProvider(appId, provider);
+
+                    Resource resource = new Resource(id, type, appId + "#" + id);
+                    Properties properties = resource.getProperties();
                     for (ConfigProperty property : connection.getConfigProperty()) {
                         String name = property.getConfigPropertyName();
                         String value = property.getConfigPropertyValue();
                         if (value != null) {
-                            resourceInfo.properties.setProperty(name, value);
+                            properties.setProperty(name, value);
                         }
                     }
-                    resourceInfo.properties.setProperty("TransactionSupport", transactionSupport);
-                    resourceInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
-                    resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
+                    properties.setProperty("TransactionSupport", transactionSupport);
+                    properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
+
+                    ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
                     connectorInfo.outbound.add(resourceInfo);
                 }
             }
@@ -337,53 +351,41 @@
             InboundResource inbound = resourceAdapter.getInboundResourceAdapter();
             if (inbound != null) {
                 for (MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
-                    MdbContainerInfo mdbContainerInfo = new MdbContainerInfo();
-                    mdbContainerInfo.service = "Container";
-                    if (messageListener.getId() != null) {
-                        mdbContainerInfo.id = messageListener.getId();
-                    } else if (inbound.getMessageAdapter().getMessageListener().size() == 1) {
-                        mdbContainerInfo.id = connectorModule.getModuleId();
-                    } else {
-                        mdbContainerInfo.id = connectorModule.getModuleId() + "-" + messageListener.getMessageListenerType();
-                    }
+                    String id = getId(messageListener, inbound, connectorModule);
+
+                    Container container = new Container(id, "MESSAGE", null);
 
-                    mdbContainerInfo.properties = new Properties();
-                    mdbContainerInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
-                    mdbContainerInfo.properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
-                    mdbContainerInfo.properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
-
-                    // todo provider system should fill in this information
-                    mdbContainerInfo.types.add("MESSAGE");
-                    mdbContainerInfo.className = "org.apache.openejb.core.mdb.MdbContainer";
-                    mdbContainerInfo.constructorArgs.addAll(Arrays.asList("id", "transactionManager", "securityService", "ResourceAdapter", "MessageListenerInterface", "ActivationSpecClass", "InstanceLimit"));
-                    mdbContainerInfo.properties.setProperty("InstanceLimit", "10");
+                    Properties properties = container.getProperties();
+                    properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
+                    properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
+                    properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
 
-                    mdbContainerInfo.properties.putAll(ConfigurationFactory.getSystemProperties(mdbContainerInfo.id, "CONTAINER"));
+                    MdbContainerInfo mdbContainerInfo = configFactory.configureService(container, MdbContainerInfo.class);
                     connectorInfo.inbound.add(mdbContainerInfo);
                 }
             }
 
             for (AdminObject adminObject : resourceAdapter.getAdminObject()) {
-                ResourceInfo resourceInfo = new ResourceInfo();
-                resourceInfo.service = "Resource";
-                if (adminObject.getId() != null) {
-                    resourceInfo.id = adminObject.getId();
-                } else if (resourceAdapter.getAdminObject().size() == 1) {
-                    resourceInfo.id = connectorModule.getModuleId();
-                } else {
-                    resourceInfo.id = connectorModule.getModuleId() + "-" + adminObject.getAdminObjectInterface();
-                }
-                resourceInfo.className = adminObject.getAdminObjectClass();
-                resourceInfo.types.add(adminObject.getAdminObjectInterface());
-                resourceInfo.properties = new Properties();
+
+                String id = getId(adminObject, resourceAdapter, connectorModule);
+                String className = adminObject.getAdminObjectClass();
+                String type = adminObject.getAdminObjectInterface();
+
+                ServiceProvider provider = new ServiceProvider(className, id, "Resource");
+                provider.getTypes().add(type);
+
+                ServiceUtils.registerServiceProvider(appId, provider);
+
+                Resource resource = new Resource(id, type, appId + "#" + id);
+                Properties properties = resource.getProperties();
                 for (ConfigProperty property : adminObject.getConfigProperty()) {
                     String name = property.getConfigPropertyName();
                     String value = property.getConfigPropertyValue();
                     if (value != null) {
-                        resourceInfo.properties.setProperty(name, value);
+                        properties.setProperty(name, value);
                     }
                 }
-                resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
+                ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
                 connectorInfo.adminObject.add(resourceInfo);
             }
 
@@ -391,6 +393,50 @@
         }
     }
 
+    private String getId(AdminObject adminObject, ResourceAdapter resourceAdapter, ConnectorModule connectorModule) {
+        String id;
+        if (adminObject.getId() != null) {
+            id = adminObject.getId();
+        } else if (resourceAdapter.getAdminObject().size() == 1) {
+            id = connectorModule.getModuleId();
+        } else {
+            id = connectorModule.getModuleId() + "-" + adminObject.getAdminObjectInterface();
+        }
+        return id;
+    }
+
+    private String getId(MessageListener messageListener, InboundResource inbound, ConnectorModule connectorModule) {
+        String id;
+        if (messageListener.getId() != null) {
+            id = messageListener.getId();
+        } else if (inbound.getMessageAdapter().getMessageListener().size() == 1) {
+            id = connectorModule.getModuleId();
+        } else {
+            id = connectorModule.getModuleId() + "-" + messageListener.getMessageListenerType();
+        }
+        return id;
+    }
+
+    private String getId(ConnectionDefinition connection, OutboundResourceAdapter outbound, ConnectorModule connectorModule) {
+        String id;
+        if (connection.getId() != null) {
+            id = connection.getId();
+        } else if (outbound.getConnectionDefinition().size() == 1) {
+            id = connectorModule.getModuleId();
+        } else {
+            id = connectorModule.getModuleId() + "-" + connection.getConnectionFactoryInterface();
+        }
+        return id;
+    }
+
+    private String getId(ConnectorModule connectorModule) {
+        String id = connectorModule.getConnector().getResourceAdapter().getId();
+        if (id == null) {
+            id = connectorModule.getModuleId() + "RA";
+        }
+        return id;
+    }
+
     private void buildPersistenceModules(AppModule appModule, AppInfo appInfo) {
         for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
             String rootUrl = persistenceModule.getRootUrl();

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java Fri Aug  1 14:22:06 2008
@@ -310,17 +310,20 @@
             if (bean instanceof MessageDrivenBean) {
                 MessageDrivenBean mdb = (MessageDrivenBean) bean;
 
+                if (mdb.getActivationConfig() == null) {
+                    mdb.setActivationConfig(new ActivationConfig());
+                }
+
+                if (!isJms(mdb)) continue;
+
                 EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
                 if (ejbDeployment == null) {
                     throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
                 }
 
-                if (mdb.getActivationConfig() == null) {
-                    mdb.setActivationConfig(new ActivationConfig());
-                }
-
                 Properties properties = mdb.getActivationConfig().toProperties();
 
+
                 // destination
                 String destination = properties.getProperty("destination", properties.getProperty("destinationName"));
                 if (destination == null) {
@@ -356,10 +359,16 @@
                         mdb.getActivationConfig().addProperty("subscriptionName", ejbDeployment.getDeploymentId() + "_subscription");
                     }
                 }
+
             }
         }
     }
 
+    private boolean isJms(MessageDrivenBean mdb) {
+        String messagingType = mdb.getMessagingType();
+        return (messagingType != null && messagingType.startsWith("javax.jms"));
+    }
+
     /**
      * Set resource id in all message-destination-refs and MDBs that are using message destination links.
      */
@@ -521,6 +530,8 @@
                 if (bean instanceof MessageDrivenBean) {
                     MessageDrivenBean mdb = (MessageDrivenBean) bean;
 
+                    if (!isJms(mdb)) continue;
+
                     EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
                     if (ejbDeployment == null) {
                         throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
@@ -697,7 +708,9 @@
             }
 
             // create the container if it doesn't exist
-            if (!configFactory.getContainerIds().contains(ejbDeployment.getContainerId()) && !skipMdb(bean)) {
+            List<String> containerIds = configFactory.getContainerIds();
+            containerIds.addAll(appResources.getContainerIds());
+            if (!containerIds.contains(ejbDeployment.getContainerId()) && !skipMdb(bean)) {
                 createContainer(containerInfoType, ejbDeployment, bean);
             }
 
@@ -1584,5 +1597,13 @@
             }
             return Collections.emptyList();
         }
+
+        public List<String> getContainerIds() {
+            ArrayList<String> ids = new ArrayList<String>();
+            for (List<String> list : containerIdsByType.values()) {
+                ids.addAll(list);
+            }
+            return ids;
+        }
     }
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java Fri Aug  1 14:22:06 2008
@@ -41,6 +41,10 @@
     private final List<URL> libraries = new ArrayList<URL>();
     private final Set<String> watchedResources = new TreeSet<String>();
 
+    public ConnectorModule(Connector connector) {
+        this(connector, Thread.currentThread().getContextClassLoader(), null, null);
+    }
+
     public ConnectorModule(Connector connector, ClassLoader classLoader, String jarLocation, String moduleId) {
         this.connector = connector;
         this.classLoader = classLoader;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java Fri Aug  1 14:22:06 2008
@@ -208,6 +208,25 @@
         return services;
     }
 
+    public static void registerServiceProvider(String packageName, ServiceProvider provider) {
+        List<ServiceProvider> services = loadedServiceJars.get(packageName);
+        if (services == null) {
+            ServicesJar servicesJar = null;
+            try {
+                servicesJar = JaxbOpenejb.readServicesJar(packageName);
+            } catch (OpenEJBException e) {
+                servicesJar = new ServicesJar();
+            }
+
+            // index services by provider id
+            List<ServiceProvider> serviceProviders = servicesJar.getServiceProvider();
+            services = new ArrayList<ServiceProvider>(serviceProviders);
+
+            loadedServiceJars.put(packageName, services);
+        }
+        services.add(provider);
+    }
+
     private static ProviderInfo getProviderInfo(String id) {
         String providerName = null;
         String serviceName = null;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProvider.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProvider.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProvider.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/ServiceProvider.java Fri Aug  1 14:22:06 2008
@@ -79,6 +79,15 @@
     // for some reason when this field is type List JaxB gives us a List<List<String>>
     protected List<String> types;
 
+    public ServiceProvider() {
+    }
+
+    public ServiceProvider(String className, String id, String service) {
+        this.className = className;
+        this.id = id;
+        this.service = service;
+    }
+
     /**
      * Gets the value of the properties property.
      * <p/>

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java?rev=681831&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java Fri Aug  1 14:22:06 2008
@@ -0,0 +1,223 @@
+/**
+ * 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.openejb.core.mdb;
+
+import junit.framework.TestCase;
+import junit.framework.Assert;
+import org.apache.openejb.core.ivm.naming.InitContextFactory;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.config.ConnectorModule;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.MessageDrivenBean;
+import org.apache.openejb.jee.Connector;
+import org.apache.openejb.jee.ResourceAdapter;
+import org.apache.openejb.jee.InboundResource;
+import org.apache.openejb.jee.MessageAdapter;
+import org.apache.openejb.jee.MessageListener;
+import org.apache.openejb.util.Join;
+
+import javax.naming.InitialContext;
+import javax.jms.ConnectionFactory;
+import javax.annotation.Resource;
+import javax.annotation.PostConstruct;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.MessageDriven;
+import javax.ejb.ActivationConfigProperty;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.InvalidPropertyException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.ResourceException;
+import javax.transaction.xa.XAResource;
+import java.util.Stack;
+import java.util.List;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.Condition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CustomMdbContainerTest extends TestCase {
+    public void test() throws Exception {
+        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+
+        ConfigurationFactory config = new ConfigurationFactory();
+        Assembler assembler = new Assembler();
+
+        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        // Setup the descriptor information
+
+        EmailBean.lifecycle.clear();
+
+
+        AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
+
+        Connector connector = new Connector("email-ra");
+        ResourceAdapter adapter = connector.setResourceAdapter(new ResourceAdapter(EmailResourceAdapter.class));
+        InboundResource inbound = adapter.setInboundResourceAdapter(new InboundResource());
+        MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
+        MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
+        listener.getActivationSpec().addRequiredConfigProperty("address");
+        app.getResourceModules().add(new ConnectorModule(connector));
+
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
+        app.getEjbModules().add(new EjbModule(ejbJar));
+
+        AppInfo appInfo = config.configureApplication(app);
+        assembler.createApplication(appInfo);
+
+        InitialContext initialContext = new InitialContext();
+
+        EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
+
+        Properties headers = new Properties();
+        headers.put("To", "dblevins@apache.org");
+        headers.put("From", "dblevins@visi.com");
+        headers.put("Subject", "Hello");
+
+        ra.deliverEmail(headers, "How's it going?");
+
+        Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
+
+        List expected = Arrays.asList(Lifecycle.values());
+
+        Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
+
+    }
+
+    public static enum Lifecycle {
+        CONSTRUCTOR, INJECTION, POST_CONSTRUCT, ON_MESSAGE
+    }
+
+    @MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "address", propertyValue = "dblevins@apache.org")})
+    public static class EmailBean implements EmailConsumer {
+
+        public static Lock lock = new ReentrantLock();
+        public static Condition messageRecieved = lock.newCondition();
+
+        private static Stack<Lifecycle> lifecycle = new Stack<Lifecycle>();
+
+        public EmailBean() {
+            lifecycle.push(Lifecycle.CONSTRUCTOR);
+        }
+
+        @Resource
+        public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {
+            lifecycle.push(Lifecycle.INJECTION);
+        }
+
+        @PostConstruct
+        public void init() {
+            lifecycle.push(Lifecycle.POST_CONSTRUCT);
+        }
+
+        public void receiveEmail(Properties headers, String body) {
+            lifecycle.push(Lifecycle.ON_MESSAGE);
+        }
+    }
+
+    public static interface EmailConsumer {
+        public void receiveEmail(Properties headers, String body);
+    }
+
+    public static class EmailResourceAdapter implements javax.resource.spi.ResourceAdapter {
+        public boolean started;
+
+        private final Map<String, EmailConsumer> consumers = new HashMap<String, EmailConsumer>();
+
+        public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
+        }
+
+        public void stop() {
+        }
+
+        public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
+            EmailAccountInfo accountInfo = (EmailAccountInfo) activationSpec;
+
+            EmailConsumer emailConsumer = (EmailConsumer) messageEndpointFactory.createEndpoint(null);
+            consumers.put(accountInfo.getAddress(), emailConsumer);
+        }
+
+        public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) {
+            EmailAccountInfo accountInfo = (EmailAccountInfo) activationSpec;
+
+            EmailConsumer emailConsumer = consumers.remove(accountInfo.getAddress());
+            MessageEndpoint endpoint = (MessageEndpoint) emailConsumer;
+            endpoint.release();
+        }
+
+        public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
+            return new XAResource[0];
+        }
+
+        public void deliverEmail(Properties headers, String body) throws Exception {
+            String to = headers.getProperty("To");
+
+            EmailConsumer emailConsumer = consumers.get(to);
+
+            if (emailConsumer == null) throw new Exception("No such account");
+
+            MessageEndpoint endpoint = (MessageEndpoint) emailConsumer;
+
+            endpoint.beforeDelivery(EmailConsumer.class.getMethod("receiveEmail", Properties.class, String.class));
+            emailConsumer.receiveEmail(headers, body);
+            endpoint.afterDelivery();
+        }
+    }
+
+    public static class EmailAccountInfo implements ActivationSpec {
+        private EmailResourceAdapter emailResourceAdapter;
+
+        private String address;
+
+        public void validate() throws InvalidPropertyException {
+        }
+
+        public String getAddress() {
+            return address;
+        }
+
+        public void setAddress(String address) {
+            this.address = address;
+        }
+
+        public EmailResourceAdapter getResourceAdapter() {
+            return emailResourceAdapter;
+        }
+
+        public void setResourceAdapter(javax.resource.spi.ResourceAdapter resourceAdapter) {
+            this.emailResourceAdapter = (EmailResourceAdapter) resourceAdapter;
+        }
+    }
+
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/JmsMdbContainerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/JmsMdbContainerTest.java?rev=681831&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/JmsMdbContainerTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/JmsMdbContainerTest.java Fri Aug  1 14:22:06 2008
@@ -0,0 +1,153 @@
+/**
+ * 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.openejb.core.mdb;
+
+import junit.framework.TestCase;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.ivm.naming.InitContextFactory;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.MessageDrivenBean;
+import static org.apache.openejb.util.Join.join;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Stack;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JmsMdbContainerTest extends TestCase {
+    public void test() throws Exception {
+        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+
+        ConfigurationFactory config = new ConfigurationFactory();
+        Assembler assembler = new Assembler();
+
+        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        // Setup the descriptor information
+
+        WidgetBean.lifecycle.clear();
+
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new MessageDrivenBean(WidgetBean.class));
+
+        assembler.createApplication(config.configureApplication(ejbJar));
+
+        InitialContext initialContext = new InitialContext();
+
+        ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("java:openejb/Resource/Default JMS Connection Factory");
+
+        sendMessage(connectionFactory, "WidgetBean", "test");
+
+        Stack<Lifecycle> lifecycle = WidgetBean.lifecycle;
+
+        List expected = Arrays.asList(Lifecycle.values());
+
+        assertEquals(join("\n", expected), join("\n", lifecycle));
+
+    }
+
+    private void sendMessage(ConnectionFactory connectionFactory, String bean, String text) throws JMSException, InterruptedException {
+        WidgetBean.lock.lock();
+
+        try {
+            Connection connection = connectionFactory.createConnection();
+            connection.start();
+
+            // Create a Session
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            Queue queue = session.createQueue(bean);
+
+            // Create a MessageProducer from the Session to the Topic or Queue
+            MessageProducer producer = session.createProducer(queue);
+            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+            // Create a message
+            TextMessage message = session.createTextMessage(text);
+
+            // Tell the producer to send the message
+            producer.send(message);
+
+            WidgetBean.messageRecieved.await();
+        } finally {
+            WidgetBean.lock.unlock();
+        }
+    }
+
+    public static enum Lifecycle {
+        CONSTRUCTOR, INJECTION, POST_CONSTRUCT, ON_MESSAGE
+    }
+
+    public static class WidgetBean implements javax.jms.MessageListener {
+
+        public static Lock lock = new ReentrantLock();
+        public static Condition messageRecieved = lock.newCondition();
+
+        private static Stack<Lifecycle> lifecycle = new Stack<Lifecycle>();
+
+        @Resource
+        ConnectionFactory connectionFactory;
+
+        public WidgetBean() {
+            lifecycle.push(Lifecycle.CONSTRUCTOR);
+        }
+
+        @Resource
+        public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {
+            lifecycle.push(Lifecycle.INJECTION);
+        }
+
+        @PostConstruct
+        public void init() {
+            lifecycle.push(Lifecycle.POST_CONSTRUCT);
+        }
+
+        public void onMessage(Message message) {
+            lifecycle.push(Lifecycle.ON_MESSAGE);
+
+            lock.lock();
+            try {
+                messageRecieved.signalAll();
+            } finally {
+                lock.unlock();
+            }
+        }
+
+    }
+}

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ActivationSpec.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ActivationSpec.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ActivationSpec.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ActivationSpec.java Fri Aug  1 14:22:06 2008
@@ -49,6 +49,17 @@
     @XmlID
     protected String id;
 
+    public ActivationSpec() {
+    }
+
+    public ActivationSpec(String activationSpecClass) {
+        this.activationSpecClass = activationSpecClass;
+    }
+
+    public ActivationSpec(Class activationSpecClass) {
+        this(activationSpecClass.getName());
+    }
+
     public String getActivationSpecClass() {
         return activationSpecClass;
     }
@@ -64,6 +75,12 @@
         return this.requiredConfigProperty;
     }
 
+    public RequiredConfigProperty addRequiredConfigProperty(String name) {
+        RequiredConfigProperty property = new RequiredConfigProperty(name);
+        getRequiredConfigProperty().add(property);
+        return property;
+    }
+    
     public String getId() {
         return id;
     }

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/Connector.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/Connector.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/Connector.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/Connector.java Fri Aug  1 14:22:06 2008
@@ -69,6 +69,13 @@
     @XmlAttribute(required = true)
     protected String version;
 
+    public Connector() {
+    }
+
+    public Connector(String id) {
+        this.id = id;
+    }
+
     @XmlElement(name = "description", required = true)
     public Text[] getDescriptions() {
         return description.toArray();
@@ -146,11 +153,15 @@
     }
 
     public ResourceAdapter getResourceAdapter() {
+        if (resourceAdapter == null){
+            resourceAdapter = new ResourceAdapter();
+        }
         return resourceAdapter;
     }
 
-    public void setResourceAdapter(ResourceAdapter value) {
+    public ResourceAdapter setResourceAdapter(ResourceAdapter value) {
         this.resourceAdapter = value;
+        return resourceAdapter;
     }
 
     public String getId() {

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/InboundResource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/InboundResource.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/InboundResource.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/InboundResource.java Fri Aug  1 14:22:06 2008
@@ -48,8 +48,9 @@
         return messageAdapter;
     }
 
-    public void setMessageAdapter(MessageAdapter value) {
+    public MessageAdapter setMessageAdapter(MessageAdapter value) {
         this.messageAdapter = value;
+        return messageAdapter;
     }
 
     public String getId() {

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageAdapter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageAdapter.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageAdapter.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageAdapter.java Fri Aug  1 14:22:06 2008
@@ -54,6 +54,11 @@
         return this.messageListener;
     }
 
+    public MessageListener addMessageListener(MessageListener listener){
+        getMessageListener().add(listener);
+        return listener;
+    }
+    
     public String getId() {
         return id;
     }

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageDrivenBean.java Fri Aug  1 14:22:06 2008
@@ -176,6 +176,19 @@
         this.ejbName = ejbName;
     }
 
+    public MessageDrivenBean(String ejbName, String ejbClass) {
+        this.ejbName = ejbName;
+        this.ejbClass = ejbClass;
+    }
+
+    public MessageDrivenBean(Class ejbClass) {
+        this(ejbClass.getSimpleName(), ejbClass.getName());
+    }
+
+    public MessageDrivenBean(String ejbName, Class ejbClass) {
+        this(ejbName, ejbClass.getName());
+    }
+
     public String getJndiConsumerName() {
         return ejbName;
     }

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageListener.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageListener.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/MessageListener.java Fri Aug  1 14:22:06 2008
@@ -48,6 +48,18 @@
     @XmlID
     protected String id;
 
+    public MessageListener() {
+    }
+
+    public MessageListener(String messageListenerType, String activationSpecClass) {
+        this.messageListenerType = messageListenerType;
+        this.activationSpec = new ActivationSpec(activationSpecClass);
+    }
+
+    public MessageListener(Class messageListenerType, Class activationSpecClass) {
+        this(messageListenerType.getName(), activationSpecClass.getName());
+    }
+
     public String getMessageListenerType() {
         return messageListenerType;
     }

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/RequiredConfigProperty.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/RequiredConfigProperty.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/RequiredConfigProperty.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/RequiredConfigProperty.java Fri Aug  1 14:22:06 2008
@@ -52,6 +52,13 @@
     @XmlID
     protected String id;
 
+    public RequiredConfigProperty() {
+    }
+
+    public RequiredConfigProperty(String configPropertyName) {
+        this.configPropertyName = configPropertyName;
+    }
+
     public List<Text> getDescription() {
         if (description == null) {
             description = new ArrayList<Text>();

Modified: openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceAdapter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceAdapter.java?rev=681831&r1=681830&r2=681831&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceAdapter.java (original)
+++ openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/ResourceAdapter.java Fri Aug  1 14:22:06 2008
@@ -64,6 +64,17 @@
     @XmlID
     protected String id;
 
+    public ResourceAdapter() {
+    }
+
+    public ResourceAdapter(String resourceAdapterClass) {
+        this.resourceAdapterClass = resourceAdapterClass;
+    }
+
+    public ResourceAdapter(Class resourceAdapterClass) {
+        this(resourceAdapterClass.getName());
+    }
+
     public String getResourceAdapterClass() {
         return resourceAdapterClass;
     }
@@ -83,16 +94,18 @@
         return outboundResourceAdapter;
     }
 
-    public void setOutboundResourceAdapter(OutboundResourceAdapter value) {
+    public OutboundResourceAdapter setOutboundResourceAdapter(OutboundResourceAdapter value) {
         this.outboundResourceAdapter = value;
+        return outboundResourceAdapter;
     }
 
     public InboundResource getInboundResourceAdapter() {
         return inboundResourceAdapter;
     }
 
-    public void setInboundResourceAdapter(InboundResource value) {
+    public InboundResource setInboundResourceAdapter(InboundResource value) {
         this.inboundResourceAdapter = value;
+        return inboundResourceAdapter;
     }
 
     public List<AdminObject> getAdminObject() {



Mime
View raw message