[Jboss-cvs] JBossAS SVN: r55495 - in trunk/ejb3/src: main/org/jboss/ejb3 main/org/jboss/injection resources/test/dd/web/WEB-INF test/org/jboss/ejb3/test/dd/web/servlets
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 10 15:08:56 EDT 2006
Author: bill.burke at jboss.com
Date: 2006-08-10 15:08:52 -0400 (Thu, 10 Aug 2006)
New Revision: 55495
Added:
trunk/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java
trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java
trunk/ejb3/src/resources/test/dd/web/WEB-INF/jbosstest-web.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/dd/web/servlets/EJBServlet.java
Log:
implementation and some testing of injeciton annotations for WAR components
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java 2006-08-10 18:05:14 UTC (rev 55494)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java 2006-08-10 19:08:52 UTC (rev 55495)
@@ -21,9 +21,7 @@
*/
package org.jboss.ejb3;
-import java.util.Collection;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import javax.management.ObjectName;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.system.ServiceMBeanSupport;
@@ -43,78 +41,32 @@
private Ejb3JmxDeployment deployment;
private DeploymentInfo di;
- private static class EARImpl implements EAR
- {
- private ConcurrentHashMap<String, Ejb3Deployment> deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
- private String shortName;
- private String baseName;
+ public Ejb3Module(DeploymentInfo di)
+ {
+ EAR ear = null;
+ if (di.parent != null)
+ {
+ if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
+ {
+ synchronized(di.parent.context)
+ {
+ ear = (EAR)di.parent.context.get("EJB3_EAR_METADATA");
+ if (ear == null)
+ {
+ ear = new JmxEARImpl(di.parent.shortName);
+ di.parent.context.put("EJB3_EAR_METADATA", ear);
+ }
+ }
+ }
+ }
+ deployment = new Ejb3JmxDeployment(di, ear);
+ if (ear != null)
+ {
+ ear.register(deployment);
+ }
+ this.di = di;
+ }
- public EARImpl(String shortName)
- {
- this.shortName = shortName;
- int idx = shortName.lastIndexOf('.');
- baseName = shortName.substring(0, idx);
- }
-
- public Collection<Ejb3Deployment> getEjbDeployments()
- {
- return deployments.values();
- }
-
- public void register(Ejb3Deployment deployment)
- {
- deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
- }
-
- public void unregister(Ejb3Deployment deployment)
- {
- deployments.remove(deployment.getDeploymentUnit().getShortName());
- }
-
- public Ejb3Deployment findRelativeDeployment(String relativeName)
- {
- String relativeShortName = relativeName.substring(3);
- return deployments.get(relativeShortName);
- }
-
- public String getShortName()
- {
- return shortName;
- }
-
- public String getBaseName()
- {
- return baseName;
- }
-
- }
-
- public Ejb3Module(DeploymentInfo di)
- {
- EAR ear = null;
- if (di.parent != null)
- {
- if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
- {
- synchronized(di.parent.context)
- {
- ear = (EAR)di.parent.context.get("EJB3_EAR_METADATA");
- if (ear == null)
- {
- ear = new EARImpl(di.parent.shortName);
- di.parent.context.put("EJB3_EAR_METADATA", ear);
- }
- }
- }
- }
- deployment = new Ejb3JmxDeployment(di, ear);
- if (ear != null)
- {
- ear.register(deployment);
- }
- this.di = di;
- }
-
protected void createService() throws Exception
{
super.createService();
Added: trunk/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java 2006-08-10 18:05:14 UTC (rev 55494)
+++ trunk/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java 2006-08-10 19:08:52 UTC (rev 55495)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collection;
+
+/**
+ * JMX JBoss 4.x Kernel abstraction for an ear.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 1.17 $
+ */
+public class JmxEARImpl implements EAR
+{
+ private ConcurrentHashMap<String, Ejb3Deployment> deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
+ private String shortName;
+ private String baseName;
+
+ public JmxEARImpl(String shortName)
+ {
+ this.shortName = shortName;
+ int idx = shortName.lastIndexOf('.');
+ baseName = shortName.substring(0, idx);
+ }
+
+ public Collection<Ejb3Deployment> getEjbDeployments()
+ {
+ return deployments.values();
+ }
+
+ public void register(Ejb3Deployment deployment)
+ {
+ deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
+ }
+
+ public void unregister(Ejb3Deployment deployment)
+ {
+ deployments.remove(deployment.getDeploymentUnit().getShortName());
+ }
+
+ public Ejb3Deployment findRelativeDeployment(String relativeName)
+ {
+ String relativeShortName = relativeName.substring(3);
+ return deployments.get(relativeShortName);
+ }
+
+ public String getShortName()
+ {
+ return shortName;
+ }
+
+ public String getBaseName()
+ {
+ return baseName;
+ }
+
+}
Modified: trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java 2006-08-10 18:05:14 UTC (rev 55494)
+++ trunk/ejb3/src/main/org/jboss/injection/ResourceHandler.java 2006-08-10 19:08:52 UTC (rev 55495)
@@ -39,6 +39,8 @@
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
+import java.net.URL;
+import java.net.MalformedURLException;
/**
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
@@ -67,7 +69,21 @@
if (container.getEncInjectors().containsKey(encName)) continue;
if (envRef.getMappedName() == null || envRef.getMappedName().equals(""))
{
- throw new RuntimeException("mapped-name is required for " + envRef.getResRefName() + " of deployment " + container.getIdentifier());
+ if (envRef.getResUrl() != null)
+ {
+ try
+ {
+ container.getEncInjectors().put(encName, new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ else
+ {
+ throw new RuntimeException("mapped-name is required for " + envRef.getResRefName() + " of deployment " + container.getIdentifier());
+ }
}
container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
Modified: trunk/ejb3/src/resources/test/dd/web/WEB-INF/jbosstest-web.xml
===================================================================
--- trunk/ejb3/src/resources/test/dd/web/WEB-INF/jbosstest-web.xml 2006-08-10 18:05:14 UTC (rev 55494)
+++ trunk/ejb3/src/resources/test/dd/web/WEB-INF/jbosstest-web.xml 2006-08-10 19:08:52 UTC (rev 55495)
@@ -394,12 +394,17 @@
<env-entry-value>com.sun.model.dao.CatalogDAOImpl</env-entry-value>
</env-entry>
+ <env-entry>
+ <env-entry-name>overridenConstant</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>42</env-entry-value>
+ </env-entry>
<!-- ### EJB References (java:comp/env/ejb) -->
<ejb-ref>
<ejb-ref-name>ejb/OptimizedEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>org.jboss.ejb3.test.dd.web.interfaces.StatelessSessionHome</home>
- <remote>org.jboss.ejb3.test.dd.web.interfaces.StatelessSession</remote>\
+ <remote>org.jboss.ejb3.test.dd.web.interfaces.StatelessSession</remote>
<ejb-link>OptimizedEJB</ejb-link>
</ejb-ref>
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/dd/web/servlets/EJBServlet.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/dd/web/servlets/EJBServlet.java 2006-08-10 18:05:14 UTC (rev 55494)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/dd/web/servlets/EJBServlet.java 2006-08-10 19:08:52 UTC (rev 55495)
@@ -27,12 +27,18 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.EntityManagerFactory;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.UserTransaction;
+import javax.ejb.EJB;
+import javax.annotation.Resource;
+
import org.jboss.ejb3.test.dd.web.ejb.Address;
import org.jboss.ejb3.test.dd.web.interfaces.ReferenceTest;
import org.jboss.ejb3.test.dd.web.interfaces.Session30;
@@ -43,8 +49,9 @@
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;
-/** A servlet that accesses an EJB and tests whether the call argument
- is serialized.
+/**
+ *
+ * tests injection annotations of @EJB, @PersistenceContext, @PersistenceUnit, etc...
@author Scott.Stark at jboss.org
@version $Revision$
@@ -52,7 +59,14 @@
public class EJBServlet extends HttpServlet
{
private static final Logger log = Logger.getLogger(EJBServlet.class);
-
+
+ @EJB Session30 injectedSession30;
+ @PersistenceContext(unitName="../dd-web-ejbs.jar#tempdb") EntityManager injectedEntityManager;
+ @PersistenceUnit(unitName="../dd-web-ejbs.jar#tempdb") EntityManagerFactory injectedEntityManagerFactory;
+ @Resource int nonOverridentConstant = 5;
+ @Resource(name="overridenConstant") int overridenConstant = 1;
+ @Resource UserTransaction tx;
+
public void init(ServletConfig config) throws ServletException
{
String param = config.getInitParameter("failOnError");
@@ -85,7 +99,6 @@
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
- UserTransaction tx = null;
try
{
SecurityAssociation.setPrincipal(new SimplePrincipal("jduke"));
@@ -101,6 +114,7 @@
Session30 session30 = (Session30)ctx.lookup("java:comp/env/ejb/Session30");
String access = session30.access();
+ access = injectedSession30.access();
//TODO EMPTYSTRING can't be right - correct lookup when fixed
EntityManager entityManager = (EntityManager)ctx.lookup("java:/WebDDEntityManager");
@@ -111,10 +125,26 @@
address.setState("MA");
address.setZip("02116");
- tx = (UserTransaction)ctx.lookup("UserTransaction");
+ Address address2 = new Address();
+ address.setStreet("Clarendon Street");
+ address.setCity("Boston");
+ address.setState("MA");
+ address.setZip("02116");
+
+ Address address3 = new Address();
+ address.setStreet("Clarendon Street");
+ address.setCity("Boston");
+ address.setState("MA");
+ address.setZip("02116");
+
+ //tx = (UserTransaction)ctx.lookup("UserTransaction");
+ EntityManager em = injectedEntityManagerFactory.createEntityManager();
tx.begin();
entityManager.persist(address);
+ injectedEntityManager.persist(address2);
+ em.persist(address3);
tx.commit();
+ em.close();
}
catch (Exception e)
{
@@ -128,6 +158,8 @@
}
throw new ServletException("Failed to call OptimizedEJB/Session30 through remote and local interfaces", e);
}
+ if (overridenConstant != 42) throw new RuntimeException("@Resource constant not overriden by XML");
+ if (nonOverridentConstant != 5) throw new RuntimeException("@Resource constant should not have been overriden");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
More information about the jboss-cvs-commits
mailing list