This is an automated email from the ASF dual-hosted git repository. jgallimore pushed a commit to branch tomee-1.7.x in repository https://gitbox.apache.org/repos/asf/tomee.git
commit 25dd8c7e76141be9babc349792eba859ed8feb02 Author: rmannibucau <[email protected]> AuthorDate: Tue May 2 17:09:52 2017 +0200 better corba extraction --- .../java/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(-) 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 bcc9a5b..42df723 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); 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 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); + } +}
