You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ri...@apache.org on 2007/01/15 12:47:20 UTC

svn commit: r496285 - in /incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko: ORBConfigAdapter.java RMIStubHandler.java RMIStubHandlerFactory.java

Author: rickmcguire
Date: Mon Jan 15 03:47:19 2007
New Revision: 496285

URL: http://svn.apache.org/viewvc?view=rev&rev=496285
Log:
OPENEJB-443 RMI stub interceptors not working with Yoko.

Added:
    incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java   (with props)
    incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java   (with props)
Modified:
    incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/ORBConfigAdapter.java

Modified: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/ORBConfigAdapter.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/ORBConfigAdapter.java?view=diff&rev=496285&r1=496284&r2=496285
==============================================================================
--- incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/ORBConfigAdapter.java (original)
+++ incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/ORBConfigAdapter.java Mon Jan 15 03:47:19 2007
@@ -95,10 +95,11 @@
         // this tells the openejb UtilDelegateImpl which implementation to delegate non-overridden
         // operations to.
         System.setProperty("org.apache.openejb.corba.UtilDelegateClass", "org.apache.yoko.rmi.impl.UtilImpl");
+        // this allows us to hook RMI stub invocation/serialization events. 
+        System.setProperty("org.apache.yoko.rmi.RMIStubInitializerClass", "org.apache.openejb.yoko.RMIStubHandlerFactory");
 
         // ok, now we have a potential classloading problem because of where our util delegates are located.
         // by forcing these classes to load now using our class loader, we can ensure things are properly initialized
-        this.getClass().getClassLoader().loadClass("javax.rmi.PortableRemoteObject");
         this.getClass().getClassLoader().loadClass("javax.rmi.PortableRemoteObject");
 
         log.debug("Started  Yoko ORBConfigAdapter");

Added: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java?view=auto&rev=496285
==============================================================================
--- incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java (added)
+++ incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java Mon Jan 15 03:47:19 2007
@@ -0,0 +1,90 @@
+/**
+*
+* 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.yoko;
+
+import javax.ejb.EJBHome;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.yoko.rmi.impl.MethodDescriptor;
+import org.apache.yoko.rmi.impl.RMIStub; 
+
+import org.omg.CORBA.ORB;
+import org.apache.openejb.corba.CorbaApplicationServer;
+import org.apache.openejb.corba.CORBAEJBMemento;
+import org.apache.openejb.corba.ClientContext;
+import org.apache.openejb.corba.ClientContextHolder;
+import org.apache.openejb.corba.ClientContextManager;
+import org.apache.openejb.server.ServerFederation;
+import org.apache.openejb.spi.ApplicationServer;
+import org.apache.openejb.proxy.SerializationHandler;
+import org.apache.openejb.proxy.ReplacementStrategy;
+
+/**
+ * This class is the InvocationHandler for instances of POAStub. When a client
+ * calls a remote method, this is translated to a call to the invoke() method in
+ * this class.
+ */
+public class RMIStubHandler extends org.apache.yoko.rmi.impl.RMIStubHandler {
+    // the application server singleton
+    private static CorbaApplicationServer corbaApplicationServer = new CorbaApplicationServer();
+    // the client context this stub was created under 
+    private final ClientContext clientContext;
+    
+    public RMIStubHandler() {
+        clientContext = ClientContextManager.getClientContext();
+    }
+
+    public Object stubWriteReplace(RMIStub stub) {
+        String ior = getOrb().object_to_string(stub);
+        return new CORBAEJBMemento(ior, stub instanceof EJBHome);
+    }
+    
+    public Object invoke(RMIStub stub, MethodDescriptor method, Object[] args) throws Throwable {
+        ClientContext oldContext = ClientContextManager.getClientContext();
+        // object types must bbe written in the context of the corba application server
+        // which properly write replaces our objects for corba
+        ApplicationServer oldApplicationServer = ServerFederation.getApplicationServer();
+
+        ServerFederation.setApplicationServer(corbaApplicationServer);
+        SerializationHandler.setStrategy(ReplacementStrategy.REPLACE);
+
+        try {
+            ClientContextManager.setClientContext(clientContext);
+            // let the super class handle everything.  We just need to wrap the context 
+            return super.invoke(stub, method, args); 
+            
+        } finally {
+            ServerFederation.setApplicationServer(oldApplicationServer);
+            SerializationHandler.setStrategy(null);
+            ClientContextManager.setClientContext(oldContext);
+        }
+    }
+    
+    private static ORB getOrb() {
+        try {
+            Context context = new InitialContext();
+            ORB orb = (ORB) context.lookup("java:comp/ORB");
+            return orb;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find ORB in jndi at java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+}
+

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java?view=auto&rev=496285
==============================================================================
--- incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java (added)
+++ incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java Mon Jan 15 03:47:19 2007
@@ -0,0 +1,41 @@
+/**
+*
+* 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.yoko;
+
+/**
+ * Implementation of the yoko StubInitializer class to provide instances 
+ * of RMIStubHandlers to Stub instances. 
+ */
+public class RMIStubHandlerFactory implements org.apache.yoko.rmi.util.stub.StubInitializer {
+    public RMIStubHandlerFactory() {
+    }
+    
+    /**
+     * Provide an RMIStub instance with an RMIStubHandler instance.  This version
+     * instantiates a new handler for each stub instance because the handler 
+     * needs to be initialized with the appropriate execution context. 
+     * 
+     * @return An instance of StubHandler that hooks the RMI stub invocation into the openejb
+     *         context.
+     */
+    public Object getStubHandler() {
+        return new RMIStubHandler(); 
+    }
+}
+

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/openejb/trunk/openejb2/modules/openejb-yoko/src/main/java/org/apache/openejb/yoko/RMIStubHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain