You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2017/05/02 15:09:58 UTC

tomee git commit: better corba extraction

Repository: tomee
Updated Branches:
  refs/heads/master 49b1d1469 -> 55a598e40


better corba extraction


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/55a598e4
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/55a598e4
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/55a598e4

Branch: refs/heads/master
Commit: 55a598e400f19c05b140a72962d5b9acc3d92d41
Parents: 49b1d14
Author: rmannibucau <rm...@apache.org>
Authored: Tue May 2 17:09:52 2017 +0200
Committer: rmannibucau <rm...@apache.org>
Committed: Tue May 2 17:09:52 2017 +0200

----------------------------------------------------------------------
 .../org/apache/openejb/client/EJBRequest.java   | 14 ++++++-
 .../org/apache/openejb/client/corba/Corbas.java | 15 +++-----
 .../apache/openejb/client/corba/InstanceOf.java | 39 ++++++++++++++++++++
 3 files changed, 57 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/55a598e4/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
index b2ee800..efc0723 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
@@ -17,13 +17,16 @@
 package org.apache.openejb.client;
 
 import org.apache.openejb.client.corba.Corbas;
+import org.apache.openejb.client.corba.InstanceOf;
 import org.apache.openejb.client.serializer.EJBDSerializer;
 import org.apache.openejb.client.serializer.SerializationWrapper;
 
+import javax.rmi.PortableRemoteObject;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.lang.reflect.Method;
+import java.rmi.Remote;
 import java.util.Arrays;
 
 public class EJBRequest implements ClusterableRequest {
@@ -550,7 +553,9 @@ public class EJBRequest implements ClusterableRequest {
                         throw new IOException("Unkown primitive type: " + clazz);
                     }
                 } else {
-                    obj = Corbas.toStub(obj);
+                    if (PortableRemoteObject.class.isInstance(obj) && Remote.class.isInstance(obj)) {
+                        obj = Corbas.toStub(obj);
+                    }
                     out.write(OBJECT);
                     out.writeObject(clazz);
                     out.writeObject(obj);
@@ -625,7 +630,12 @@ public class EJBRequest implements ClusterableRequest {
 
                     case OBJECT:
                         clazz = (Class) in.readObject();
-                        obj = Corbas.connect(in.readObject());
+                        final Object read = in.readObject();
+                        if (InstanceOf.isStub(read)) {
+                            obj = Corbas.connect(read);
+                        } else {
+                            obj = read;
+                        }
                         break;
                     default:
                         throw new IOException("Unkown data type: " + type);

http://git-wip-us.apache.org/repos/asf/tomee/blob/55a598e4/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java b/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java
index 2d765e3..f7c06d9 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java
@@ -31,16 +31,13 @@ public class Corbas {
     }
 
     public static Object toStub(final Object obj) throws IOException {
-        if (obj instanceof PortableRemoteObject && obj instanceof Remote) {
-            final Tie tie = javax.rmi.CORBA.Util.getTie((Remote) obj);
-            if (tie == null) {
-                throw new IOException("Unable to serialize PortableRemoteObject; object has not been exported: " + obj);
-            }
-            final ORB orb = getORB();
-            tie.orb(orb);
-            return PortableRemoteObject.toStub((Remote) obj);
+        final Tie tie = javax.rmi.CORBA.Util.getTie((Remote) obj);
+        if (tie == null) {
+            throw new IOException("Unable to serialize PortableRemoteObject; object has not been exported: " + obj);
         }
-        return obj;
+        final ORB orb = getORB();
+        tie.orb(orb);
+        return PortableRemoteObject.toStub((Remote) obj);
     }
 
     private static ORB getORB() throws IOException { // note: we can cache it if needed but needs to be contextual

http://git-wip-us.apache.org/repos/asf/tomee/blob/55a598e4/server/openejb-client/src/main/java/org/apache/openejb/client/corba/InstanceOf.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/corba/InstanceOf.java b/server/openejb-client/src/main/java/org/apache/openejb/client/corba/InstanceOf.java
new file mode 100644
index 0000000..80c76c2
--- /dev/null
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/corba/InstanceOf.java
@@ -0,0 +1,39 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.client.corba;
+
+public final class InstanceOf {
+    private static final Class<?> STUB;
+
+    static {
+        Class<?> stub = null;
+        try {
+            stub = Thread.currentThread().getContextClassLoader().loadClass("javax.rmi.CORBA.Stub");
+        } catch (ClassNotFoundException e) {
+            // no-op
+        }
+        STUB = stub;
+    }
+
+    private InstanceOf() {
+        // no-op
+    }
+
+    public static boolean isStub(final Object instance) {
+        return STUB != null && STUB.isInstance(instance);
+    }
+}