[jboss-svn-commits] JBL Code SVN: r11901 - in labs/jbossesb/trunk/product: core/listeners/src/org/jboss/soa/esb/listeners and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed May 16 16:51:50 EDT 2007


Author: bill.burke at jboss.com
Date: 2007-05-16 16:51:50 -0400 (Wed, 16 May 2007)
New Revision: 11901

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ServiceInvoker.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/ActivationBridge.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointContainer.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointFactory.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/InflowGateway.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JBoss42ActivationBridge.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JcaInflowGateway.java
Modified:
   labs/jbossesb/trunk/product/build-distr.xml
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/MapperUtil.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
Log:
jca gateway

Modified: labs/jbossesb/trunk/product/build-distr.xml
===================================================================
--- labs/jbossesb/trunk/product/build-distr.xml	2007-05-16 15:55:41 UTC (rev 11900)
+++ labs/jbossesb/trunk/product/build-distr.xml	2007-05-16 20:51:50 UTC (rev 11901)
@@ -51,13 +51,11 @@
             <include name="**/*"/>
          </fileset>
       </copy>
-      <!--
       <copy todir="${esbserver.dist.dir}/server/default/deploy">
          <fileset dir="ftp/build">
             <include name="ftp-server.sar/**/*"/>
          </fileset>
       </copy>
-      -->
       <copy todir="${esbserver.dist.dir}/server/default/deploy">
          <fileset dir="tools/configeditor/editor/dist">
             <include name="jbossesb-config-editor.war"/>

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ServiceInvoker.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ServiceInvoker.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ServiceInvoker.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.services.registry.RegistryException;
+
+import java.util.Collection;
+
+/**
+ * At initialization, this object looks up target EPR for a given service/category.
+ * The postMessage method invokes on a target EPR.
+ *
+ * This class is really for use with Gateways, but could be used by clients to pre-initialize a service lookup
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceInvoker
+{
+   private String name;
+   private String category;
+
+   private Collection<EPR> targetEprs;
+
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getCategory()
+   {
+      return category;
+   }
+
+   public void setCategory(String category)
+   {
+      this.category = category;
+   }
+
+   public void start()
+   {
+      try
+      {
+          targetEprs = RegistryUtil.getEprs(category, name);
+      }
+      catch (final RegistryException re)
+      {
+          throw new RuntimeException("Unexpected registry exception", re) ;
+      }
+
+   }
+
+   public void postMessage(Message message) throws CourierException, MalformedEPRException
+   {
+      boolean bSent = false;
+      for (EPR current : targetEprs)
+      {
+         Courier courier = CourierFactory.getCourier(current);
+         try
+         {
+            System.out.println("Trying EPR: " + current);
+            if (courier.deliver(message))
+            {
+               bSent = true;
+               break;
+            }
+         }
+         finally
+         {
+            CourierUtil.cleanCourier(courier);
+         }
+      }
+      if (!bSent)
+      {
+         String text = "Target service <" + category + "," + name + "> is not registered";
+         throw new CourierException(text);
+      }
+   }
+}

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/MapperUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/MapperUtil.java	2007-05-16 15:55:41 UTC (rev 11900)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/MapperUtil.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -37,6 +37,7 @@
 import org.jboss.soa.esb.listeners.message.MessageAwareListener;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.milyn.xml.DomUtils;
 
 /**
  * Mapper utility methods.
@@ -93,8 +94,17 @@
 	protected static void mapProperties(List<Property> properties, Element target) {
 		// Map the property elements to actions attributes...
 		for(Property property : properties) {
-			target.setAttribute(property.getName(), property.getValue());
-		}
+         Element propertyElement = target.getOwnerDocument().createElement("property");
+         serialize(property, propertyElement);
+         if (propertyElement.hasChildNodes())
+         {
+            DomUtils.copyChildNodes(propertyElement, target);
+         }
+         else
+         {
+            target.setAttribute(property.getName(), property.getValue());
+         }
+      }
 	}
 
 	/**

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java	2007-05-16 15:55:41 UTC (rev 11900)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -32,13 +32,10 @@
 import java.util.Properties;
 import java.util.Set;
 
-import javax.jms.BytesMessage;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
-import javax.jms.ObjectMessage;
 import javax.jms.Queue;
 import javax.jms.QueueSession;
-import javax.jms.TextMessage;
 import javax.naming.Context;
 import javax.naming.NamingException;
 
@@ -62,7 +59,6 @@
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
 import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.services.registry.RegistryException;
 import org.jboss.soa.esb.util.ClassUtil;
 
@@ -72,7 +68,7 @@
          * serial version uid for this class
          */
         private static final long serialVersionUID = 5070422864110923930L;
