dain 2005/06/22 20:56:43
Modified: modules/core/src/java/org/openejb/corba/util
DynamicStubClassLoader.java
StubMethodInterceptor.java
Added: modules/core/src/java/org/openejb/corba/util
StubDelegateImpl.java
Removed: modules/core/src/java/org/openejb/corba/util
ClientContextHolderStub.java
Log:
Removed PortableStubGenerator since it is totally broken. We now use
DynamicStubClassLoader instead.
Added StubDelegate to handle assigning ClientDelegate objects to new stubs
Removed ClienContextHolder since it is no longer used
Fixed several marshalling errors in the StubMethodInterceptor
Revision Changes Path
1.2 +5 -5
openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java
Index: DynamicStubClassLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/DynamicStubClassLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynamicStubClassLoader.java 22 Jun 2005 19:39:52 -0000 1.1
+++ DynamicStubClassLoader.java 23 Jun 2005 00:56:43 -0000 1.2
@@ -50,6 +50,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import javax.rmi.CORBA.Stub;
import net.sf.cglib.core.NamingPolicy;
import net.sf.cglib.core.Predicate;
@@ -65,7 +66,6 @@
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.openejb.corba.ClientContextHolder;
import org.openejb.corba.compiler.PortableStubCompiler;
@@ -112,8 +112,8 @@
// create the stub builder
try {
Enhancer enhancer = new Enhancer();
- enhancer.setSuperclass(ClientContextHolderStub.class);
- enhancer.setInterfaces(new Class[]{iface,
ClientContextHolder.class});
+ enhancer.setSuperclass(Stub.class);
+ enhancer.setInterfaces(new Class[]{iface});
enhancer.setCallbackFilter(FILTER);
enhancer.setCallbackTypes(new Class[]{NoOp.class,
MethodInterceptor.class, FixedValue.class});
enhancer.setUseFactory(false);
1.2 +24 -35
openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java
Index: StubMethodInterceptor.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/StubMethodInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StubMethodInterceptor.java 22 Jun 2005 19:39:52 -0000 1.1
+++ StubMethodInterceptor.java 23 Jun 2005 00:56:43 -0000 1.2
@@ -53,6 +53,7 @@
import java.util.HashMap;
import java.util.Map;
import javax.rmi.CORBA.Util;
+import javax.rmi.CORBA.Stub;
import javax.rmi.PortableRemoteObject;
import net.sf.cglib.proxy.MethodInterceptor;
@@ -65,9 +66,6 @@
import org.omg.CORBA.portable.ServantObject;
import org.omg.CORBA_2_3.portable.InputStream;
import org.omg.CORBA_2_3.portable.OutputStream;
-import org.openejb.corba.ClientContext;
-import org.openejb.corba.ClientContextHolder;
-import org.openejb.corba.ClientContextManager;
import org.openejb.corba.compiler.IiopOperation;
import org.openejb.corba.compiler.PortableStubCompiler;
@@ -91,7 +89,7 @@
}
public Object intercept(Object proxy, Method method, Object[] args,
MethodProxy methodProxy) throws Throwable {
- ClientContextHolderStub stub = ((ClientContextHolderStub) proxy);
+ Stub stub = ((Stub) proxy);
// get the operation name object
String operationName = (String) operations.get(method);
@@ -101,14 +99,10 @@
while (true) {
// if this is a stub to a remote object we invoke over the wire
- ClientContext context = stub.getClientContext();
if (!Util.isLocal(stub)) {
- ClientContext saved =
ClientContextManager.getClientContext();
InputStream in = null;
try {
- ClientContextManager.setClientContext(context);
-
// create the request output stream
OutputStream out = (OutputStream)
stub._request(operationName, true);
@@ -120,9 +114,6 @@
// read the result
Object result = readResult(method.getReturnType(), in);
- if (result instanceof ClientContextHolder) {
- ((ClientContextHolder)
result).setClientContext(context);
- }
return result;
} catch (RemarshalException exception) {
continue;
@@ -131,12 +122,9 @@
} catch (SystemException e) {
throw Util.mapSystemException(e);
} finally {
- ClientContextManager.setClientContext(saved);
stub._releaseReply(in);
}
} else {
- ClientContext saved =
ClientContextManager.getClientContext();
-
// get the servant
ServantObject servantObject =
stub._servant_preinvoke(operationName, type);
if (servantObject == null) {
@@ -144,8 +132,6 @@
}
try {
- ClientContextManager.setClientContext(context);
-
// copy the arguments
Object[] argsCopy = Util.copyObjects(args, stub._orb());
@@ -161,11 +147,7 @@
}
// copy the result
-// result =
PortableRemoteObject.narrow(Util.copyObject(result, stub._orb()), String.class);
result = Util.copyObject(result, stub._orb());
- if (result instanceof ClientContextHolder) {
- ((ClientContextHolder)
result).setClientContext(context);
- }
return result;
} catch (Throwable throwable) {
@@ -183,7 +165,6 @@
throw Util.wrapException(throwableCopy);
} finally {
- ClientContextManager.setClientContext(saved);
stub._servant_postinvoke(servantObject);
}
}
@@ -217,17 +198,21 @@
out.write_longlong(((Long) result).longValue());
} else if (type == short.class) {
out.write_short(((Short) result).shortValue());
- } else if (type == Object.class) {
+ } else if (type == Object.class || type == Serializable.class) {
Util.writeAny(out, result);
} else if (Remote.class.isAssignableFrom(type)) {
Util.writeRemoteObject(out, result);
+ } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
+ out.write_Object((org.omg.CORBA.Object) result);
} else {
out.write_value((Serializable) result, type);
}
}
private static Object readResult(Class type, InputStream in) {
- if (type == boolean.class) {
+ if (type == void.class) {
+ return null;
+ } else if (type == boolean.class) {
return new Boolean(in.read_boolean());
} else if (type == byte.class) {
return new Byte(in.read_octet());
@@ -243,10 +228,12 @@
return new Long(in.read_longlong());
} else if (type == short.class) {
return new Short(in.read_short());
- } else if (type == Object.class) {
+ } else if (type == Object.class || type == Serializable.class) {
return Util.readAny(in);
} else if (Remote.class.isAssignableFrom(type)) {
return PortableRemoteObject.narrow(in.read_Object(), type);
+ } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
+ return in.read_Object();
} else {
return in.read_value(type);
}
@@ -254,28 +241,30 @@
private void readException(Method method, InputStream in) throws
Throwable {
// read the exception id
- String id = in.read_string();
+ final String id = in.read_string();
// get the class name from the id
if (!id.startsWith("IDL:")) {
log.warn("Malformed exception id: " + id);
return;
}
- String className = id.substring("IDL:".length());
- int index = className.lastIndexOf(':');
- if (index > 0) {
- className = className.substring(0, index);
- }
- className = className.replace('/', '.');
Class[] exceptionTypes = method.getExceptionTypes();
for (int i = 0; i < exceptionTypes.length; i++) {
Class exceptionType = exceptionTypes[i];
// if (RemoteException.class.isAssignableFrom(exceptionType) ||
-//
RuntimeException.class.isAssignableFrom(exceptionType)) {
+// RuntimeException.class.isAssignableFrom(exceptionType)
) {
// continue;
// }
- if (className.equals(exceptionType.getName())) {
+
+ // Determine the exception id
+ String exceptionName = exceptionType.getName().replace('.', '/');
+ if (exceptionName.endsWith("Exception")) {
+ exceptionName = exceptionName.substring(0,
exceptionName.length() - "Exception".length());
+ }
+ exceptionName += "Ex";
+ String exceptionId = "IDL:" + exceptionName + ":1.0";
+ if (id.equals(exceptionId)) {
throw (Throwable) in.read_value(exceptionType);
}
}
1.1
openejb/modules/core/src/java/org/openejb/corba/util/StubDelegateImpl.java
Index: StubDelegateImpl.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: StubDelegateImpl.java,v 1.1 2005/06/23 00:56:43 dain Exp $
*/
package org.openejb.corba.util;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.rmi.RemoteException;
import javax.rmi.CORBA.Stub;
import javax.rmi.CORBA.StubDelegate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.omg.CORBA.ORB;
import org.openejb.corba.ClientContext;
import org.openejb.corba.ClientContextManager;
/**
* @version $Revision: 1.1 $ $Date: 2005/06/23 00:56:43 $
*/
public class StubDelegateImpl implements StubDelegate {
private static final Log log = LogFactory.getLog(StubDelegateImpl.class);
private final static String DELEGATE_NAME =
"org.openejb.corba.StubDelegateClass";
private final StubDelegate delegate;
private ClientContext clientContext;
public StubDelegateImpl() throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
String value = System.getProperty(DELEGATE_NAME);
if (value == null) {
log.error("No delegate specfied via " + DELEGATE_NAME);
throw new IllegalStateException("The property " + DELEGATE_NAME +
" must be defined!");
}
if (log.isDebugEnabled()) log.debug("Set delegate " + value);
delegate = (StubDelegate)
StubDelegateImpl.class.getClassLoader().loadClass(value).newInstance();
}
public int hashCode(Stub self) {
return delegate.hashCode(self);
}
public boolean equals(Stub self, Object obj) {
return delegate.equals(self, obj);
}
public String toString(Stub self) {
return delegate.toString(self);
}
public void connect(Stub self, ORB orb) throws RemoteException {
delegate.connect(self, orb);
clientContext = ClientContextManager.getClientContext();
}
public void readObject(Stub self, ObjectInputStream s) throws
IOException, ClassNotFoundException {
ClientContext oldClientContext =
ClientContextManager.getClientContext();
try {
ClientContextManager.setClientContext(clientContext);
delegate.readObject(self, s);
} finally {
ClientContextManager.setClientContext(oldClientContext);
}
}
public void writeObject(Stub self, ObjectOutputStream s) throws
IOException {
delegate.writeObject(self, s);
}
}