[jboss-cvs] JBossAS SVN: r86252 - in projects/ejb3/trunk/endpoint-deployer/src: test/java/org/jboss/ejb3/endpoint/deployers/test/simple and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 24 09:05:56 EDT 2009


Author: wolfc
Date: 2009-03-24 09:05:56 -0400 (Tue, 24 Mar 2009)
New Revision: 86252

Added:
   projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/MyStatefulBean.java
   projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/StatefulGreeter.java
Modified:
   projects/ejb3/trunk/endpoint-deployer/src/main/java/org/jboss/ejb3/endpoint/deployers/impl/EndpointImpl.java
   projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/unit/DeployEndpointTestCase.java
Log:
EJBTHREE-1786: implementing session factory

Modified: projects/ejb3/trunk/endpoint-deployer/src/main/java/org/jboss/ejb3/endpoint/deployers/impl/EndpointImpl.java
===================================================================
--- projects/ejb3/trunk/endpoint-deployer/src/main/java/org/jboss/ejb3/endpoint/deployers/impl/EndpointImpl.java	2009-03-24 13:05:14 UTC (rev 86251)
+++ projects/ejb3/trunk/endpoint-deployer/src/main/java/org/jboss/ejb3/endpoint/deployers/impl/EndpointImpl.java	2009-03-24 13:05:56 UTC (rev 86252)
@@ -28,17 +28,44 @@
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.ejb3.common.lang.SerializableMethod;
 import org.jboss.ejb3.endpoint.Endpoint;
+import org.jboss.ejb3.endpoint.SessionFactory;
 import org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandler;
 import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
+import org.jboss.logging.Logger;
 
 /**
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class EndpointImpl implements Endpoint
+public class EndpointImpl implements Endpoint, SessionFactory
 {
+   private static final Logger log = Logger.getLogger(EndpointImpl.class);
+   
    private InvokableContext container;
+   private StatefulSessionFactory factory;
    
+   public Serializable createSession(Class<?>[] initTypes, Object[] initValues)
+   {
+      if(initTypes != null && initTypes.length != 0)
+         throw new UnsupportedOperationException("SessionFactory " + this + " does not support arguments");
+      if(initValues != null && initValues.length != 0)
+         throw new UnsupportedOperationException("SessionFactory " + this + " does not support arguments");
+      return factory.createSession();
+   }
+   
+   public void destroySession(Serializable session)
+   {
+      log.debug("Session destruction is not supported");
+   }
+   
+   public SessionFactory getSessionFactory() throws IllegalStateException
+   {
+      if(factory == null)
+         throw new IllegalStateException("Endpoint " + this + " is not session aware");
+      return this;
+   }
+
    public Object invoke(final Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
       throws Throwable
    {
@@ -106,10 +133,18 @@
       SerializableMethod businessMethod = new SerializableMethod(method, invokedBusinessInterface);
       return container.invoke(proxy, businessMethod, args);
    }
+
+   public boolean isSessionAware()
+   {
+      return factory != null;
+   }
    
    //@Inject
    public void setContainer(InvokableContext container)
    {
       this.container = container;
+      log.info("container " + container.getClass().getName());
+      if(container instanceof StatefulSessionFactory)
+         this.factory = (StatefulSessionFactory) container;
    }
 }

Added: projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/MyStatefulBean.java	                        (rev 0)
+++ projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/MyStatefulBean.java	2009-03-24 13:05:56 UTC (rev 86252)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.endpoint.deployers.test.simple;
+
+import javax.ejb.Stateful;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+// TODO: an error with default local interface
+// java.lang.IllegalArgumentException: Specified instance of org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData is not resolvable, required type ResolveableJndiNameJbossEnterpriseBeanMetadata must be implemented
+ at Stateful
+public class MyStatefulBean //implements StatefulGreeter
+{
+   private String name;
+   
+   public String sayHi()
+   {
+      return "Hi " + name + " from " + MyStatefulBean.class.getSimpleName();
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+}

Added: projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/StatefulGreeter.java
===================================================================
--- projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/StatefulGreeter.java	                        (rev 0)
+++ projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/StatefulGreeter.java	2009-03-24 13:05:56 UTC (rev 86252)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.endpoint.deployers.test.simple;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface StatefulGreeter
+{
+   String sayHi();
+   
+   void setName(String name);
+}

Modified: projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/unit/DeployEndpointTestCase.java
===================================================================
--- projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/unit/DeployEndpointTestCase.java	2009-03-24 13:05:14 UTC (rev 86251)
+++ projects/ejb3/trunk/endpoint-deployer/src/test/java/org/jboss/ejb3/endpoint/deployers/test/simple/unit/DeployEndpointTestCase.java	2009-03-24 13:05:56 UTC (rev 86252)
@@ -25,6 +25,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.Serializable;
 import java.lang.reflect.Proxy;
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -43,6 +44,7 @@
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.ejb3.endpoint.Endpoint;
 import org.jboss.ejb3.endpoint.deployers.test.simple.Greeter;
+import org.jboss.ejb3.endpoint.deployers.test.simple.StatefulGreeter;
 import org.jboss.ejb3.endpoint.reflect.EndpointInvocationHandler;
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFS;
@@ -178,4 +180,25 @@
       String result = bean.sayHi("Thingy");
       assertEquals("Hi Thingy from MyStatelessBean", result);
    }
+
+   @Test
+   public void testStateful() throws Throwable
+   {
+      // name is not important
+      String name = "jboss.j2ee:jar=tests-classes,name=MyStatefulBean,service=EJB3_endpoint";
+      ControllerState state = null;
+      ControllerContext context = server.getKernel().getController().getContext(name, state);
+      if(context.getState() != ControllerState.INSTALLED)
+         context.getController().change(context, ControllerState.INSTALLED);
+      Endpoint endpoint = (Endpoint) context.getTarget();
+      Serializable session = endpoint.getSessionFactory().createSession(null, null);
+      Class<?> businessInterface = StatefulGreeter.class;
+      EndpointInvocationHandler handler = new EndpointInvocationHandler(endpoint, session, businessInterface);
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      Class<?> interfaces[] = { businessInterface };
+      StatefulGreeter bean = (StatefulGreeter) Proxy.newProxyInstance(loader, interfaces, handler);
+      bean.setName("testStateful");
+      String result = bean.sayHi();
+      assertEquals("Hi testStateful from MyStatefulBean", result);
+   }
 }




More information about the jboss-cvs-commits mailing list