-    
+
         public JmsGatewayListener (ConfigTree listenerConfig) throws ConfigurationException
 	{
             super(listenerConfig) ;
@@ -80,10 +76,10 @@
             checkMyParms();
 	} // __________________________________
 
-        
+
         /**
          * Handle the initialisation of the managed instance.
-         * 
+         *
          * @throws ManagedLifecycleException for errors while initialisation.
          */
         protected void doInitialise()
@@ -99,7 +95,7 @@
             {
                 throw new ManagedLifecycleException("Unexpected registry exception", re) ;
             }
-            
+
             try
             {
                 prepareMessageReceiver();
@@ -116,7 +112,7 @@
             {
                 throw new ManagedLifecycleException("Unexpected configuration exception from prepareMessageReceiver", ce);
             }
-            
+
             if (_serviceName != null)
             {
                 try
@@ -129,7 +125,7 @@
                 }
             }
         }
-        
+
         /**
          * Execute on the thread.
          */
@@ -211,7 +207,7 @@
 
         /**
          * Handle the destroy of the managed instance.
-         * 
+         *
          * @throws ManagedLifecycleException for errors while destroying.
          */
         protected void doDestroy()
@@ -221,7 +217,7 @@
             {
                 RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
             }
-            
+
             if (_messageReceiver != null)
             {
                 try
@@ -230,7 +226,7 @@
                 }
                 catch (final JMSException jmse) {} // ignore
             }
-            
+
             if (_queueSession != null)
             {
                     _pool.closeSession(_queueSession);
@@ -239,7 +235,7 @@
 
 	/**
 	 * Check for mandatory and optional attributes in parameter tree
-	 * 
+	 *
 	 * @throws ConfigurationException -
 	 *             if mandatory atts are not right or actionClass not in
 	 *             classpath
@@ -287,7 +283,7 @@
 				_logger
 						.debug("No <" + ListenerTagNames.ACTION_ELEMENT_TAG + "> element found in configuration" + " -  Using default composer class : " + _composerName);
 			}
-	
+
 			_processMethod = _composerClass.getMethod(sProcessMethod,
 					new Class[] { Object.class });
 		}
@@ -303,7 +299,7 @@
 		_queue = null;
 
         Properties environment = new Properties();
-          
+
         String sJndiURL = _config.getAttribute(JMSEpr.JNDI_URL_TAG);
         String sJndiContextFactory = _config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG);
         String sJndiPkgPrefix = _config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG);
@@ -313,11 +309,11 @@
         Set<String> names=_config.getAttributeNames();
         for (String name : names) {
             if (name.startsWith("java.naming.")) {
-                environment.setProperty(name, _config.getAttribute(name));  
+                environment.setProperty(name, _config.getAttribute(name));
             }
         }
         Context oJndiCtx = NamingContext.getServerContext(environment);
-        
+
         if (null == oJndiCtx)
             throw new ConfigurationException(
                     "Unable fo obtain jndi context <" + sJndiURL + "," + sJndiContextFactory + "," + sJndiPkgPrefix + ">");
@@ -332,15 +328,15 @@
          _serviceName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
          _myEpr = (null == _serviceName) ? null : new JMSEpr(JMSEpr.QUEUE_TYPE,
                  _queueName, sFactClass, environment, _messageSelector);
-     
+
          _pool = JmsConnectionPoolContainer.getPool(environment, sFactClass, JMSEpr.QUEUE_TYPE);
-          
+
          try {
              _queueSession = _pool.getQueueSession();
          } catch (NamingException ne) {
              throw new ConfigurationException("Failed to obtain queue session from pool", ne) ;
          }
-         
+
          try {
              _queue = (Queue) oJndiCtx.lookup(_queueName);
          } catch (NamingException nex) {
@@ -358,7 +354,7 @@
 
 	/**
 	 * Receive one message and retry if connection
-	 * 
+	 *
 	 * @return javax.jms.Message - One input message, or null
 	 */
 	protected javax.jms.Message receiveOne ()
@@ -402,70 +398,7 @@
 		return null;
 	} // ________________________________
 
