[jboss-svn-commits] JBL Code SVN: r21021 - labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 13 07:42:03 EDT 2008


Author: mark.little at jboss.com
Date: 2008-07-13 07:42:02 -0400 (Sun, 13 Jul 2008)
New Revision: 21021

Modified:
   labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1729

Modified: labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java	2008-07-13 11:29:35 UTC (rev 21020)
+++ labs/jbossesb/trunk/product/services/slsb/src/main/java/org/jboss/soa/esb/actions/EJBProcessor.java	2008-07-13 11:42:02 UTC (rev 21021)
@@ -43,6 +43,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.actions.ActionLifecycleException;
 import org.jboss.soa.esb.actions.ActionProcessingException;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
@@ -77,7 +78,10 @@
     private Map<Integer, Argument> ejbParams;
 
     private List<String> ejbParamTypeNames;
-
+    
+    private EJBHome ejbHome;
+    private EJBObject ejbObject;
+    
     public EJBProcessor(ConfigTree config)
     {
         configTree = config;
@@ -86,6 +90,45 @@
     public Message process (Message msg) throws ActionProcessingException,
             ConfigurationException
     {
+        try
+        {
+            // Assemble parameter array
+            Object[] param = new Object[ejbParams.size()];
+            for (int i = 0; i < ejbParams.size(); i++)
+            {
+                // get the parameter from the esb message and
+                // cast it to the in the jboss-esb.xml specified type
+                param[i] = Class.forName(ejbParams.get(i).getType()).cast(
+                        msg.getBody().get(ejbParams.get(i).getLoc()));
+            }
+
+            msg.getBody().add(
+                    ejbRef.get(OUT_VAR),
+                    this.invoke(ejbHome.getEJBMetaData().getRemoteInterfaceClass(), ejbObject, ejbRef.get(EJB_METHOD),
+                            param));
+            log.debug("###########################################");
+            log.debug(msg);
+            log.debug("###########################################");
+
+        }
+        catch (Exception e)
+        {
+            throw new ActionProcessingException(
+                    "Got an error while processing EJB " + ejbRef.get(EJB_NAME),
+                    new Throwable(e.getCause()));
+        }
+
+        return msg;
+    }
+
+    public void initialise () throws ActionLifecycleException
+    {
+        /*
+         * Only do the lookup once. We can do this because
+         * all of this data is statically defined and not
+         * modified by the incoming Message during process execution.
+         */
+        
         ejbRef = new HashMap<String, String>();
         ejbParams = new HashMap<Integer, Argument>();
         ejbParamTypeNames = new ArrayList<String>();
@@ -96,6 +139,7 @@
         ejbRef.put(EJB_METHOD, configTree.getAttribute(EJB_METHOD));
         ejbRef.put(INICTXFACTORY, configTree.getAttribute(INICTXFACTORY));
         ejbRef.put(PROVIDERURL, configTree.getAttribute(PROVIDERURL));
+        
         if (configTree.getAttribute(OUT_VAR) != null)
         {
             ejbRef.put(OUT_VAR, configTree.getAttribute(OUT_VAR));
@@ -127,7 +171,7 @@
         {
             if (conf == null)
             {
-                throw new ConfigurationException(
+                throw new ActionLifecycleException(
                         "Error configuring EJBProcessor");
             }
         }
@@ -144,55 +188,33 @@
             InitialContext iniCtx = new InitialContext(props);
 
             // Lookup and narrow
-            EJBHome home = (EJBHome) PortableRemoteObject.narrow(
+            ejbHome = (EJBHome) PortableRemoteObject.narrow(
                     (EJBHome) iniCtx.lookup(ejbRef.get(JNDI_NAME)),
                     EJBHome.class);
 
             // Get the EJB metadata
-            EJBMetaData metaData = home.getEJBMetaData();
+            EJBMetaData metaData = ejbHome.getEJBMetaData();
             Class homeClass = metaData.getHomeInterfaceClass();
-            Class remoteClass = metaData.getRemoteInterfaceClass();
 
             // convert handle to real home type
-            home = (EJBHome) javax.rmi.PortableRemoteObject.narrow(home,
+            ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(ejbHome,
                     homeClass);
 
             if (!(metaData.isSession() && metaData.isStatelessSession()))
             {
-                throw new ActionProcessingException("Only SLSBs are supported!");
+                throw new ActionLifecycleException("Only SLSBs are supported!");
             }
 
-            EJBObject theRemote = (EJBObject) this.create(homeClass, home);
-
-            // Assemble parameter array
-            Object[] param = new Object[ejbParams.size()];
-            for (int i = 0; i < ejbParams.size(); i++)
-            {
-                // get the parameter from the esb message and
-                // cast it to the in the jboss-esb.xml specified type
-                param[i] = Class.forName(ejbParams.get(i).getType()).cast(
-                        msg.getBody().get(ejbParams.get(i).getLoc()));
-            }
-
-            msg.getBody().add(
-                    ejbRef.get(OUT_VAR),
-                    this.invoke(remoteClass, theRemote, ejbRef.get(EJB_METHOD),
-                            param));
-            log.debug("###########################################");
-            log.debug(msg);
-            log.debug("###########################################");
-
+            ejbObject = (EJBObject) this.create(homeClass, ejbHome);
         }
         catch (Exception e)
         {
-            throw new ActionProcessingException(
+            throw new ActionLifecycleException(
                     "Got an error while processing EJB " + ejbRef.get(EJB_NAME),
                     new Throwable(e.getCause()));
         }
-
-        return msg;
     }
-
+    
     private static Object create (Class c, Object obj) throws Exception
     {
         Object ret = null;
@@ -225,7 +247,7 @@
 
         return r;
     }
-
+    
     // Helper inner class for method arguments and where to find it in the esb
     // message
     class Argument




More information about the jboss-svn-commits mailing list