geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r738102 - in /geronimo/plugins/tuscany/trunk: ./ geronimo-tuscany-implementation-ejb/ geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/ geronimo-tuscany-implementation-ejb/src/main/java/...
Date Tue, 27 Jan 2009 14:47:26 GMT
Author: vamsic007
Date: Tue Jan 27 14:47:25 2009
New Revision: 738102

URL: http://svn.apache.org/viewvc?rev=738102&view=rev
Log:
Add support for exposing SCA services from Session EJBs.

Added:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/
    geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
  (with props)
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
  (with props)
Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/pom.xml
    geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/runtime/EJBImplementationProviderFactory.java
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
    geronimo/plugins/tuscany/trunk/pom.xml

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/pom.xml?rev=738102&r1=738101&r2=738102&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/pom.xml Tue Jan 27
14:47:25 2009
@@ -31,6 +31,22 @@
     <name>Geronimo Plugins :: Tuscany Implementation EJB Runtime for Geronimo</name>
 
     <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.plugins</groupId>
+            <artifactId>geronimo-tuscany</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+    
+        <!-- Geronimo dependencies -->
+        <dependency>
+            <groupId>org.apache.geronimo.framework</groupId>
+            <artifactId>geronimo-kernel</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-openejb</artifactId>
+        </dependency>
+
         <!-- Tuscany dependencies -->
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java?rev=738102&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
Tue Jan 27 14:47:25 2009
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.sca.implementation.ejb.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.openejb.EjbDeployment;
+import org.apache.geronimo.tuscany.ComponentMapHelper;
+import org.apache.tuscany.sca.implementation.ejb.EJBImplementation;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * A class to invoke a service method from an EJB SCA component.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class EjbImplementationInvoker implements Invoker, DataExchangeSemantics {
+
+    protected Operation operation;
+    protected RuntimeComponent rtc;
+    protected RuntimeComponentService service;
+    
+    public EjbImplementationInvoker(Operation operation, RuntimeComponent rtc, RuntimeComponentService
service) {
+        this.operation = operation;
+        this.rtc = rtc;
+        this.service = service;
+    }
+
+    public Message invoke(Message msg) {
+        Operation op = msg.getOperation();
+        if (op == null) {
+            op = this.operation;
+        }
+        Object payload = msg.getBody();
+        
+        try {
+            // FIXME: Is there a better way to locate the configuration containing this EJB?
+            String componentName = rtc.getName();
+            Artifact artifact = Artifact.create(ComponentMapHelper.componentMap.get(componentName));
+            
+            Kernel kernel = KernelRegistry.getSingleKernel();
+            // Locate the GBean corresponding to this EJB.
+            Map<String, String> map = new HashMap<String, String>();
+            map.put("name", ((EJBImplementation)rtc.getImplementation()).getEJBLink());
+            AbstractNameQuery query = new AbstractNameQuery(artifact, map);
+            Set<AbstractName> gbeans = kernel.listGBeans(query);
+            AbstractName ejbGbeanName = (AbstractName)gbeans.iterator().next();
+
+            // Create a proxy to the EJB via the business remote home interface.
+            Method method;
+            EjbDeployment ejbGbean = (EjbDeployment)kernel.getProxyManager().createProxy(ejbGbeanName,
EjbDeployment.class);
+            Object ejbHome = ejbGbean.getBusinessRemoteHome();
+            method = ejbHome.getClass().getMethod("create");
+            Object ejb = method.invoke(ejbHome);
+            
+            // Locate the method that corresponds to the service operation and invoke the
method.
+            method = JavaInterfaceUtil.findMethod(ejb.getClass(), op);
+            Object ret;
+            if (payload != null && !payload.getClass().isArray()) {
+                ret = method.invoke(ejb, payload);
+            } else {
+                ret = method.invoke(ejb, (Object[])payload);
+            }
+            msg.setBody(ret);
+        } catch (InvocationTargetException e) {
+            Throwable cause = e.getTargetException();
+            boolean isChecked = false;
+            for (DataType<?> d : operation.getFaultTypes()) {
+                if (d.getPhysical().isInstance(cause)) {
+                    isChecked = true;
+                    msg.setFaultBody(cause);
+                    break;
+                }
+            }
+            if (!isChecked) {
+                if (cause instanceof RuntimeException) {
+                    throw (RuntimeException)cause;
+                }
+                if (cause instanceof Error) {
+                    throw (Error)cause;
+                } else {
+                    throw new ServiceRuntimeException(cause.getMessage(), cause);
+                }
+            }            
+        } catch(Exception e) {
+            msg.setFaultBody(e);           
+        }
+        return msg;
+    }
+
+    public boolean allowsPassByReference() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/invocation/EjbImplementationInvoker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/runtime/EJBImplementationProviderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/runtime/EJBImplementationProviderFactory.java?rev=738102&r1=738101&r2=738102&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/runtime/EJBImplementationProviderFactory.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-implementation-ejb/src/main/java/org/apache/tuscany/sca/implementation/ejb/runtime/EJBImplementationProviderFactory.java
Tue Jan 27 14:47:25 2009
@@ -24,6 +24,7 @@
 import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
 import org.apache.tuscany.sca.databinding.impl.MediatorImpl;
 import org.apache.tuscany.sca.implementation.ejb.EJBImplementation;
+import org.apache.tuscany.sca.implementation.ejb.invocation.EjbImplementationInvoker;
 import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Invoker;
@@ -60,8 +61,7 @@
             this.component = component;
         }
         public Invoker createInvoker(RuntimeComponentService service, Operation operation)
{
-            //TODO: Update when service invocation on EJBs is supported.
-            return null;
+            return new EjbImplementationInvoker(operation, component, service);
         }
         public void start() {
             ((ComponentContextImpl)component.getComponentContext()).setPropertyValueFactory(propertyValueFactory);

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java?rev=738102&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
Tue Jan 27 14:47:25 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.geronimo.tuscany;
+
+import java.util.HashMap;
+import java.util.Map;
+/**
+ * This class is used to maintain a mapping of components in the SCA Domain to the geronimo
configuration that
+ * deployed the component. This class must be done away with once there is a better way of
propagating this info
+ * to the EJBImplementationInvoker. 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ComponentMapHelper {
+    public static Map<String, String> componentMap = new HashMap<String, String>();
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ComponentMapHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java?rev=738102&r1=738101&r2=738102&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
Tue Jan 27 14:47:25 2009
@@ -55,6 +55,7 @@
     private Collection repositories;
     private AbstractName abstractName;
     private String jarFileName;
+    private List<String> components = new ArrayList<String>();
     
     public EmbeddedRuntimeGBean(EmbeddedSCADomainGBean embeddedSCADomainRef, ClassLoader
classLoader, Collection repositories, AbstractName abstractName){
         this.embeddedSCADomainRef = embeddedSCADomainRef;
@@ -116,6 +117,28 @@
         //}
         eScaDomain.getCompositeActivator().start(eScaDomain.getDomainComposite());
         
+        components.clear();
+        // Keep track of components that are added to SCA Domain from this configuration
+        for(Composite composite: composites) {
+            for(int i = 0; i < composite.getComponents().size(); ++i) {
+                Component component = null;
+                for(Component temp : eScaDomain.getDomainComposite().getComponents()) {
+                    if(temp.getName().equals(composite.getComponents().get(i).getName()))
{
+                        component = temp;
+                        break;
+                    }
+                }
+                if(component != null) {
+                    components.add(component.getName());
+                }
+            }
+        }
+        // FIXME: This mapping is used to search gbean corresponding to EJB components.
+        // Is there a better way to locate which configuration contains the EJB?
+        for(String componentName : components) {
+            ComponentMapHelper.componentMap.put(componentName, abstractName.getArtifact().toString());
+        }
+        
         scaDomain = eScaDomain;
         log.debug("EmbeddedRuntimeGBean started. Name=" + abstractName);
     }
@@ -169,6 +192,11 @@
                     eScaDomain.getDomainComposite().getComponents().remove(component);
                 }
             }
+            
+            // Remove components from the map
+            for(String componentName : components) {
+                ComponentMapHelper.componentMap.remove(componentName);
+            }
 
             // Remove contribution
             eScaDomain.getContributionService().remove(contributionRoot);

Modified: geronimo/plugins/tuscany/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/pom.xml?rev=738102&r1=738101&r2=738102&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/pom.xml Tue Jan 27 14:47:25 2009
@@ -265,6 +265,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.geronimo.modules</groupId>
+                <artifactId>geronimo-openejb</artifactId>
+                <version>${geronimoVersion}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.geronimo.modules</groupId>
                 <artifactId>geronimo-openejb-builder</artifactId>
                 <version>${geronimoVersion}</version>
             </dependency>



Mime
View raw message