-    /**
-	 * Default gateway action for plain jms messages <p/>It will just drop the
-	 * jms message contents into a esb Message
-	 * 
-	 * @author <a
-	 *         href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
-	 * @since Version 4.0
-	 * 
-	 */
-	private static class PackageJmsMessageContents
-	{
-		@SuppressWarnings("unchecked")
-		public Message process (Object obj) throws JMSException, IOException
-		{
-			if (!(obj instanceof javax.jms.Message))
-				throw new IllegalArgumentException(
-						"Object must be instance of javax.jms.Message");
-			byte[] bytes = getMessageContent((javax.jms.Message) obj);
-			if (null == bytes) return null;
-
-			javax.jms.Message jmsMsg = (javax.jms.Message) obj;
-			Message message = MessageFactory.getInstance().getMessage();
-			message.getBody().setByteArray(getMessageContent(jmsMsg));
-			Enumeration<String> EE = jmsMsg.getPropertyNames();
-			if (null != EE)
-			{
-				while (EE.hasMoreElements())
-				{
-					String name = EE.nextElement();
-					Object value = jmsMsg.getObjectProperty(name);
-					if (null != value)
-						message.getProperties().setProperty(name, value);
-				}
-			}
-			return message;
-		}
-
-		private byte[] getMessageContent (javax.jms.Message jMess) throws JMSException, IOException
-		{
-			if (jMess instanceof TextMessage)
-				return ((TextMessage) jMess).getText().getBytes();
-
-			if (jMess instanceof BytesMessage)
-			{
-				BytesMessage jBytes = (BytesMessage) jMess;
-				ByteArrayOutputStream out = new ByteArrayOutputStream();
-				byte[] ba = new byte[1000];
-				int iQread;
-				while (-1 != (iQread = jBytes.readBytes(ba)))
-					if (iQread > 0) out.write(ba, 0, iQread);
-				out.close();
-				return out.toByteArray();
-			}
-
-			if (jMess instanceof ObjectMessage)
-				return ((ObjectMessage) jMess).getObject().toString()
-						.getBytes();
-			_logger
-					.warn("Message type " + jMess.getClass().getSimpleName() + " not supported - Message is ignored");
-			return null;
-		}
-	} // ____________________________________________________
-
-	protected final static Logger _logger = Logger
+   protected final static Logger _logger = Logger
 			.getLogger(JmsGatewayListener.class);
 
 	protected String _queueName;

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.gateway;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+import javax.jms.BytesMessage;
+import javax.jms.ObjectMessage;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.util.Enumeration;
+
+/**
+	 * Default gateway action for plain jms messages <p/>It will just drop the
+* jms message contents into a esb Message
+*
+* @author <a
+*         href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+* @since Version 4.0
+*
+*/
+public class PackageJmsMessageContents
+{
+  @SuppressWarnings("unchecked")
+  public Message process (Object obj) throws JMSException, IOException
+  {
+     if (!(obj instanceof javax.jms.Message))
+        throw new IllegalArgumentException(
+              "Object must be instance of javax.jms.Message");
+     byte[] bytes = getMessageContent((javax.jms.Message) obj);
+     if (null == bytes) return null;
+
+     javax.jms.Message jmsMsg = (javax.jms.Message) obj;
+     Message message = MessageFactory.getInstance().getMessage();
+     message.getBody().setContents(getMessageContent(jmsMsg));
+     Enumeration<String> EE = jmsMsg.getPropertyNames();
+     if (null != EE)
+     {
+        while (EE.hasMoreElements())
+        {
+           String name = EE.nextElement();
+           Object value = jmsMsg.getObjectProperty(name);
+           if (null != value)
+              message.getProperties().setProperty(name, value);
+        }
+     }
+     return message;
+  }
+
+  private byte[] getMessageContent (javax.jms.Message jMess) throws JMSException, IOException
+  {
+     if (jMess instanceof TextMessage)
+        return ((TextMessage) jMess).getText().getBytes();
+
+     if (jMess instanceof BytesMessage)
+     {
+        BytesMessage jBytes = (BytesMessage) jMess;
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        byte[] ba = new byte[1000];
+        int iQread;
+        while (-1 != (iQread = jBytes.readBytes(ba)))
+           if (iQread > 0) out.write(ba, 0, iQread);
+        out.close();
+        return out.toByteArray();
+     }
+
+     if (jMess instanceof ObjectMessage)
+        return ((ObjectMessage) jMess).getObject().toString()
+              .getBytes();
+     JmsGatewayListener._logger
+             .warn("Message type " + jMess.getClass().getSimpleName() + " not supported - Message is ignored");
+     return null;
+  }
+} // ____________________________________________________

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/ActivationBridge.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/ActivationBridge.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/ActivationBridge.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import java.util.Map;
+
+/**
+ * Bridges different vendor JCA implementations to activate an endpoint
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ActivationBridge
+{
+   void setAdapter(String adapter);
+
+   void setMessagingTypeClass(Class messagingTypeClass);
+
+   void setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory);
+
+   void setActivationProperties(Map<String, String> activationProperties);
+
+   void activate();
+
+   void deactivate();
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointContainer.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointContainer.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointContainer.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import java.lang.reflect.Method;
+
+/**
+ * Contract between JCA and endpoint.  Instances of this object are used by the message endpoint factory and endopint proxy
+ * to obtain whether delivery is transacted and to invoke on the actual endpoint bean
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public interface EndpointContainer
+{
+   /**
+    * description used for logging and tracing
+    */
+   public String getDescription();
+
+   public Object invoke(Method method, Object[] args) throws Throwable;
+
+   public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException;
+
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointFactory.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointFactory.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,107 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class EndpointFactory implements MessageEndpointFactory
+{
+   private EndpointContainer container;
+   private Class messagingType;
+   private ClassLoader loader;
+
+   private Constructor proxyConstructor;
+
+
+   public EndpointContainer getContainer()
+   {
+      return container;
+   }
+
+   public void setContainer(EndpointContainer container)
+   {
+      this.container = container;
+   }
+
+
+   public void setMessagingType(Class messagingType)
+   {
+      this.messagingType = messagingType;
+   }
+
+   public void setLoader(ClassLoader loader)
+   {
+      this.loader = loader;
+   }
+
+   public void start()
+   {
+      Class[] interfaces = {messagingType, MessageEndpoint.class};
+      Class proxyClass = Proxy.getProxyClass(loader, interfaces);
+      final Class[] constructorParams = {InvocationHandler.class};
+      try
+      {
+         proxyConstructor = proxyClass.getConstructor(constructorParams);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException
+   {
+      EndpointProxy proxy = new EndpointProxy();
+      proxy.setXaResource(xaResource);
+      proxy.setMessageEndpointFactory(this);
+      proxy.setContainer(container);
+      proxy.setLoader(loader);
+      Object[] args = {proxy};
+      try
+      {
+         return (MessageEndpoint) proxyConstructor.newInstance(args);
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         return null;
+      }
+   }
+
+   public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
+   {
+      return container.isDeliveryTransacted(method);
+   }
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,438 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerLocator;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class EndpointProxy implements InvocationHandler
+{
+   private static final Logger log = Logger.getLogger(EndpointProxy.class);
+
+   /**
+    * Whether trace is enabled
+    */
+   private boolean trace = log.isTraceEnabled();
+
+   /**
+    * Whether this proxy has been released
+    */
+   protected SynchronizedBoolean released = new SynchronizedBoolean(false);
+
+   /**
+    * Whether we have delivered a message
+    */
+   protected boolean delivered = false;
+
+   /**
+    * The in use thread
+    */
+   protected Thread inUseThread = null;
+
+   /**
+    * The old classloader of the thread
+    */
+   protected ClassLoader oldClassLoader = null;
+
+   /**
+    * Any transaction we started
+    */
+   protected Transaction transaction = null;
+
+   /**
+    * Any suspended transaction
+    */
+   protected Transaction suspended = null;
+
+   protected ClassLoader loader;
+
+   private XAResource resource;
+   private MessageEndpointFactory messageEndpointFactory;
+   private EndpointContainer container;
+
+
+   public void setContainer(EndpointContainer container)
+   {
+      this.container = container;
+   }
+
+   public void setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)
+   {
+      this.messageEndpointFactory = messageEndpointFactory;
+   }
+
+   public void setXaResource(XAResource resource)
+   {
+      this.resource = resource;
+   }
+
+
+   public void setLoader(ClassLoader loader)
+   {
+      this.loader = loader;
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args)
+           throws Throwable
+   {
+      // Are we still useable?
+      if (released.get())
+         throw new IllegalStateException("This message endpoint + " + getProxyString(proxy) + " has been released");
+
+      // Concurrent invocation?
+      Thread currentThread = Thread.currentThread();
+      if (inUseThread != null && inUseThread.equals(currentThread) == false)
+         throw new IllegalStateException("This message endpoint + " + getProxyString(proxy) + " is already in use by another thread " + inUseThread);
+      inUseThread = currentThread;
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " in use by " + method + " " + inUseThread);
+
+      // Which operation?
+      if (method.getName().equals("release"))
+      {
+         release(proxy);
+         return null;
+      }
+      else if (method.getName().equals("beforeDelivery"))
+      {
+         before(proxy, method, args);
+         return null;
+      }
+      else if (method.getName().equals("afterDelivery"))
+      {
+         after(proxy);
+         return null;
+      }
+      else
+         return delivery(proxy, method, args);
+   }
+
+   // -----------------------------------------------------------
+
+   protected void release(Object proxy) throws Throwable
+   {
+      // We are now released
+      released.set(true);
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " released");
+
+      // Tidyup any outstanding delivery
+      if (oldClassLoader != null)
+      {
+         try
+         {
+            finish("release", proxy, false);
+         }
+         catch (Throwable t)
+         {
+            log.warn("Error in release ", t);
+         }
+      }
+   }
+
+   protected void before(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      // Called out of sequence
+      if (oldClassLoader != null)
+         throw new IllegalStateException("Missing afterDelivery from the previous beforeDelivery for message endpoint " + getProxyString(proxy));
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " released");
+
+      // Set the classloader
+      oldClassLoader = inUseThread.getContextClassLoader();
+      inUseThread.setContextClassLoader(loader);
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " set context classloader to " + loader);
+
+      // start any transaction
+      try
+      {
+         // Is the delivery transacted?
+         Method beforeMethod = (Method) args[0];
+         boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(beforeMethod);
+
+         startTransaction("beforeDelivery", proxy, method, args, isTransacted);
+      }
+      catch (Throwable t)
+      {
+         resetContextClassLoader(proxy);
+         throw new ResourceException(t);
+      }
+   }
+
+   protected void after(Object proxy) throws Throwable
+   {
+      // Called out of sequence
+      if (oldClassLoader == null)
+         throw new IllegalStateException("afterDelivery without a previous beforeDelivery for message endpoint " + getProxyString(proxy));
+
+      // Finish this delivery committing if we can
+      try
+      {
+         finish("afterDelivery", proxy, true);
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException(t);
+      }
+   }
+
+   protected Object delivery(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      // Have we already delivered a message?
+      if (delivered)
+         throw new IllegalStateException("Multiple message delivery between before and after delivery is not allowed for message endpoint " + getProxyString(proxy));
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " delivering");
+
+      // Mark delivery if beforeDelivery was invoked
+      if (oldClassLoader != null)
+         delivered = true;
+
+      boolean commit = true;
+      try
+      {
+         // Check for starting a transaction
+         if (oldClassLoader == null)
+         {
+            boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(method);
+            startTransaction("delivery", proxy, method, args, isTransacted);
+         }
+         return container.invoke(method, args);
+      }
+      catch (Throwable t)
+      {
+         if (trace)
+            log.trace("MessageEndpoint " + getProxyString(proxy) + " delivery error", t);
+         if (t instanceof Error || t instanceof RuntimeException)
+         {
+            if (transaction != null)
+               transaction.setRollbackOnly();
+            commit = false;
+         }
+         throw t;
+      }
+      finally
+      {
+         // No before/after delivery, end any transaction and release the lock
+         if (oldClassLoader == null)
+         {
+            try
+            {
+               // Finish any transaction we started
+               endTransaction(proxy, commit);
+            }
+            finally
+            {
+               releaseThreadLock(proxy);
+            }
+         }
+      }
+   }
+
+   protected void finish(String context, Object proxy, boolean commit) throws Throwable
+   {
+      try
+      {
+         endTransaction(proxy, commit);
+      }
+      finally
+      {
+         // Reset delivered flag
+         delivered = false;
+         // Change back to the original context classloader
+         resetContextClassLoader(proxy);
+         // We no longer hold the lock
+         releaseThreadLock(proxy);
+      }
+   }
+
+   protected void startTransaction(String context, Object proxy, Method m, Object[] args, boolean isTransacted) throws Throwable
+   {
+      Method method;
+
+      // Normal delivery
+      if ("delivery".equals(context))
+         method = m;
+         // Before delivery
+      else
+         method = (Method) args[0];
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " " + context + " method=" + method + " xaResource=" + resource + " transacted=" + isTransacted);
+
+      // Get the transaction status
+      TransactionManager tm = TransactionManagerLocator.getInstance().locate();
+      suspended = tm.suspend();
+
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " " + context + " currentTx=" + suspended);
+
+      // Delivery is transacted
+      if (isTransacted)
+      {
+         // No transaction means we start a new transaction and enlist the resource
+         if (suspended == null)
+         {
+            tm.begin();
+            transaction = tm.getTransaction();
+            if (trace)
+               log.trace("MessageEndpoint " + getProxyString(proxy) + " started transaction=" + transaction);
+
+            // Enlist the XAResource in the transaction
+            if (resource != null)
+            {
+               transaction.enlistResource(resource);
+               if (trace)
+                  log.trace("MessageEndpoint " + getProxyString(proxy) + " enlisted=" + resource);
+            }
+         }
+         else
+         {
+            // If there is already a transaction we ignore the XAResource (by spec 12.5.9)
+            try
+            {
+               tm.resume(suspended);
+            }
+            finally
+            {
+               suspended = null;
+               if (trace)
+                  log.trace("MessageEndpoint " + getProxyString(proxy) + " transaction=" + suspended + " already active, IGNORED=" + resource);
+            }
+         }
+      }
+   }
+
+   protected void endTransaction(Object proxy, boolean commit) throws Throwable
+   {
+      TransactionManager tm = null;
+      Transaction currentTx = null;
+      try
+      {
+         // If we started the transaction, commit it
+         if (transaction != null)
+         {
+            tm = TransactionManagerLocator.getInstance().locate();
+            currentTx = tm.getTransaction();
+
+            // Suspend any bad transaction - there is bug somewhere, but we will try to tidy things up
+            if (currentTx != null && currentTx.equals(transaction) == false)
+            {
+               log.warn("Current transaction " + currentTx + " is not the expected transaction.");
+               tm.suspend();
+               tm.resume(transaction);
+            }
+            else
+            {
+               // We have the correct transaction
+               currentTx = null;
+            }
+
+            // Commit or rollback depending on the status
+            if (commit == false || transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+            {
+               if (trace)
+                  log.trace("MessageEndpoint " + getProxyString(proxy) + " rollback");
+               tm.rollback();
+            }
+            else
+            {
+               if (trace)
+                  log.trace("MessageEndpoint " + getProxyString(proxy) + " commit");
+               tm.commit();
+            }
+         }
+
+         // If we suspended the incoming transaction, resume it
+         if (suspended != null)
+         {
+            try
+            {
+               tm = TransactionManagerLocator.getInstance().locate();
+               tm.resume(suspended);
+            }
+            finally
+            {
+               suspended = null;
+            }
+         }
+      }
+      finally
+      {
+         // Resume any suspended transaction
+         if (currentTx != null)
+         {
+            try
+            {
+               tm.resume(currentTx);
+            }
+            catch (Throwable t)
+            {
+               log.warn("MessageEndpoint " + getProxyString(proxy) + " failed to resume old transaction " + currentTx);
+
+            }
+         }
+      }
+   }
+
+   protected void resetContextClassLoader(Object proxy)
+   {
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " reset classloader " + oldClassLoader);
+      inUseThread.setContextClassLoader(oldClassLoader);
+      oldClassLoader = null;
+   }
+
+   protected void releaseThreadLock(Object proxy)
+   {
+      if (trace)
+         log.trace("MessageEndpoint " + getProxyString(proxy) + " no longer in use by " + inUseThread);
+      inUseThread = null;
+   }
+
+   protected String getProxyString(Object proxy)
+   {
+      return container.getDescription();
+   }
+
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/InflowGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/InflowGateway.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/InflowGateway.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import org.jboss.soa.esb.listeners.ServiceInvoker;
+
+/**
+ * Required interface for JCA ESB Gateways
+ * <p/>
+ * The injected ServiceInvoker should be used by the user object to invoke on target ESB service after, of course,
+ * it transforms the incoming gateway message into a generic ESB message
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public interface InflowGateway
+{
+   public void setServiceInvoker(ServiceInvoker invoker);
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JBoss42ActivationBridge.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JBoss42ActivationBridge.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JBoss42ActivationBridge.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,165 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import org.apache.log4j.Logger;
+import org.jboss.metadata.ActivationConfigPropertyMetaData;
+import org.jboss.mx.util.JMXExceptionDecoder;
+import org.jboss.mx.util.MBeanServerLocator;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * interfaces with JCA to activate an endpoint
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBoss42ActivationBridge implements ActivationBridge
+{
+   private static Logger logger = Logger.getLogger(JBoss42ActivationBridge.class);
+
+   /**
+    * The signature for createActivationSpec
+    */
+   protected static final String[] createActivationSpecSig = new String[]
+           {
+                   Class.class.getName(),
+                   Collection.class.getName()
+           };
+
+   /**
+    * The signature for activate/deactivateEndpint
+    */
+   protected static final String[] activationSig = new String[]
+           {
+                   MessageEndpointFactory.class.getName(),
+                   ActivationSpec.class.getName()
+           };
+
+   private String adapter;
+   private Class messagingTypeClass;
+   private MessageEndpointFactory messageEndpointFactory;
+   private Map<String, String> activationProperties;
+
+
+   private ActivationSpec activationSpec;
+   private MBeanServer mbeanServer;
+   private ObjectName resourceAdapterObjectName;
+
+
+   public void setAdapter(String adapter)
+   {
+      this.adapter = adapter;
+   }
+
+   public void setMessagingTypeClass(Class messagingTypeClass)
+   {
+      this.messagingTypeClass = messagingTypeClass;
+   }
+
+   public void setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)
+   {
+      this.messageEndpointFactory = messageEndpointFactory;
+   }
+
+   public void setActivationProperties(Map<String, String> activationProperties)
+   {
+      this.activationProperties = activationProperties;
+   }
+
+   public void activate()
+   {
+      mbeanServer = MBeanServerLocator.locateJBoss();
+      try
+      {
+         resourceAdapterObjectName = new ObjectName("jboss.jca:service=RARDeployment,name='" + adapter + "'");
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new RuntimeException("Unable to create JMX ObjectName to register adapter: " + adapter, e);
+      }
+
+      ArrayList<ActivationConfigPropertyMetaData> metaData = new ArrayList<ActivationConfigPropertyMetaData>();
+      for (String key : activationProperties.keySet())
+      {
+         String value = activationProperties.get(key);
+         metaData.add(new ActivationConfigPropertyMetaData(key, value));
+      }
+
+      Object[] params = new Object[]
+              {
+                      messagingTypeClass,
+                      metaData
+              };
+      try
+      {
+         activationSpec = (ActivationSpec) mbeanServer.invoke(resourceAdapterObjectName, "createActivationSpec", params, createActivationSpecSig);
+      }
+      catch (Throwable t)
+      {
+         t = JMXExceptionDecoder.decode(t);
+         throw new RuntimeException("Endpoint activation failed ra=" + resourceAdapterObjectName +
+                 " activationSpec=" + activationSpec, t);
+      }
+
+      params = new Object[]{messageEndpointFactory, activationSpec};
+      try
+      {
+         mbeanServer.invoke(resourceAdapterObjectName, "endpointActivation", params, activationSig);
+      }
+      catch (Throwable t)
+      {
+         t = JMXExceptionDecoder.decode(t);
+         throw new RuntimeException("Endpoint activation failed ra=" + resourceAdapterObjectName +
+                 " activationSpec=" + activationSpec, t);
+      }
+
+
+   }
+
+   /**
+    * Deactivate
+    */
+   public void deactivate()
+   {
+      Object[] params = new Object[]{messageEndpointFactory, activationSpec};
+      try
+      {
+         mbeanServer.invoke(resourceAdapterObjectName, "endpointDeactivation", params, activationSig);
+      }
+      catch (Throwable t)
+      {
+         t = JMXExceptionDecoder.decode(t);
+         logger.warn("Endpoint activation failed ra=" + resourceAdapterObjectName +
+                 " activationSpec=" + activationSpec, t);
+      }
+   }
+
+}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JcaInflowGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JcaInflowGateway.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/jca/JcaInflowGateway.java	2007-05-16 20:51:50 UTC (rev 11901)
@@ -0,0 +1,241 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.jca;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ServiceInvoker;
+
+import java.util.HashMap;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class JcaInflowGateway extends AbstractThreadedManagedLifecycle
+{
+   private static final long serialVersionUID = 1L;
+   private static Logger logger = Logger.getLogger(JcaInflowGateway.class);
+   private HashMap<String, String> activationSpec = new HashMap<String, String>();
+   private ClassLoader classLoader;
+   private Class beanClass;
+   private Class messagingType;
+   private ActivationBridge bridge;
+   private String adapter;
+   private String serviceName;
+   private String serviceCategory;
+   private boolean isTransacted = true;
+   private InflowGateway bean;
+
+   public JcaInflowGateway(ConfigTree config) throws ConfigurationException
+   {
+      super(config);
+      //System.out.println("CONFIG: " + config);
+
+      serviceCategory = ListenerUtil.obtainAtt(config,
+            ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+      serviceName = ListenerUtil.obtainAtt(config,
+            ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+
+      ConfigTree spec = config.getFirstChild("activation-config");
+      for (ConfigTree configProperty : spec.getChildren("activation-config-property"))
+      {
+         String name = configProperty.getFirstTextChild("activation-config-property-name").trim();
+         String value = configProperty.getFirstTextChild("activation-config-property-value").trim();
+         activationSpec.put(name, value);
+      }
+
+      this.classLoader = Thread.currentThread().getContextClassLoader();
+      adapter = config.getAttribute("adapter");
+
+      String bc = config.getAttribute("endpointClass");
+      if (bc == null) throw new ConfigurationException("endpointClass attribute is required for Jca Gateway");
+      try
+      {
+         beanClass = classLoader.loadClass(bc);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new ConfigurationException("Unable to load Jca Gateway endpointClass: " + bc, e);
+      }
+      if (!InflowGateway.class.isAssignableFrom(beanClass))
+         throw new ConfigurationException("endpointClass must implement InflowGateway interface");
+      String mt = config.getAttribute("messagingType");
+      if (mt != null)
+      {
+         try
+         {
+            messagingType = classLoader.loadClass(mt);
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new ConfigurationException("Unable to load Jca Gateway messagingType: " + mt, e);
+         }
+      }
+      else
+      {
+         messagingType = findMessagingType(beanClass);
+      }
+
+      String brdg = config.getAttribute("jcaBridge");
+      if (brdg != null)
+      {
+         try
+         {
+            bridge = (ActivationBridge) classLoader.loadClass(mt).newInstance();
+         }
+         catch (Exception e)
+         {
+            throw new ConfigurationException("Unable to load jcaBridge: " + brdg, e);
+         }
+      }
+      else
+      {
+         bridge = new JBoss42ActivationBridge();
+      }
+      String transacted = config.getAttribute("transacted");
+      if (transacted != null) isTransacted = Boolean.parseBoolean(transacted.trim());
+
+   }
+
+   public static Class findMessagingType(Class clazz)
+           throws ConfigurationException
+   {
+      if (clazz.equals(Object.class)) return null;
+
+      Class[] interfaces = clazz.getInterfaces();
+      Class type = null;
+      for (Class intf : interfaces)
+      {
+         if (intf.equals(InflowGateway.class)) continue;
+         if (type != null)
+         {
+            throw new ConfigurationException("Unable to guess messagingType interface from endpointClass as the base class implements too many interfaces, specify this explicity");
+         }
+         type = intf;
+      }
+      if (type == null) return findMessagingType(clazz.getSuperclass());
+      return type;
+   }
+
+
+   protected void doInitialise() throws ManagedLifecycleException
+   {
+      try
+      {
+         Constructor beanClassConstructor = beanClass.getConstructor(ConfigTree.class);
+         try
+         {
+            bean = (InflowGateway)beanClassConstructor.newInstance(getConfig());
+         }
+         catch (InstantiationException e)
+         {
+            throw new RuntimeException("Unable to create endpoint bean", e);
+         }
+         catch (IllegalAccessException e)
+         {
+            throw new RuntimeException("Unable to create endpoint bean", e);
+         }
+         catch (InvocationTargetException e)
+         {
+            throw new RuntimeException("Unable to create endpoint bean", e.getTargetException());
+         }
+      }
+      catch (NoSuchMethodException e)
+      {
+         try
+         {
+            bean = (InflowGateway)beanClass.newInstance();
+         }
+         catch (Exception e1)
+         {
+            throw new RuntimeException("Unable to create endpoint bean", e1);
+         }
+      }
+      final Object theBean = bean;
+      EndpointContainer container = new EndpointContainer()
+      {
+
+         public String getDescription()
+         {
+            return "category: " + serviceCategory + " service: " + serviceName + " jca adapter: " + adapter;
+         }
+
+         public Object invoke(Method method, Object[] args) throws Throwable
+         {
+            try
+            {
+               return method.invoke(theBean, args);
+            }
+            catch (IllegalAccessException e)
+            {
+               throw new RuntimeException(e);
+            }
+            catch (InvocationTargetException e)
+            {
+               throw e.getTargetException();
+            }
+         }
+
+         public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
+         {
+            return isTransacted;
+         }
+      };
+
+
+      EndpointFactory mef = new EndpointFactory();
+      mef.setContainer(container);
+      mef.setLoader(classLoader);
+      mef.setMessagingType(messagingType);
+      mef.start();
+      bridge.setActivationProperties(activationSpec);
+      bridge.setAdapter(adapter);
+      bridge.setMessageEndpointFactory(mef);
+      bridge.setMessagingTypeClass(messagingType);
+   }
+
+   protected void doRun()
+   {
+      ServiceInvoker invoker = new ServiceInvoker();
+      invoker.setCategory(this.serviceCategory);
+      invoker.setName(this.serviceName);
+      invoker.start();
+      bean.setServiceInvoker(invoker);
+      bridge.activate();
+      
+   }
+
+
+   protected void doStop() throws ManagedLifecycleException
+   {
+      bridge.deactivate();
+   }
+}




More information about the jboss-svn-commits mailing list