Author: andygumbrecht
Date: Tue Mar 12 16:11:18 2013
New Revision: 1455597
URL: http://svn.apache.org/r1455597
Log:
Fix org.apache.openejb.core.ivm.BaseEjbProxyHandler#convertException -
AccessException was never reached due to RemoteException order.
Finals and formatting.
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityContextHandler.java
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java?rev=1455597&r1=1455596&r2=1455597&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
Tue Mar 12 16:11:18 2013
@@ -16,62 +16,66 @@
*/
package org.apache.openejb.core.ivm;
-import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.COPY;
-import static
org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.CLASSLOADER_COPY;
-import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.NONE;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.BeanType;
+import org.apache.openejb.InterfaceType;
+import org.apache.openejb.RpcContainer;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.proxy.ProxyManager;
+import javax.ejb.AccessLocalException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBTransactionRequiredException;
+import javax.ejb.EJBTransactionRolledbackException;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.TransactionRequiredLocalException;
+import javax.ejb.TransactionRolledbackLocalException;
+import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
-import java.io.NotSerializableException;
import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.math.BigDecimal;
+import java.rmi.AccessException;
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
-import java.rmi.AccessException;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.List;
-import java.util.ArrayList;
-import java.util.WeakHashMap;
import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.locks.ReentrantLock;
-import javax.ejb.EJBException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.TransactionRequiredLocalException;
-import javax.ejb.TransactionRolledbackLocalException;
-import javax.ejb.EJBTransactionRequiredException;
-import javax.ejb.EJBTransactionRolledbackException;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.AccessLocalException;
-import javax.transaction.TransactionRequiredException;
-import javax.transaction.TransactionRolledbackException;
-
-import org.apache.openejb.BeanContext;
-import org.apache.openejb.BeanType;
-import org.apache.openejb.InterfaceType;
-import org.apache.openejb.RpcContainer;
-import org.apache.openejb.core.ThreadContext;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-import org.apache.openejb.spi.SecurityService;
-import java.lang.reflect.InvocationHandler;
-import org.apache.openejb.util.proxy.ProxyManager;
+import static
org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.CLASSLOADER_COPY;
+import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.COPY;
+import static org.apache.openejb.core.ivm.IntraVmCopyMonitor.State.NONE;
+@SuppressWarnings("unchecked")
public abstract class BaseEjbProxyHandler implements InvocationHandler,
Serializable {
+
private static final String OPENEJB_LOCALCOPY = "openejb.localcopy";
private IntraVmCopyMonitor.State strategy = NONE;
private static class ProxyRegistry {
- protected final Hashtable liveHandleRegistry = new Hashtable();
+ protected final HashMap liveHandleRegistry = new HashMap();
}
+ private final ReentrantLock lock = new ReentrantLock();
+
public final Object deploymentID;
public final Object primaryKey;
@@ -103,10 +107,10 @@ public abstract class BaseEjbProxyHandle
private boolean doCrossClassLoaderCopy;
private static final boolean REMOTE_COPY_ENABLED =
parseRemoteCopySetting();
protected final InterfaceType interfaceType;
- private transient WeakHashMap<Class,Object> interfaces;
+ private transient WeakHashMap<Class, Object> interfaces;
private transient WeakReference<Class> mainInterface;
- public BaseEjbProxyHandler(BeanContext beanContext, Object pk,
InterfaceType interfaceType, List<Class> interfaces, Class mainInterface) {
+ public BaseEjbProxyHandler(final BeanContext beanContext, final Object pk,
final InterfaceType interfaceType, List<Class> interfaces, Class mainInterface)
{
this.container = (RpcContainer) beanContext.getContainer();
this.deploymentID = beanContext.getDeploymentID();
this.interfaceType = interfaceType;
@@ -114,36 +118,40 @@ public abstract class BaseEjbProxyHandle
this.setBeanContext(beanContext);
if (interfaces == null || interfaces.size() == 0) {
- InterfaceType objectInterfaceType = (interfaceType.isHome()) ?
interfaceType.getCounterpart() : interfaceType;
+ final InterfaceType objectInterfaceType = (interfaceType.isHome())
? interfaceType.getCounterpart() : interfaceType;
interfaces = new
ArrayList<Class>(beanContext.getInterfaces(objectInterfaceType));
}
-
+
if (mainInterface == null && interfaces.size() == 1) {
mainInterface = interfaces.get(0);
}
-
+
setInterfaces(interfaces);
setMainInterface(mainInterface);
if (mainInterface == null) {
- throw new IllegalArgumentException("No mainInterface: otherwise
di: " + beanContext + " InterfaceType: " + interfaceType + " interfaces: " +
interfaces );
+ throw new IllegalArgumentException("No mainInterface: otherwise
di: " + beanContext + " InterfaceType: " + interfaceType + " interfaces: " +
interfaces);
}
this.setDoIntraVmCopy(REMOTE_COPY_ENABLED && !interfaceType.isLocal()
&& !interfaceType.isLocalBean());
}
- protected void setDoIntraVmCopy(boolean doIntraVmCopy) {
+ protected void setDoIntraVmCopy(final boolean doIntraVmCopy) {
this.doIntraVmCopy = doIntraVmCopy;
setStrategy();
}
- protected void setDoCrossClassLoaderCopy(boolean doCrossClassLoaderCopy) {
+ protected void setDoCrossClassLoaderCopy(final boolean
doCrossClassLoaderCopy) {
this.doCrossClassLoaderCopy = doCrossClassLoaderCopy;
setStrategy();
}
private void setStrategy() {
- if (!doIntraVmCopy) strategy = NONE;
- else if (doCrossClassLoaderCopy) strategy = CLASSLOADER_COPY;
- else strategy = COPY;
+ if (!doIntraVmCopy) {
+ strategy = NONE;
+ } else if (doCrossClassLoaderCopy) {
+ strategy = CLASSLOADER_COPY;
+ } else {
+ strategy = COPY;
+ }
}
/**
@@ -151,30 +159,35 @@ public abstract class BaseEjbProxyHandle
* business interface class to name as the invoking interface.
* This method should NOT be called on non-business-interface
* methods the proxy has such as java.lang.Object or IntraVmProxy.
- * @param method
+ *
+ * @param method Method
* @return the business (or component) interface matching this method
*/
- protected Class<?> getInvokedInterface(Method method) {
+ protected Class<?> getInvokedInterface(final Method method) {
// Home's only have one interface ever. We don't
// need to verify that the method invoked is in
// it's interface.
- Class mainInterface = getMainInterface();
- if (interfaceType.isHome()) return mainInterface;
- if (interfaceType.isLocalBean()) return mainInterface;
+ final Class mainInterface = getMainInterface();
+ if (interfaceType.isHome()) {
+ return mainInterface;
+ }
+ if (interfaceType.isLocalBean()) {
+ return mainInterface;
+ }
- Class declaringClass = method.getDeclaringClass();
+ final Class declaringClass = method.getDeclaringClass();
// If our "main" interface is or extends the method's declaring class
// then we're good. We know the main interface has the method being
// invoked and it's safe to return it as the invoked interface.
- if (mainInterface != null &&
declaringClass.isAssignableFrom(mainInterface)){
+ if (mainInterface != null &&
declaringClass.isAssignableFrom(mainInterface)) {
return mainInterface;
}
// If the method being invoked isn't in the "main" interface
// we need to find a suitable interface or throw an exception.
- for (Class secondaryInterface : interfaces.keySet()) {
- if (declaringClass.isAssignableFrom(secondaryInterface)){
+ for (final Class secondaryInterface : interfaces.keySet()) {
+ if (declaringClass.isAssignableFrom(secondaryInterface)) {
return secondaryInterface;
}
}
@@ -188,19 +201,19 @@ public abstract class BaseEjbProxyHandle
return mainInterface.get();
}
- private void setMainInterface(Class referent) {
+ private void setMainInterface(final Class referent) {
mainInterface = new WeakReference<Class>(referent);
}
- private void setInterfaces(List<Class> interfaces) {
- this.interfaces = new WeakHashMap<Class,Object>(interfaces.size());
- for (Class clazz : interfaces) {
+ private void setInterfaces(final List<Class> interfaces) {
+ this.interfaces = new WeakHashMap<Class, Object>(interfaces.size());
+ for (final Class clazz : interfaces) {
this.interfaces.put(clazz, null);
}
}
public List<Class> getInterfaces() {
- Set<Class> classes = interfaces.keySet();
+ final Set<Class> classes = interfaces.keySet();
return new ArrayList(classes);
}
@@ -208,48 +221,58 @@ public abstract class BaseEjbProxyHandle
return SystemInstance.get().getOptions().get(OPENEJB_LOCALCOPY, true);
}
- protected void checkAuthorization(Method method) throws
org.apache.openejb.OpenEJBException {
+ protected void checkAuthorization(final Method method) throws
org.apache.openejb.OpenEJBException {
}
- public void setIntraVmCopyMode(boolean on) {
+ public void setIntraVmCopyMode(final boolean on) {
setDoIntraVmCopy(on);
}
- public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
+ @Override
+ public Object invoke(final Object proxy, Method method, Object[] args)
throws Throwable {
isValidReference(method);
- if (args == null) args = new Object[]{};
-
+ if (args == null) {
+ args = new Object[]{};
+ }
+
if (method.getDeclaringClass() == Object.class) {
final String methodName = method.getName();
- if (methodName.equals("toString")) return toString();
- else if (methodName.equals("equals")) return equals(args[0]) ?
Boolean.TRUE : Boolean.FALSE;
- else if (methodName.equals("hashCode")) return new
Integer(hashCode());
- else throw new UnsupportedOperationException("Unknown method: " +
method);
+ if (methodName.equals("toString")) {
+ return toString();
+ } else if (methodName.equals("equals")) {
+ return equals(args[0]) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (methodName.equals("hashCode")) {
+ return hashCode();
+ } else {
+ throw new UnsupportedOperationException("Unknown method: " +
method);
+ }
} else if (method.getDeclaringClass() == IntraVmProxy.class) {
final String methodName = method.getName();
- if (methodName.equals("writeReplace")) return _writeReplace(proxy);
- else throw new UnsupportedOperationException("Unknown method: " +
method);
+ if (methodName.equals("writeReplace")) {
+ return _writeReplace(proxy);
+ } else {
+ throw new UnsupportedOperationException("Unknown method: " +
method);
+ }
} else if (method.getDeclaringClass() == BeanContext.Removable.class) {
return _invoke(proxy, BeanContext.Removable.class, method, args);
}
Class interfce = getInvokedInterface(method);
-
- ThreadContext callContext = ThreadContext.getThreadContext();
- Object localClientIdentity = ClientSecurity.getIdentity();
+ final ThreadContext callContext = ThreadContext.getThreadContext();
+ final Object localClientIdentity = ClientSecurity.getIdentity();
try {
if (callContext == null && localClientIdentity != null) {
- SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
+ final SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
securityService.associate(localClientIdentity);
}
if (strategy == CLASSLOADER_COPY) {
IntraVmCopyMonitor.pre(strategy);
- ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
+ final ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getBeanContext().getClassLoader());
try {
args = copyArgs(args);
@@ -269,14 +292,14 @@ public abstract class BaseEjbProxyHandle
IntraVmCopyMonitor.post();
}
}
- IntraVmCopyMonitor.State oldStrategy = strategy;
- if (getBeanContext().isAsynchronous(method) ||
getBeanContext().getComponentType().equals(BeanType.MANAGED)){
+ final IntraVmCopyMonitor.State oldStrategy = strategy;
+ if (getBeanContext().isAsynchronous(method) ||
getBeanContext().getComponentType().equals(BeanType.MANAGED)) {
strategy = IntraVmCopyMonitor.State.NONE;
}
-
+
try {
- Object returnValue = _invoke(proxy, interfce, method, args);
+ final Object returnValue = _invoke(proxy, interfce, method,
args);
return copy(strategy, returnValue);
} catch (Throwable throwable) {
throwable = copy(strategy, throwable);
@@ -285,28 +308,30 @@ public abstract class BaseEjbProxyHandle
strategy = oldStrategy;
}
} finally {
-
+
if (callContext == null && localClientIdentity != null) {
- SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
+ final SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
securityService.disassociate();
}
}
}
- private <T> T copy(IntraVmCopyMonitor.State strategy, T object) throws
IOException, ClassNotFoundException {
- if (object == null || !strategy.isCopy()) return object;
+ private <T> T copy(final IntraVmCopyMonitor.State strategy, final T
object) throws IOException, ClassNotFoundException {
+ if (object == null || !strategy.isCopy()) {
+ return object;
+ }
IntraVmCopyMonitor.pre(strategy);
try {
- return (T) copyObj(object);
+ return copyObj(object);
} finally {
IntraVmCopyMonitor.post();
}
}
- private void isValidReference(Method method) throws NoSuchObjectException {
+ private void isValidReference(final Method method) throws
NoSuchObjectException {
if (isInvalidReference) {
- if (interfaceType.isComponent() && interfaceType.isLocal()){
+ if (interfaceType.isComponent() && interfaceType.isLocal()) {
throw new NoSuchObjectLocalException("reference is invalid");
} else if (interfaceType.isComponent() ||
java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())) {
throw new NoSuchObjectException("reference is invalid");
@@ -315,9 +340,9 @@ public abstract class BaseEjbProxyHandle
}
}
if (!(Object.class.equals(method.getDeclaringClass())
- && method.getName().equals("finalize")
- && method.getExceptionTypes().length == 1
- && Throwable.class.equals(method.getExceptionTypes()[0]))) {
+ && method.getName().equals("finalize")
+ && method.getExceptionTypes().length == 1
+ && Throwable.class.equals(method.getExceptionTypes()[0]))) {
getBeanContext(); // will throw an exception if app has been
undeployed.
}
}
@@ -325,12 +350,13 @@ public abstract class BaseEjbProxyHandle
/**
* Renamed method so it shows up with a much more understandable purpose
as it
* will be the top element in the stacktrace
- * @param e
- * @param method
- * @param interfce
+ *
+ * @param e Throwable
+ * @param method Method
+ * @param interfce Class
*/
- protected Throwable convertException(Throwable e, Method method, Class
interfce) {
- boolean rmiRemote = java.rmi.Remote.class.isAssignableFrom(interfce);
+ protected Throwable convertException(Throwable e, final Method method,
final Class interfce) {
+ final boolean rmiRemote =
java.rmi.Remote.class.isAssignableFrom(interfce);
if (e instanceof TransactionRequiredException) {
if (!rmiRemote && interfaceType.isBusiness()) {
return new
EJBTransactionRequiredException(e.getMessage()).initCause(getCause(e));
@@ -358,26 +384,26 @@ public abstract class BaseEjbProxyHandle
return e;
}
}
- if (e instanceof RemoteException) {
+ if (e instanceof AccessException) {
if (!rmiRemote && interfaceType.isBusiness()) {
- return new EJBException(e.getMessage()).initCause(getCause(e));
+ return new
AccessLocalException(e.getMessage()).initCause(getCause(e));
} else if (interfaceType.isLocal()) {
- return new EJBException(e.getMessage()).initCause(getCause(e));
+ return new
AccessLocalException(e.getMessage()).initCause(getCause(e));
} else {
return e;
}
}
- if (e instanceof AccessException) {
+ if (e instanceof RemoteException) {
if (!rmiRemote && interfaceType.isBusiness()) {
- return new
AccessLocalException(e.getMessage()).initCause(getCause(e));
+ return new EJBException(e.getMessage()).initCause(getCause(e));
} else if (interfaceType.isLocal()) {
- return new
AccessLocalException(e.getMessage()).initCause(getCause(e));
+ return new EJBException(e.getMessage()).initCause(getCause(e));
} else {
return e;
}
}
- for (Class<?> type : method.getExceptionTypes()) {
+ for (final Class<?> type : method.getExceptionTypes()) {
if (type.isAssignableFrom(e.getClass())) {
return e;
}
@@ -396,26 +422,25 @@ public abstract class BaseEjbProxyHandle
* the bean's classloader need to be swapped out for the identical
* method in the bean's classloader.
*
- * @param method
+ * @param method Method
* @return return's the same method but loaded from the beans classloader
*/
- private Method copyMethod(Method method) throws Exception {
- int parameterCount = method.getParameterTypes().length;
- Object[] types = new Object[1 + parameterCount];
+ private Method copyMethod(final Method method) throws Exception {
+ final int parameterCount = method.getParameterTypes().length;
+ Class[] types = new Class[1 + parameterCount];
types[0] = method.getDeclaringClass();
System.arraycopy(method.getParameterTypes(), 0, types, 1,
parameterCount);
- types = copyArgs(types);
+ types = (Class[]) copyArgs(types);
- Class targetClass = (Class) types[0];
- Class[] targetParameters = new Class[parameterCount];
+ final Class targetClass = types[0];
+ final Class[] targetParameters = new Class[parameterCount];
System.arraycopy(types, 1, targetParameters, 0, parameterCount);
- Method targetMethod = targetClass.getMethod(method.getName(),
targetParameters);
- return targetMethod;
+ return targetClass.getMethod(method.getName(), targetParameters);
}
- protected Throwable getCause(Throwable e) {
+ protected Throwable getCause(final Throwable e) {
if (e != null && e.getCause() != null) {
return e.getCause();
}
@@ -427,6 +452,7 @@ public abstract class BaseEjbProxyHandle
try {
name = getProxyInfo().getInterface().getName();
} catch (Exception e) {
+ //Ignore
}
return "proxy=" + name + ";deployment=" + this.deploymentID + ";pk=" +
this.primaryKey;
}
@@ -445,27 +471,29 @@ public abstract class BaseEjbProxyHandle
return false;
}
try {
- obj = ProxyManager.getInvocationHandler(obj);
+ obj = (ProxyManager.getInvocationHandler(obj));
} catch (IllegalArgumentException e) {
return false;
}
if (this == obj) {
return true;
}
- BaseEjbProxyHandler other = (BaseEjbProxyHandler) obj;
+ final BaseEjbProxyHandler other = (BaseEjbProxyHandler) obj;
return equalHandler(other);
}
- protected boolean equalHandler(BaseEjbProxyHandler other) {
- return (primaryKey == null? other.primaryKey == null:
primaryKey.equals(other.primaryKey))
- && deploymentID.equals(other.deploymentID)
- && getMainInterface().equals(other.getMainInterface());
+ protected boolean equalHandler(final BaseEjbProxyHandler other) {
+ return (primaryKey == null ? other.primaryKey == null :
primaryKey.equals(other.primaryKey))
+ && deploymentID.equals(other.deploymentID)
+ && getMainInterface().equals(other.getMainInterface());
}
protected abstract Object _invoke(Object proxy, Class interfce, Method
method, Object[] args) throws Throwable;
- protected Object[] copyArgs(Object[] objects) throws IOException,
ClassNotFoundException {
- if (objects == null) return objects;
+ protected Object[] copyArgs(final Object[] objects) throws IOException,
ClassNotFoundException {
+ if (objects == null) {
+ return objects;
+ }
/*
while copying the arguments is necessary. Its not necessary to
copy the array itself,
because they array is created by the Proxy implementation for the
sole purpose of
@@ -481,45 +509,47 @@ public abstract class BaseEjbProxyHandle
}
/* change dereference to copy */
- protected <T> T copyObj(T object) throws IOException,
ClassNotFoundException {
- // Check for primitive and other known class types that are immutable.
If detected
- // we can safely return them.
- if (object == null) return null;
- Class ooc = object.getClass();
- if ((ooc == int.class ) ||
- (ooc == String.class ) ||
- (ooc == long.class ) ||
- (ooc == boolean.class ) ||
- (ooc == byte.class ) ||
- (ooc == float.class ) ||
- (ooc == double.class ) ||
- (ooc == short.class ) ||
- (ooc == Long.class ) ||
- (ooc == Boolean.class ) ||
- (ooc == Byte.class ) ||
- (ooc == Character.class ) ||
- (ooc == Float.class ) ||
- (ooc == Double.class ) ||
- (ooc == Short.class ) ||
- (ooc == BigDecimal.class ))
- {
+ protected <T> T copyObj(final T object) throws IOException,
ClassNotFoundException {
+ // Check for primitive and other known class types that are immutable.
If detected
+ // we can safely return them.
+ if (object == null) {
+ return null;
+ }
+ final Class ooc = object.getClass();
+ if ((ooc == int.class) ||
+ (ooc == String.class) ||
+ (ooc == long.class) ||
+ (ooc == boolean.class) ||
+ (ooc == byte.class) ||
+ (ooc == float.class) ||
+ (ooc == double.class) ||
+ (ooc == short.class) ||
+ (ooc == Long.class) ||
+ (ooc == Boolean.class) ||
+ (ooc == Byte.class) ||
+ (ooc == Character.class) ||
+ (ooc == Float.class) ||
+ (ooc == Double.class) ||
+ (ooc == Short.class) ||
+ (ooc == BigDecimal.class)) {
return object;
}
-
- ByteArrayOutputStream baos = null;
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
try {
- baos = new ByteArrayOutputStream(128);
- ObjectOutputStream out = new ObjectOutputStream(baos);
+ final ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(object);
out.close();
} catch (NotSerializableException e) {
- throw (IOException) new NotSerializableException(e.getMessage()+"
: The EJB specification restricts remote interfaces to only serializable data
types. This can be disabled for in-vm use with the "+OPENEJB_LOCALCOPY+"=false
system property.").initCause(e);
+ throw (IOException) new NotSerializableException(e.getMessage() +
+ " : The EJB
specification restricts remote interfaces to only serializable data types.
This can be disabled for in-vm use with the " +
+ OPENEJB_LOCALCOPY
+
+ "=false system
property.").initCause(e);
}
- ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream in = new EjbObjectInputStream(bais);
- Object obj = in.readObject();
+ final ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
+ final ObjectInputStream in = new EjbObjectInputStream(bais);
+ final Object obj = in.readObject();
return (T) obj;
}
@@ -529,23 +559,36 @@ public abstract class BaseEjbProxyHandle
this.isInvalidReference = true;
}
- protected void invalidateAllHandlers(Object key) {
- HashSet<BaseEjbProxyHandler> set = (HashSet)
getLiveHandleRegistry().remove(key);
- if (set == null) return;
- synchronized (set) {
- for (BaseEjbProxyHandler handler : set) {
+ protected void invalidateAllHandlers(final Object key) {
+ final HashSet<BaseEjbProxyHandler> set = (HashSet)
getLiveHandleRegistry().remove(key);
+ if (set == null) {
+ return;
+ }
+
+ final ReentrantLock l = lock;
+ l.lock();
+
+ try {
+ for (final BaseEjbProxyHandler handler : set) {
handler.invalidateReference();
}
+ } finally {
+ l.unlock();
}
}
protected abstract Object _writeReplace(Object proxy) throws
ObjectStreamException;
- protected void registerHandler(Object key, BaseEjbProxyHandler handler) {
+ protected void registerHandler(final Object key, final BaseEjbProxyHandler
handler) {
HashSet set = (HashSet) getLiveHandleRegistry().get(key);
if (set != null) {
- synchronized (set) {
+ final ReentrantLock l = lock;
+ l.lock();
+
+ try {
set.add(handler);
+ } finally {
+ l.unlock();
}
} else {
set = new HashSet();
@@ -557,40 +600,40 @@ public abstract class BaseEjbProxyHandle
public abstract org.apache.openejb.ProxyInfo getProxyInfo();
public BeanContext getBeanContext() {
- BeanContext beanContext = beanContextRef.get();
- if (beanContext == null|| beanContext.isDestroyed()){
+ final BeanContext beanContext = beanContextRef.get();
+ if (beanContext == null || beanContext.isDestroyed()) {
invalidateReference();
- throw new IllegalStateException("Bean '"+deploymentID+"' has been
undeployed.");
+ throw new IllegalStateException("Bean '" + deploymentID + "' has
been undeployed.");
}
return beanContext;
}
- public void setBeanContext(BeanContext beanContext) {
+ public void setBeanContext(final BeanContext beanContext) {
this.beanContextRef = new WeakReference<BeanContext>(beanContext);
}
- public Hashtable getLiveHandleRegistry() {
- BeanContext beanContext = getBeanContext();
+ public HashMap getLiveHandleRegistry() {
+ final BeanContext beanContext = getBeanContext();
ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
- if (proxyRegistry == null){
+ if (proxyRegistry == null) {
proxyRegistry = new ProxyRegistry();
beanContext.set(ProxyRegistry.class, proxyRegistry);
}
return proxyRegistry.liveHandleRegistry;
}
- private void writeObject(java.io.ObjectOutputStream out) throws
IOException {
+ private void writeObject(final java.io.ObjectOutputStream out) throws
IOException {
out.defaultWriteObject();
out.writeObject(getInterfaces());
out.writeObject(getMainInterface());
}
- private void readObject(java.io.ObjectInputStream in) throws
java.io.IOException, ClassNotFoundException {
+ private void readObject(final java.io.ObjectInputStream in) throws
java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
- ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
+ final ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
setBeanContext(containerSystem.getBeanContext(deploymentID));
container = (RpcContainer) getBeanContext().getContainer();
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityContextHandler.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityContextHandler.java?rev=1455597&r1=1455596&r2=1455597&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityContextHandler.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityContextHandler.java
Tue Mar 12 16:11:18 2013
@@ -16,55 +16,57 @@
*/
package org.apache.openejb.core.security;
+import org.apache.geronimo.connector.work.WorkContextHandler;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.SecurityService;
+
import javax.resource.spi.work.SecurityContext;
import javax.resource.spi.work.WorkCompletedException;
import javax.resource.spi.work.WorkContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
-import org.apache.geronimo.connector.work.WorkContextHandler;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.SecurityService;
-
-public class SecurityContextHandler implements
WorkContextHandler<SecurityContext>{
+public class SecurityContextHandler implements
WorkContextHandler<SecurityContext> {
private ConnectorCallbackHandler callbackHandler;
- private final String securityRealmName;
+ private final String securityRealmName;
- public SecurityContextHandler(final String securityRealmName) {
- this.securityRealmName = securityRealmName;
- }
+ public SecurityContextHandler(final String securityRealmName) {
+ this.securityRealmName = securityRealmName;
+ }
- @Override
+ @Override
public void before(final SecurityContext securityContext) throws
WorkCompletedException {
if (securityContext != null) {
callbackHandler = new ConnectorCallbackHandler(securityRealmName);
-
+
final Subject clientSubject = new Subject();
- securityContext.setupSecurityContext(callbackHandler,
clientSubject, null);
+ securityContext.setupSecurityContext(callbackHandler,
clientSubject, null);
}
}
+ @SuppressWarnings("unchecked")
@Override
public void after(final SecurityContext securityContext) throws
WorkCompletedException {
- final SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
- final Object loginObj = securityService.disassociate();
- if (loginObj != null) {
- try {
- securityService.logout(loginObj);
- } catch (LoginException e) {
- }
- }
+ final SecurityService securityService =
SystemInstance.get().getComponent(SecurityService.class);
+ final Object loginObj = securityService.disassociate();
+ if (loginObj != null) {
+ try {
+ securityService.logout(loginObj);
+ } catch (LoginException e) {
+ //Ignore
+ }
+ }
}
- @Override
+ @Override
public boolean supports(final Class<? extends WorkContext> clazz) {
- return SecurityContext.class.isAssignableFrom(clazz);
- }
+ return SecurityContext.class.isAssignableFrom(clazz);
+ }
- @Override
+ @Override
public boolean required() {
- return false;
- }
+ return false;
+ }
}