djencks 2005/06/23 02:59:19
Modified: modules/core/src/java/org/openejb/corba/util
DynamicStubClassLoader.java StubDelegateImpl.java
StubMethodInterceptor.java
Added: modules/core/src/java/org/openejb/corba/util
ClientContextHolderStub.java
Log:
Put the ClientContext back in the Stub so it is actually accessible from the
ClientSecurityInterceptor. I don't know if the code in StubDelegateImpl is
actually useful -- need an actual test case
Revision Changes Path
1.3 +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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DynamicStubClassLoader.java 23 Jun 2005 00:56:43 -0000 1.2
+++ DynamicStubClassLoader.java 23 Jun 2005 06:59:19 -0000 1.3
@@ -50,7 +50,6 @@
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;
@@ -67,6 +66,7 @@
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.openejb.corba.compiler.PortableStubCompiler;
+import org.openejb.corba.ClientContextHolder;
/**
@@ -112,8 +112,8 @@
// create the stub builder
try {
Enhancer enhancer = new Enhancer();
- enhancer.setSuperclass(Stub.class);
- enhancer.setInterfaces(new Class[]{iface});
+ enhancer.setSuperclass(ClientContextHolderStub.class);
+ enhancer.setInterfaces(new Class[]{iface,
ClientContextHolder.class});
enhancer.setCallbackFilter(FILTER);
enhancer.setCallbackTypes(new Class[]{NoOp.class,
MethodInterceptor.class, FixedValue.class});
enhancer.setUseFactory(false);
1.2 +16 -2
openejb/modules/core/src/java/org/openejb/corba/util/StubDelegateImpl.java
Index: StubDelegateImpl.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/util/StubDelegateImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StubDelegateImpl.java 23 Jun 2005 00:56:43 -0000 1.1
+++ StubDelegateImpl.java 23 Jun 2005 06:59:19 -0000 1.2
@@ -48,6 +48,9 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.rmi.RemoteException;
+import java.util.Map;
+import java.util.Collections;
+import java.util.WeakHashMap;
import javax.rmi.CORBA.Stub;
import javax.rmi.CORBA.StubDelegate;
@@ -66,6 +69,8 @@
private final StubDelegate delegate;
private ClientContext clientContext;
+ private static final Map stubToDelegateMap =
Collections.synchronizedMap(new WeakHashMap());
+
public StubDelegateImpl() throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
String value = System.getProperty(DELEGATE_NAME);
if (value == null) {
@@ -77,6 +82,10 @@
delegate = (StubDelegate)
StubDelegateImpl.class.getClassLoader().loadClass(value).newInstance();
}
+ public static StubDelegateImpl getDelegateForStub(Stub stub) {
+ return (StubDelegateImpl) stubToDelegateMap.get(stub);
+ }
+
public int hashCode(Stub self) {
return delegate.hashCode(self);
}
@@ -89,9 +98,14 @@
return delegate.toString(self);
}
+ public ClientContext getClientContext() {
+ return clientContext;
+ }
+
public void connect(Stub self, ORB orb) throws RemoteException {
delegate.connect(self, orb);
clientContext = ClientContextManager.getClientContext();
+ stubToDelegateMap.put(self, this);
}
public void readObject(Stub self, ObjectInputStream s) throws
IOException, ClassNotFoundException {
1.3 +93 -65
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StubMethodInterceptor.java 23 Jun 2005 00:56:43 -0000 1.2
+++ StubMethodInterceptor.java 23 Jun 2005 06:59:19 -0000 1.3
@@ -68,6 +68,9 @@
import org.omg.CORBA_2_3.portable.OutputStream;
import org.openejb.corba.compiler.IiopOperation;
import org.openejb.corba.compiler.PortableStubCompiler;
+import org.openejb.corba.ClientContext;
+import org.openejb.corba.ClientContextManager;
+import org.openejb.corba.ClientContextHolder;
/**
* @version $Revision$ $Date$
@@ -96,78 +99,99 @@
if (operationName == null) {
throw new IllegalStateException("Unknown method: " + method);
}
+ ClientContext oldContext = ClientContextManager.getClientContext();
- while (true) {
- // if this is a stub to a remote object we invoke over the wire
- if (!Util.isLocal(stub)) {
-
- InputStream in = null;
- try {
- // create the request output stream
- OutputStream out = (OutputStream)
stub._request(operationName, true);
-
- // write the arguments
- writeArguments(method, args, out);
-
- // send the invocation
- in = (InputStream) stub._invoke(out);
-
- // read the result
- Object result = readResult(method.getReturnType(), in);
- return result;
- } catch (RemarshalException exception) {
- continue;
- } catch (ApplicationException exception) {
- readException(method, (InputStream)
exception.getInputStream());
- } catch (SystemException e) {
- throw Util.mapSystemException(e);
- } finally {
- stub._releaseReply(in);
- }
- } else {
- // get the servant
- ServantObject servantObject =
stub._servant_preinvoke(operationName, type);
- if (servantObject == null) {
- continue;
- }
+ //first try the stub
+ ClientContextHolder holder = (ClientContextHolder) proxy;
+ ClientContext context = holder.getClientContext();
+
+ //if stub got deserialized rather than looked up via CSSBean, it
might not have the context
+ if (context == null) {
+ StubDelegateImpl delegate =
StubDelegateImpl.getDelegateForStub(stub);
+ if (delegate == null) {
+ throw new IllegalStateException("No StubDelegateImpl for
stub");
+ }
+ context = delegate.getClientContext();
+ //might as well set it for next time
+ holder.setClientContext(context);
+ }
+ try {
+ ClientContextManager.setClientContext(context);
- try {
- // copy the arguments
- Object[] argsCopy = Util.copyObjects(args, stub._orb());
+ while (true) {
+ // if this is a stub to a remote object we invoke over the
wire
+ if (!Util.isLocal(stub)) {
- // invoke the servant
- Object result = null;
+ InputStream in = null;
try {
- result = method.invoke(servantObject.servant,
argsCopy);
- } catch (InvocationTargetException e) {
- if (e.getCause() != null) {
- throw e.getCause();
- }
- throw e;
+ // create the request output stream
+ OutputStream out = (OutputStream)
stub._request(operationName, true);
+
+ // write the arguments
+ writeArguments(method, args, out);
+
+ // send the invocation
+ in = (InputStream) stub._invoke(out);
+
+ // read the result
+ Object result = readResult(method.getReturnType(),
in, context);
+ return result;
+ } catch (RemarshalException exception) {
+ continue;
+ } catch (ApplicationException exception) {
+ readException(method, (InputStream)
exception.getInputStream());
+ } catch (SystemException e) {
+ throw Util.mapSystemException(e);
+ } finally {
+ stub._releaseReply(in);
+ }
+ } else {
+ // get the servant
+ ServantObject servantObject =
stub._servant_preinvoke(operationName, type);
+ if (servantObject == null) {
+ continue;
}
- // copy the result
- result = Util.copyObject(result, stub._orb());
+ try {
+ // copy the arguments
+ Object[] argsCopy = Util.copyObjects(args,
stub._orb());
- return result;
- } catch (Throwable throwable) {
- // copy the exception
- Throwable throwableCopy = (Throwable)
Util.copyObject(throwable, stub._orb());
-
- // if it is one of my exception rethrow it
- Class[] exceptionTypes = method.getExceptionTypes();
- for (int i = 0; i < exceptionTypes.length; i++) {
- Class exceptionType = exceptionTypes[i];
- if (exceptionType.isInstance(throwableCopy)) {
- throw throwableCopy;
+ // invoke the servant
+ Object result = null;
+ try {
+ result = method.invoke(servantObject.servant,
argsCopy);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() != null) {
+ throw e.getCause();
+ }
+ throw e;
}
- }
- throw Util.wrapException(throwableCopy);
- } finally {
- stub._servant_postinvoke(servantObject);
+ // copy the result
+ result = Util.copyObject(result, stub._orb());
+
+ return result;
+ } catch (Throwable throwable) {
+ // copy the exception
+ Throwable throwableCopy = (Throwable)
Util.copyObject(throwable, stub._orb());
+
+ // if it is one of my exception rethrow it
+ Class[] exceptionTypes = method.getExceptionTypes();
+ for (int i = 0; i < exceptionTypes.length; i++) {
+ Class exceptionType = exceptionTypes[i];
+ if (exceptionType.isInstance(throwableCopy)) {
+ throw throwableCopy;
+ }
+ }
+
+ throw Util.wrapException(throwableCopy);
+ } finally {
+ stub._servant_postinvoke(servantObject);
+ }
}
}
+ } finally {
+ ClientContextManager.setClientContext(oldContext);
}
}
@@ -209,7 +233,7 @@
}
}
- private static Object readResult(Class type, InputStream in) {
+ private static Object readResult(Class type, InputStream in,
ClientContext context) {
if (type == void.class) {
return null;
} else if (type == boolean.class) {
@@ -231,7 +255,11 @@
} 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);
+ Object o = PortableRemoteObject.narrow(in.read_Object(), type);
+ if (o instanceof ClientContextHolder) {
+ ((ClientContextHolder)o).setClientContext(context);
+ }
+ return o;
} else if (org.omg.CORBA.Object.class.isAssignableFrom(type)) {
return in.read_Object();
} else {
1.3 +66 -64
openejb/modules/core/src/java/org/openejb/corba/util/ClientContextHolderStub.java