You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/04/25 19:48:55 UTC
[tomee] 22/26: extracting corba rmi types in an utility class for
now
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 58dfb991826cdbbe10e727bd2968b92c417f0e25
Author: rmannibucau <rm...@apache.org>
AuthorDate: Mon May 1 21:31:37 2017 +0200
extracting corba rmi types in an utility class for now
---
.../org/apache/openejb/config/RemoteServer.java | 3 +-
.../java/org/apache/openejb/client/EJBRequest.java | 64 +--------------------
.../org/apache/openejb/client/corba/Corbas.java | 67 ++++++++++++++++++++++
3 files changed, 72 insertions(+), 62 deletions(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
index 50c0fa9..4ae0806 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
@@ -295,7 +295,8 @@ public class RemoteServer {
if (!addedArgs.containsKey("-Djava.io.tmpdir")) {
argsList.add("-Djava.io.tmpdir=" + temp.getAbsolutePath());
}
- if (!addedArgs.containsKey("-Djava.endorsed.dirs")) {
+ if ((javaVersion.startsWith("1.7") || javaVersion.startsWith("1.8")) && // java 9 dropped endorsed folder
+ !addedArgs.containsKey("-Djava.endorsed.dirs") && endorsed.exists()) {
argsList.add("-Djava.endorsed.dirs=" + endorsed.getAbsolutePath());
}
if (!addedArgs.containsKey("-Dcatalina.base")) {
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 e26c7e9..bcc9a5b 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
@@ -16,20 +16,14 @@
*/
package org.apache.openejb.client;
+import org.apache.openejb.client.corba.Corbas;
import org.apache.openejb.client.serializer.EJBDSerializer;
import org.apache.openejb.client.serializer.SerializationWrapper;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.rmi.CORBA.Stub;
-import javax.rmi.CORBA.Tie;
-import javax.rmi.PortableRemoteObject;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.rmi.Remote;
import java.util.Arrays;
public class EJBRequest implements ClusterableRequest {
@@ -556,22 +550,7 @@ public class EJBRequest implements ClusterableRequest {
throw new IOException("Unkown primitive type: " + clazz);
}
} else {
- 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 Object orb = getORB();
- try {
- tie.getClass().getMethod("orb", Thread.currentThread().getContextClassLoader().loadClass("org.omg.CORBA.ORB"))
- .invoke(tie, orb);
- } catch (final ClassNotFoundException | IllegalAccessException | NoSuchMethodException e) {
- throw new IllegalStateException("No CORBA available", e);
- } catch (final InvocationTargetException e) {
- throw new IllegalStateException("No CORBA available", e.getCause());
- }
- obj = PortableRemoteObject.toStub((Remote) obj);
- }
+ obj = Corbas.toStub(obj);
out.write(OBJECT);
out.writeObject(clazz);
out.writeObject(obj);
@@ -583,31 +562,6 @@ public class EJBRequest implements ClusterableRequest {
static final Object[] noArgsO = new Object[0];
/**
- * Obtain an ORB instance for this request to activate remote
- * arguments and return results.
- *
- * @return An ORB instance.
- * @throws java.io.IOException On error
- */
- protected Object getORB() throws IOException {
- // first ORB request? Check our various sources
- if (orb == null) {
- try {
- final Context initialContext = new InitialContext();
- orb = initialContext.lookup("java:comp/ORB");
- } catch (final Throwable e) {
- try {
- // any orb will do if we can't get a context one.
- orb = Thread.currentThread().getContextClassLoader().loadClass("org.omg.CORBA.ORB").getMethod("init").invoke(null);
- } catch (final Throwable ex) {
- throw new IOException("Unable to connect PortableRemoteObject stub to an ORB, no ORB bound to java:comp/ORB");
- }
- }
- }
- return orb;
- }
-
- /**
* Changes to this method must observe the optional {@link #metaData} version
*/
protected void readMethodParameters(final ObjectInput in) throws IOException, ClassNotFoundException {
@@ -671,19 +625,7 @@ public class EJBRequest implements ClusterableRequest {
case OBJECT:
clazz = (Class) in.readObject();
- obj = in.readObject();
- if (obj instanceof Stub) {
- final Stub stub = (Stub) obj;
- final Object orb = getORB();
- try {
- stub.getClass().getMethod("connect", Thread.currentThread().getContextClassLoader().loadClass("org.omg.CORBA.ORB"))
- .invoke(stub, orb);
- } catch (final ClassNotFoundException | IllegalAccessException | NoSuchMethodException e) {
- throw new IllegalStateException("No CORBA available", e);
- } catch (final InvocationTargetException e) {
- throw new IllegalStateException("No CORBA available", e.getCause());
- }
- }
+ obj = Corbas.connect(in.readObject());
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
new file mode 100644
index 0000000..2d765e3
--- /dev/null
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/corba/Corbas.java
@@ -0,0 +1,67 @@
+/**
+ * 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;
+
+import org.omg.CORBA.ORB;
+
+import javax.naming.InitialContext;
+import javax.rmi.CORBA.Stub;
+import javax.rmi.CORBA.Tie;
+import javax.rmi.PortableRemoteObject;
+import java.io.IOException;
+import java.rmi.Remote;
+
+public class Corbas {
+ private Corbas() {
+ // no-op
+ }
+
+ 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);
+ }
+ return obj;
+ }
+
+ private static ORB getORB() throws IOException { // note: we can cache it if needed but needs to be contextual
+ try {
+ return ORB.class.cast(new InitialContext().lookup("java:comp/ORB"));
+ } catch (final Throwable e) {
+ try {
+ // any orb will do if we can't get a context one.
+ return ORB.init();
+ } catch (final Throwable ex) {
+ throw new IOException("Unable to connect PortableRemoteObject stub to an ORB, no ORB bound to java:comp/ORB");
+ }
+ }
+ }
+
+ public static Object connect(final Object obj) throws IOException {
+ if (obj instanceof Stub) {
+ final Stub stub = (Stub) obj;
+ final ORB orb = getORB();
+ stub.connect(orb);
+ }
+ return obj;
+ }
+}