[Jboss-cvs] JBossAS SVN: r55119 - in trunk: ejb3/src/main/org/jboss/ejb3 ejb3/src/main/org/jboss/ejb3/iiop ejb3/src/main/org/jboss/ejb3/mdb ejb3/src/main/org/jboss/ejb3/service ejb3/src/main/org/jboss/ejb3/stateful ejb3/src/main/org/jboss/ejb3/stateless ejb3/src/test/org/jboss/ejb3/test/iiop ejb3/src/test/org/jboss/ejb3/test/iiop/unit iiop/src/main/org/jboss/iiop/csiv2
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 3 13:48:23 EDT 2006
Author: wolfc
Date: 2006-08-03 13:47:51 -0400 (Thu, 03 Aug 2006)
New Revision: 55119
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySession.java
trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySessionBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MyStatefulBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/unit/IiopRemoteUnitTestCase.java
trunk/iiop/src/main/org/jboss/iiop/csiv2/CSIv2Util.java
Log:
EJBTHREE-667: passing basic unit tests after refactoring invocation of EJB beans
Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -33,6 +33,8 @@
public Object createProxy();
+ public Object createProxy(Object id);
+
public void start() throws Exception;
public void stop() throws Exception;
Modified: trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -25,17 +25,21 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
+
+import javax.ejb.Handle;
import javax.ejb.LocalHome;
import javax.ejb.RemoteHome;
-import javax.naming.NamingException;
-
import org.jboss.aop.AspectManager;
import org.jboss.aop.Dispatcher;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.InvocationResponse;
import org.jboss.aop.util.MethodHashing;
+import org.jboss.aspects.asynch.FutureHolder;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
import org.jboss.ejb3.remoting.IsLocalInterceptor;
+import org.jboss.ejb3.stateful.StatefulContainerInvocation;
import org.jboss.logging.Logger;
import org.jboss.serial.io.MarshalledObjectForLocalCalls;
@@ -47,6 +51,7 @@
*/
public abstract class SessionContainer extends EJBContainer
{
+ @SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(SessionContainer.class);
protected ProxyDeployer proxyDeployer;
@@ -247,4 +252,133 @@
response.setContextInfo(responseContext);
return response;
}
+
+ /**
+ * Invoke a method on the virtual EJB bean. The method must be one of the methods defined in one
+ * of the business interfaces (or home interface) of the bean.
+ *
+ * TODO: work in progress
+ *
+ * @param factory the originating end point
+ * @param id unique identifier (primary key), can be null for stateless
+ * @param method the business or home method to invoke
+ * @param args the arguments for the method
+ * @param provider for asynchronous usage
+ */
+ public Object invoke(ProxyFactory factory, Object id, Method method, Object args[], FutureHolder provider) throws Throwable
+ {
+ ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ ThreadLocalENCFactory.push(enc);
+ try
+ {
+ long hash = MethodHashing.calculateHash(method);
+ MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
+ if (info == null)
+ {
+ throw new RuntimeException(
+ "Could not resolve beanClass method from proxy call: "
+ + method.toString());
+ }
+
+ Method unadvisedMethod = info.getUnadvisedMethod();
+
+ if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+ {
+ return invokeHomeMethod(factory, info, args);
+ }
+ else if (unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
+ {
+ return invokeEJBObjectMethod(id, info, args);
+ }
+
+ Interceptor[] aspects = info.getInterceptors();
+ // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
+ StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, aspects, id);
+ nextInvocation.setAdvisor(this);
+ nextInvocation.setArguments(args);
+
+ ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+ try
+ {
+ invokedMethod.push(new InvokedMethod(true, method));
+ return nextInvocation.invokeNext();
+ }
+ finally
+ {
+ invokedMethod.pop();
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldLoader);
+ ThreadLocalENCFactory.pop();
+ }
+ }
+
+ /**
+ * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
+ */
+ private Object invokeHomeMethod(ProxyFactory factory, MethodInfo info, Object args[]) throws Exception
+ {
+ Method unadvisedMethod = info.getUnadvisedMethod();
+ if (unadvisedMethod.getName().equals("create"))
+ {
+ Class[] initParameterTypes = {};
+ Object[] initParameterValues = {};
+ if (unadvisedMethod.getParameterTypes().length > 0)
+ {
+ initParameterTypes = unadvisedMethod.getParameterTypes();
+ initParameterValues = args;
+ }
+
+ Object id = createSession(initParameterTypes, initParameterValues);
+
+ Object proxy = factory.createProxy(id);
+
+ return proxy;
+ }
+ else if (unadvisedMethod.getName().equals("remove"))
+ {
+ removeHandle((Handle) args[0]);
+
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("illegal home method " + unadvisedMethod);
+ }
+ }
+
+ /**
+ * Create session to an EJB bean.
+ *
+ * @param initParameterTypes the parameter types used by the home's create method
+ * @param initParameterValues the arguments for the home's create method
+ * @return the identifier of the session
+ */
+ abstract protected Object createSession(Class initParameterTypes[], Object initParameterValues[]);
+
+ /**
+ * Destroy a created session.
+ *
+ * @param id the identifier of the session
+ */
+ protected void destroySession(Object id)
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ protected Object invokeEJBObjectMethod(Object id, MethodInfo info, Object args[]) throws Exception
+ {
+ Method unadvisedMethod = info.getUnadvisedMethod();
+ if (unadvisedMethod.getName().equals("remove"))
+ {
+ destroySession(id);
+
+ return null;
+ }
+ throw new RuntimeException("NYI");
+ }
+
+ abstract protected void removeHandle(Handle handle);
}
\ No newline at end of file
Modified: trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -22,14 +22,18 @@
package org.jboss.ejb3.iiop;
import java.lang.reflect.Method;
+import java.security.Principal;
import java.util.HashMap;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import org.jboss.ejb3.Container;
+import org.jboss.ejb3.SessionContainer;
import org.jboss.ejb3.stateful.StatefulContainer;
import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.iiop.CorbaORB;
+import org.jboss.iiop.csiv2.SASCurrent;
import org.jboss.iiop.rmi.AttributeAnalysis;
import org.jboss.iiop.rmi.InterfaceAnalysis;
import org.jboss.iiop.rmi.OperationAnalysis;
@@ -37,11 +41,14 @@
import org.jboss.iiop.rmi.marshal.strategy.SkeletonStrategy;
import org.jboss.invocation.iiop.ReferenceData;
import org.jboss.logging.Logger;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
import org.jboss.tm.TransactionManagerLocator;
import org.jboss.tm.iiop.TxServerInterceptor;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.InterfaceDef;
import org.omg.CORBA.SystemException;
+import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.OutputStream;
@@ -60,34 +67,52 @@
implements InvokeHandler
{
private static final Logger log = Logger.getLogger(BeanCorbaServant.class);
-
+
+ private final IORFactory factory;
private final Current poaCurrent;
private final Container container;
private final InterfaceDef interfaceDef;
private final String repositoryIds[];
+ private SASCurrent sasCurrent;
private HashMap<String, SkeletonStrategy> methodMap;
- protected BeanCorbaServant(Current poaCurrent, Container container, InterfaceDef interfaceDef, InterfaceAnalysis interfaceAnalysis)
+ protected BeanCorbaServant(IORFactory factory, Current poaCurrent, Container container, InterfaceDef interfaceDef, InterfaceAnalysis interfaceAnalysis)
{
+ assert factory != null;
+ assert poaCurrent != null;
+ assert container != null;
+ assert container instanceof SessionContainer; // see invoke
+ assert interfaceDef != null;
+ assert interfaceAnalysis != null;
+
+ this.factory = factory;
this.poaCurrent = poaCurrent;
this.container = container;
this.interfaceDef = interfaceDef;
this.repositoryIds = interfaceAnalysis.getAllTypeIds();
+ try
+ {
+ this.sasCurrent = (SASCurrent) CorbaORB.getInstance().resolve_initial_references("SASCurrent");
+ }
+ catch (InvalidName e)
+ {
+ log.warn("Can't find SASCurrent");
+ this.sasCurrent = null;
+ }
+
this.methodMap = new HashMap<String, SkeletonStrategy>();
AttributeAnalysis[] attrs = interfaceAnalysis.getAttributes();
for (int i = 0; i < attrs.length; i++) {
OperationAnalysis op = attrs[i].getAccessorAnalysis();
- log.debug(" " + op.getJavaName()
- + "\n " + op.getIDLName());
+ log.debug(" " + op.getJavaName() + ": " + op.getIDLName());
methodMap.put(op.getIDLName(),
new SkeletonStrategy(op.getMethod()));
op = attrs[i].getMutatorAnalysis();
if (op != null) {
- log.debug(" " + op.getJavaName()
- + "\n " + op.getIDLName());
+ log.debug(" " + op.getJavaName() + ": " + op.getIDLName());
methodMap.put(op.getIDLName(),
new SkeletonStrategy(op.getMethod()));
}
@@ -95,12 +120,10 @@
OperationAnalysis[] ops = interfaceAnalysis.getOperations();
for (int i = 0; i < ops.length; i++) {
- log.debug(" " + ops[i].getJavaName()
- + "\n " + ops[i].getIDLName());
+ log.debug(" " + ops[i].getJavaName() + ": " + ops[i].getIDLName());
methodMap.put(ops[i].getIDLName(),
new SkeletonStrategy(ops[i].getMethod()));
}
-
}
@Override
@@ -123,7 +146,7 @@
public OutputStream _invoke(String opName, InputStream in, ResponseHandler handler) throws SystemException
{
- log.info("invoke: " + opName);
+ log.trace("invoke: " + opName);
SkeletonStrategy op = (SkeletonStrategy) methodMap.get(opName);
if (op == null)
@@ -136,11 +159,37 @@
try
{
Object id = ReferenceData.extractObjectId(poaCurrent.get_object_id());
- log.info("id = " + id);
+ log.trace("id = " + id);
Transaction tx = TxServerInterceptor.getCurrentTransaction();
- log.info("tx = " + tx);
+ log.trace("tx = " + tx);
+ if(sasCurrent != null)
+ {
+ byte username[] = sasCurrent.get_incoming_username();
+ byte credentials[] = sasCurrent.get_incoming_password();
+ byte principalName[] = sasCurrent.get_incoming_principal_name();
+
+ if(username != null && username.length > 0)
+ {
+ String name = new String(username, "UTF-8");
+ int domainIndex = name.lastIndexOf("@");
+ if(domainIndex > 0)
+ name = name.substring(0, domainIndex);
+ log.info("username = " + name);
+ Principal principal = new SimplePrincipal(name);
+ SecurityAssociation.setPrincipal(principal);
+ }
+
+ if(credentials != null && credentials.length > 0)
+ {
+ SecurityAssociation.setCredential(new String(credentials, "UTF-8").toCharArray());
+ }
+
+ if(principalName != null)
+ log.warn("principalName = " + new String(principalName, "UTF-8")); // FIXME: implement principalName support
+ }
+
Object args[] = op.readParams((org.omg.CORBA_2_3.portable.InputStream) in);
Object retVal = invoke(tx, id, op.getMethod(), args);
@@ -163,7 +212,7 @@
else
throw new RuntimeException("NYI");
}
- return null;
+ return out;
}
private TransactionManager getTransactionManager()
@@ -174,11 +223,13 @@
private Object invoke(Object id, Method method, Object args[]) throws Throwable
{
- // FIXME: Not hard coded on stateless container
- if(container instanceof StatelessContainer)
- return ((StatelessContainer) container).localInvoke(method, args);
- else
- return ((StatefulContainer) container).localInvoke(id, method, args);
+ // TODO: Support other containers beside Stateless and Stateful?
+// if(container instanceof StatelessContainer)
+// return ((StatelessContainer) container).localInvoke(method, args); // FIXME: it's a hack to call localInvoke here
+// else
+// return ((StatefulContainer) container).invoke(factory, id, method, args, null);
+
+ return ((SessionContainer) container).invoke(factory, id, method, args, null);
}
private Object invoke(Transaction tx, Object id, Method method, Object args[]) throws Throwable
@@ -196,9 +247,6 @@
tm.resume(tx);
try
{
- log.info("currentThread = " + Thread.currentThread());
- log.info("currentTransaction = " + tm.getTransaction());
- log.info("tm = " + tm);
return invoke(id, method, args);
}
finally
Modified: trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -143,7 +143,7 @@
}
}
- public EJBObject createProxy()
+ public Object createProxy()
{
try
{
@@ -159,6 +159,22 @@
}
}
+ public Object createProxy(Object id)
+ {
+ try
+ {
+ org.omg.CORBA.Object corbaRef = referenceFactory.createReferenceWithId(id, beanRepositoryIds[0]);
+
+ EJBObject corbaObj = (EJBObject) PortableRemoteObject.narrow(corbaRef, EJBObject.class);
+
+ return corbaObj;
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
private IIOP getIIOP()
{
IIOP iiop = (IIOP) advisor.resolveAnnotation(IIOP.class);
@@ -242,9 +258,12 @@
Class homeInterface = ProxyFactoryHelper.getRemoteHomeInterface(container);
if(homeInterface != null)
{
+ if(!EJBHome.class.isAssignableFrom(homeInterface))
+ throw new IllegalArgumentException("home interface " + homeInterface.getName() + " must extend javax.ejb.EJBHome (EJB3 4.6.8)");
homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeInterface);
this.homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
}
+ // To allow EJB3 Stateless beans to operate we can function without a home interface.
// Get orb and irPoa references
try {
@@ -303,21 +322,22 @@
// setup a codebase policy, the CodebaseInterceptor will translate this to a TAG_JAVA_CODEBASE
String codebaseString = wcl.getCodebaseString();
- log.info("codebase = " + codebaseString);
+ log.debug("codebase = " + codebaseString);
Any codebase = orb.create_any();
codebase.insert_string(codebaseString);
Policy codebasePolicy;
codebasePolicy = orb.create_policy(CodebasePolicy.TYPE, codebase);
-// // Create csiv2Policy for both home and remote containing
-// // IorSecurityConfigMetadata
-// Any secPolicy = orb.create_any();
+ // Create csiv2Policy for both home and remote containing
+ // IorSecurityConfigMetadata
+ Any secPolicy = orb.create_any();
// IorSecurityConfigMetaData iorSecurityConfigMetaData =
// container.getBeanMetaData().getIorSecurityConfigMetaData();
-// secPolicy.insert_Value(iorSecurityConfigMetaData);
-// Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
+ IorSecurityConfigMetaData iorSecurityConfigMetaData = new IorSecurityConfigMetaData(); // TODO: make ior security configurable
+ secPolicy.insert_Value(iorSecurityConfigMetaData);
+ Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
- Policy policies[] = { codebasePolicy };
+ Policy policies[] = { codebasePolicy, csiv2Policy };
InterfaceDef interfaceDef = null;
if(iri != null)
@@ -330,17 +350,19 @@
NamingContextExt ctx = getNamingContextExt();
- Servant servant = new BeanCorbaServant(poaCurrent, container, interfaceDef, interfaceAnalysis);
+ log.debug("binding servant name " + getServantName());
+
+ Servant servant = new BeanCorbaServant(this, poaCurrent, container, interfaceDef, interfaceAnalysis);
this.referenceFactory = servantRegistry.bind(getServantName(), servant, policies);
- EJBObject corbaObj = createProxy();
+ EJBObject corbaObj = (EJBObject) createProxy();
rebind(ctx, getJndiName(), (org.omg.CORBA.Object) corbaObj);
// TODO: use iri
if(homeInterfaceAnalysis != null)
{
- servant = new BeanCorbaServant(poaCurrent, container, null, homeInterfaceAnalysis);
+ servant = new BeanCorbaServant(this, poaCurrent, container, null, homeInterfaceAnalysis);
this.homeReferenceFactory = homeServantRegistry.bind(getServantName() + "Home", servant, policies);
Object homeObject = createHomeProxy();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -109,6 +109,13 @@
jndiName = producer.getName();
}
+ public Object createProxy(Object id)
+ {
+ if(id != null)
+ throw new IllegalArgumentException("producer proxy must not have an id");
+ return createProxy();
+ }
+
public void setContainer(Container container)
{
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -45,6 +45,13 @@
protected Container container;
protected Advisor advisor;
+ public Object createProxy(Object id)
+ {
+ if(id != null)
+ throw new IllegalArgumentException("service proxy must not have an id");
+ return createProxy();
+ }
+
public void start() throws Exception
{
initializeJndiName();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -25,6 +25,7 @@
import java.util.Hashtable;
import javax.ejb.EJBException;
+import javax.ejb.Handle;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.management.Attribute;
@@ -108,6 +109,13 @@
}
}
+ protected Object createSession(Class initTypes[], Object initArgs[])
+ {
+// if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
+// throw new IllegalArgumentException("service bean create method must take no arguments");
+ throw new RuntimeException("NYI");
+ }
+
public Object getSingleton()
{
return singleton;
@@ -358,6 +366,11 @@
return delegate.invoke(actionName, params, signature);
}
+ @Override
+ protected Object invokeEJBObjectMethod(Object id, MethodInfo info, Object[] args) throws Exception
+ {
+ throw new RuntimeException("NYI");
+ }
public MBeanInfo getMBeanInfo()
{
@@ -416,4 +429,8 @@
}
}
+ protected void removeHandle(Handle handle)
+ {
+ throw new RuntimeException("Don't do this");
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -149,6 +149,11 @@
}
}
+ public Object createProxy(Object id)
+ {
+ throw new RuntimeException("NYI");
+ }
+
public void stop() throws Exception
{
super.stop();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -41,6 +41,7 @@
import org.jboss.ejb3.SessionContainer;
import org.jboss.ejb3.ThreadLocalENCFactory;
import org.jboss.ejb3.cache.StatefulCache;
+import org.jboss.ejb3.iiop.IORFactory;
import org.jboss.ejb3.injection.Injector;
import org.jboss.ejb3.injection.JndiFieldInjector;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
@@ -52,6 +53,7 @@
import javax.annotation.PreDestroy;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
+import javax.ejb.Handle;
import javax.ejb.Init;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
@@ -255,6 +257,11 @@
}
}
+ protected void destroySession(Object id)
+ {
+ getCache().remove(id);
+ }
+
/**
* This should be a remote invocation call
*
@@ -517,7 +524,7 @@
return false;
}
- private Object invokeEJBLocalObjectMethod(Object id, MethodInfo info,
+ protected Object invokeEJBLocalObjectMethod(Object id, MethodInfo info,
Object[] args) throws Exception
{
Method unadvisedMethod = info.getUnadvisedMethod();
@@ -875,4 +882,15 @@
throw new IllegalStateException("Unable to create proxy for getBusinessObject as a proxy factory was not found");
}
+ protected void removeHandle(Handle arg)
+ {
+ StatefulHandleImpl handle = (StatefulHandleImpl) arg;
+
+ //BeanContext ctx = getCache().get(handle.id);
+
+ // TODO: EJBTHREE-670: the pool calls PreDestroy
+ //invokePreDestroy(ctx);
+
+ destroySession(handle.id);
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -158,6 +158,12 @@
}
}
+ public final Object createProxy(Object id)
+ {
+ assert id == null : "stateless bean must not have an id";
+ return createProxy();
+ }
+
public void init() throws Exception
{
initializeJndiName();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -49,6 +49,7 @@
import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
import javax.ejb.EJBException;
+import javax.ejb.Handle;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.naming.NamingException;
@@ -77,6 +78,15 @@
beanContextClass = StatelessBeanContext.class;
}
+ public Object createSession(Class initTypes[], Object initArgs[])
+ {
+ if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
+ throw new IllegalArgumentException("stateless bean create method must take no arguments (EJB3 4.5)");
+ // a stateless bean has no sessions
+ // TODO: pool stuff
+ return null;
+ }
+
public void start() throws Exception
{
try
@@ -367,4 +377,8 @@
}
}
+ protected void removeHandle(Handle handle)
+ {
+ throw new RuntimeException("NYI");
+ }
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySession.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySession.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySession.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -24,7 +24,6 @@
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
-import javax.ejb.Remote;
/**
* Comment
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySessionBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySessionBean.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MySessionBean.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -23,18 +23,13 @@
import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
-import javax.ejb.EJBException;
import javax.ejb.Remote;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
import org.jboss.annotation.ejb.IIOP;
import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.security.SecurityDomain;
import org.jboss.ejb3.iiop.IORFactory;
/**
@@ -47,11 +42,12 @@
@Remote(MySession.class)
@RemoteBinding(factory=IORFactory.class)
@IIOP(interfaceRepositorySupported=false)
+ at SecurityDomain("other")
public class MySessionBean
{
@Resource SessionContext ctx;
- @RolesAllowed({"user"})
+ @RolesAllowed({"allowed"})
public String getWhoAmI()
{
return ctx.getCallerPrincipal().getName();
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MyStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MyStatefulBean.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/MyStatefulBean.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -23,14 +23,18 @@
import java.rmi.RemoteException;
+import javax.annotation.PreDestroy;
import javax.ejb.CreateException;
import javax.ejb.Init;
import javax.ejb.Remote;
import javax.ejb.RemoteHome;
+import javax.ejb.Remove;
+import javax.ejb.RemoveException;
import javax.ejb.Stateful;
import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.ejb3.iiop.IORFactory;
+import org.jboss.logging.Logger;
/**
* Comment
@@ -44,6 +48,8 @@
@RemoteBinding(factory=IORFactory.class)
public class MyStatefulBean
{
+ private static final Logger log = Logger.getLogger(MyStatefulBean.class);
+
private String name;
@Init
@@ -52,16 +58,29 @@
name = "anonymous";
}
+ @Init
public void ejbCreate(String name) throws CreateException, RemoteException
{
this.name = name;
}
+ @Remove
+ public void ejbRemove() throws RemoveException, RemoteException
+ {
+ log.info("remove bean");
+ }
+
public String getName() throws RemoteException
{
return name;
}
+ @PreDestroy
+ public void preDestroy()
+ {
+ log.info("pre destroy");
+ }
+
public String sayHello() throws RemoteException
{
return "Hello " + name;
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/unit/IiopRemoteUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/unit/IiopRemoteUnitTestCase.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/iiop/unit/IiopRemoteUnitTestCase.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -31,10 +31,13 @@
import junit.framework.Test;
+import org.jboss.ejb3.test.iiop.HomedStatelessHome;
import org.jboss.ejb3.test.iiop.MyStatefulHome;
import org.jboss.ejb3.test.iiop.TxTester;
import org.jboss.ejb3.test.iiop.MySession;
import org.jboss.ejb3.test.iiop.MyStateful;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
import org.jboss.test.JBossTestCase;
/**
@@ -62,11 +65,19 @@
props.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
props.put("java.naming.provider.url", "corbaloc::localhost:3528/NameService");
props.put("java.naming.factory.object", "org.jboss.tm.iiop.client.IIOPClientUserTransactionObjectFactory");
+
+// props.put(InitialContext.SECURITY_PRINCIPAL, "somebody");
+// props.put(InitialContext.SECURITY_CREDENTIALS, "password");
+
return props;
}
public void test1() throws Exception
{
+ SimplePrincipal principal = new SimplePrincipal("somebody");
+ SecurityAssociation.setPrincipal(principal);
+ SecurityAssociation.setCredential("password".toCharArray());
+
InitialContext ctx = getInitialContext();
Object obj = ctx.lookup("MySessionBean/remote");
System.err.println(obj.getClass());
@@ -87,8 +98,34 @@
bean1.setName("bean1");
String response = bean1.sayHello();
assertEquals("Hello bean1", response);
+ bean1.remove();
}
+ public void testHomedStateless() throws Exception
+ {
+ InitialContext ctx = getInitialContext();
+ Object obj = ctx.lookup("HomedStatelessBean/remoteHome");
+ HomedStatelessHome home = (HomedStatelessHome) PortableRemoteObject.narrow(obj, HomedStatelessHome.class);
+ MySession session = home.create();
+ String me = new Date().toString();
+ String response = session.sayHelloTo(me);
+ assertEquals("Hi " + me, response);
+ }
+
+ public void testSecurity() throws Exception
+ {
+ SimplePrincipal principal = new SimplePrincipal("somebody");
+ SecurityAssociation.setPrincipal(principal);
+
+ InitialContext ctx = getInitialContext();
+ Object obj = ctx.lookup("MySessionBean/remote");
+ System.err.println(obj.getClass());
+ MySession session = (MySession) PortableRemoteObject.narrow(obj, MySession.class);
+ assertNotNull(session);
+ String actual = session.getWhoAmI();
+ System.err.println("whoAmI = " + actual);
+ }
+
public void testTxPropegation() throws Exception
{
InitialContext ctx = getInitialContext();
Modified: trunk/iiop/src/main/org/jboss/iiop/csiv2/CSIv2Util.java
===================================================================
--- trunk/iiop/src/main/org/jboss/iiop/csiv2/CSIv2Util.java 2006-08-03 16:33:33 UTC (rev 55118)
+++ trunk/iiop/src/main/org/jboss/iiop/csiv2/CSIv2Util.java 2006-08-03 17:47:51 UTC (rev 55119)
@@ -324,7 +324,7 @@
AS_ContextSec context = null;
// the content of the context
- int support = 0;
+ int support = EstablishTrustInClient.value; // per default support this
int require = 0;
byte[] clientAuthMech = {};
byte[] targetName = {};
@@ -337,6 +337,9 @@
if( asMeta == null || asMeta.getAuthMethod().equals(AsContext.AUTH_METHOD_NONE)
|| asMeta.isRequired() == false )
{
+ // TODO: check if an empty AS context may contain a target name.
+ targetName = encodeGssExportedName(targetName);
+
context = new AS_ContextSec((short) support,
(short) require,
clientAuthMech,
@@ -344,9 +347,6 @@
}
else
{
- // we do support
- support = EstablishTrustInClient.value;
-
// required depends on the metadata
if( asMeta.isRequired() )
require = EstablishTrustInClient.value;
More information about the jboss-cvs-commits
mailing list