[jboss-cvs] JBossAS SVN: r76353 - in trunk: testsuite/imports/sections and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 29 04:52:02 EDT 2008
Author: alesj
Date: 2008-07-29 04:52:02 -0400 (Tue, 29 Jul 2008)
New Revision: 76353
Added:
trunk/testsuite/src/main/org/jboss/test/web/servlets/MCAwareServlet.java
trunk/testsuite/src/main/org/jboss/test/web/test/MCAwareUnitTestCase.java
trunk/testsuite/src/resources/web/mcaware/
trunk/testsuite/src/resources/web/mcaware/web.xml
Modified:
trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java
trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
trunk/server/src/main/org/jboss/web/deployers/WebModule.java
trunk/server/src/main/org/jboss/web/deployers/WebModuleMBean.java
trunk/testsuite/imports/sections/web.xml
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
Log:
[JBAS-5808]; exposing MC Kernel and underlying deployment unit as ServletContext attribute.
Modified: trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployer.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -30,7 +30,6 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -42,6 +41,7 @@
import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.metadata.ear.spec.ModuleMetaData;
import org.jboss.metadata.ear.spec.WebModuleMetaData;
@@ -678,6 +678,7 @@
webModule.setConstructor(constructor);
List<ServiceAttributeMetaData> attrs = new ArrayList<ServiceAttributeMetaData>();
+
ServiceAttributeMetaData attr = new ServiceAttributeMetaData();
attr.setName("SecurityManagement");
ServiceInjectionValueMetaData injectionValue = new ServiceInjectionValueMetaData(deployment.getSecurityManagementName());
@@ -690,6 +691,12 @@
attrPR.setValue(injectionValuePR);
attrs.add(attrPR);
+ ServiceAttributeMetaData attrKernel = new ServiceAttributeMetaData();
+ attrKernel.setName("Kernel");
+ ServiceInjectionValueMetaData injectionValueKernel = new ServiceInjectionValueMetaData(KernelConstants.KERNEL_NAME);
+ attrKernel.setValue(injectionValueKernel);
+ attrs.add(attrKernel);
+
webModule.setAttributes(attrs);
// Dependencies...Still have old jmx names here
Modified: trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
-
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.Context;
@@ -42,6 +41,7 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.ejb.EjbUtil50;
import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
+import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData;
import org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData;
@@ -104,6 +104,9 @@
protected MBeanServer server;
protected MainDeployerStructure mainDeployer;
+ // servlet context attributes
+ protected Kernel kernel;
+ protected DeploymentUnit unit;
/**
* The parent class loader first model flag
@@ -142,7 +145,17 @@
{
log = Logger.getLogger(getClass());
}
-
+
+ public void setKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+ public void setDeploymentUnit(DeploymentUnit unit)
+ {
+ this.unit = unit;
+ }
+
/**
* Utility method that builds a string url based on the ServerConfig.SERVER_HOME_URL system
* property and the input url. If the input url is under the SERVER_HOME_URL, the SERVER_HOME_URL
Modified: trunk/server/src/main/org/jboss/web/deployers/WebModule.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/WebModule.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/server/src/main/org/jboss/web/deployers/WebModule.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -23,6 +23,7 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.deployment.DeploymentException;
+import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.security.ISecurityManagement;
@@ -44,24 +45,29 @@
@author adrian at jboss.org
@version $Revison:$
*/
-public class WebModule
- implements WebModuleMBean
+public class WebModule implements WebModuleMBean
{
private static Logger log = Logger.getLogger(WebModule.class);
+
private VFSDeploymentUnit di;
private AbstractWarDeployer container;
private AbstractWarDeployment deployment;
private ISecurityManagement securityManagement;
- public WebModule(VFSDeploymentUnit di, AbstractWarDeployer container,
- AbstractWarDeployment deployment)
+ public WebModule(VFSDeploymentUnit di, AbstractWarDeployer container, AbstractWarDeployment deployment)
{
this.di = di;
this.container = container;
this.deployment = deployment;
- }
+ this.deployment.setDeploymentUnit(di);
+ }
+ public void setKernel(Kernel kernel)
+ {
+ this.deployment.setKernel(kernel);
+ }
+
/**
* Set the PolicyRegistration instance
* @param policyRegistration the policy registration instance
Modified: trunk/server/src/main/org/jboss/web/deployers/WebModuleMBean.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/WebModuleMBean.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/server/src/main/org/jboss/web/deployers/WebModuleMBean.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -21,10 +21,11 @@
*/
package org.jboss.web.deployers;
+import org.jboss.kernel.Kernel;
import org.jboss.security.ISecurityManagement;
import org.jboss.security.authorization.PolicyRegistration;
-
+
/** The standard mbean service interface for the WebModule
* @author Scott.Stark at jboss.org
* @author Anil.Saldhana at redhat.com
@@ -37,6 +38,7 @@
public void stop() throws Exception;
public void destroy() throws Exception;
+ public void setKernel(Kernel kernel);
public void setPolicyRegistration(PolicyRegistration policyRegistration);
public void setSecurityManagement(ISecurityManagement securityManagement);
}
Modified: trunk/testsuite/imports/sections/web.xml
===================================================================
--- trunk/testsuite/imports/sections/web.xml 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/testsuite/imports/sections/web.xml 2008-07-29 08:52:02 UTC (rev 76353)
@@ -3,6 +3,14 @@
<target name="_jars-web">
<mkdir dir="${build.lib}"/>
+ <!-- The mcaware.war -->
+ <war warfile="${build.lib}/mcaware.war"
+ webxml="${build.resources}/web/mcaware/web.xml">
+ <classes dir="${build.classes}">
+ <include name="org/jboss/test/web/servlets/MCAwareServlet.class"/>
+ </classes>
+ </war>
+
<!-- The altdd.war/altddweb.ear -->
<war warfile="${build.lib}/altdd.war"
webxml="${build.resources}/web/altdd/web.xml">
Copied: trunk/testsuite/src/main/org/jboss/test/web/servlets/MCAwareServlet.java (from rev 76315, trunk/testsuite/src/main/org/jboss/test/web/servlets/RequestInfoServlet.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/servlets/MCAwareServlet.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/servlets/MCAwareServlet.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.test.web.servlets;
+
+import java.util.Enumeration;
+import java.io.IOException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A simple servlet that checks MC aware servlet context attributes
+ *
+ * @author Ales.Justin at jboss.org
+ */
+public class MCAwareServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1;
+
+ public void init(ServletConfig servletConfig) throws ServletException
+ {
+ super.init(servletConfig);
+ ServletContext servletContext = servletConfig.getServletContext();
+ checkAttribute(servletContext, "org.jboss.deployers.structure.spi.DeploymentUnit");
+ checkAttribute(servletContext, "jboss.kernel:service=Kernel");
+ }
+
+ protected static void checkAttribute(ServletContext context, String name)
+ {
+ Object attribute = context.getAttribute(name);
+ if (attribute == null)
+ {
+ Enumeration names = context.getAttributeNames();
+ System.out.println("ServletContext attributes = " + context);
+ while(names.hasMoreElements())
+ {
+ System.out.println(names.nextElement());
+ }
+ throw new IllegalArgumentException("No such attribute: " + name);
+ }
+ }
+
+ protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
+ {
+ System.out.println("doGet");
+ }
+
+ protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
+ {
+ System.out.println("doPost");
+ }
+}
\ No newline at end of file
Copied: trunk/testsuite/src/main/org/jboss/test/web/test/MCAwareUnitTestCase.java (from rev 76315, trunk/testsuite/src/main/org/jboss/test/web/test/AltDDUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/test/MCAwareUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/test/MCAwareUnitTestCase.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.test.web.test;
+
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.web.HttpUtils;
+
+/** Tests of using MC aware servlet context
+
+ @author Ales.Justin at jboss.org
+ */
+public class MCAwareUnitTestCase extends JBossTestCase
+{
+ private String baseURL = HttpUtils.getBaseURL();
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(MCAwareUnitTestCase.class, "mcaware.war");
+ }
+
+ public MCAwareUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testMCAwareServlet() throws Exception
+ {
+ URL url = new URL(baseURL+"mcaware/MCAwareServlet");
+ HttpMethodBase request = HttpUtils.accessURL(url);
+ }
+}
\ No newline at end of file
Added: trunk/testsuite/src/resources/web/mcaware/web.xml
===================================================================
--- trunk/testsuite/src/resources/web/mcaware/web.xml (rev 0)
+++ trunk/testsuite/src/resources/web/mcaware/web.xml 2008-07-29 08:52:02 UTC (rev 76353)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
+ <description>The web.xml that should be overriden by altdd-web.xml</description>
+
+ <servlet>
+ <description>A servlet in WEB-INF/classes</description>
+ <servlet-name>MCAwareServlet</servlet-name>
+ <servlet-class>org.jboss.test.web.servlets.MCAwareServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>MCAwareServlet</servlet-name>
+ <url-pattern>/MCAwareServlet</url-pattern>
+ </servlet-mapping>
+
+</web-app>
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -27,12 +27,15 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import javax.servlet.ServletContext;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.ContextConfig;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.DescriptionGroupMetaData;
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
@@ -74,6 +77,9 @@
public static ThreadLocal<DeployerConfig> deployerConfig = new ThreadLocal<DeployerConfig>();
+ public static ThreadLocal<Kernel> kernelLocal = new ThreadLocal<Kernel>();
+ public static ThreadLocal<DeploymentUnit> deploymentUnitLocal = new ThreadLocal<DeploymentUnit>();
+
private static Logger log = Logger.getLogger(JBossContextConfig.class);
private boolean runDestroy = false;
@@ -109,6 +115,13 @@
protected void defaultWebConfig()
{
processWebMetaData(metaDataShared.get());
+
+ ServletContext servletContext = context.getServletContext();
+ Kernel kernel = kernelLocal.get();
+ DeploymentUnit unit = deploymentUnitLocal.get();
+ log.debug("Setting MC attributes, kernel: " + kernel + ", unit: " + unit);
+ servletContext.setAttribute(KernelConstants.KERNEL_NAME, kernel);
+ servletContext.setAttribute(DeploymentUnit.class.getName(), unit);
}
protected void processWebMetaData(JBossWebMetaData metaData)
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2008-07-29 07:20:24 UTC (rev 76352)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2008-07-29 08:52:02 UTC (rev 76353)
@@ -348,6 +348,9 @@
JBossContextConfig.metaDataLocal.set(metaData);
JBossContextConfig.metaDataShared.set(config.getSharedMetaData());
JBossContextConfig.deployerConfig.set(config);
+
+ JBossContextConfig.kernelLocal.set(kernel);
+ JBossContextConfig.deploymentUnitLocal.set(unit);
try
{
// Init the context
@@ -366,6 +369,9 @@
JBossContextConfig.metaDataLocal.set(null);
JBossContextConfig.metaDataShared.set(null);
JBossContextConfig.deployerConfig.set(null);
+
+ JBossContextConfig.kernelLocal.set(null);
+ JBossContextConfig.deploymentUnitLocal.set(null);
}
if (context.getState() != 1)
{
More information about the jboss-cvs-commits
mailing list