Author: mwringe
Date: 2009-04-02 19:22:29 -0400 (Thu, 02 Apr 2009)
New Revision: 13146
Removed:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/CannotCreatePortletWebAppException.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat4App.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat5App.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat6App.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppAdapter.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppEnhancer.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppIntercepter.java
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/jboss/
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/impl/xml/
Modified:
branches/JBoss_Portal_Branch_2_7_AS5/server/.classpath
branches/JBoss_Portal_Branch_2_7_AS5/server/build.xml
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
Log:
Remove some of the old deployer classes.
Add theme deployment support.
Modified: branches/JBoss_Portal_Branch_2_7_AS5/server/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_7_AS5/server/.classpath 2009-04-02 23:22:25 UTC (rev
13145)
+++ branches/JBoss_Portal_Branch_2_7_AS5/server/.classpath 2009-04-02 23:22:29 UTC (rev
13146)
@@ -5,7 +5,6 @@
<classpathentry kind="lib"
path="/thirdparty/apache-httpclient/lib/commons-httpclient.jar"/>
<classpathentry kind="lib"
path="/thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss.jar"/>
- <classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss-common.jar"/>
<classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss-jmx.jar"/>
<classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss-system.jar"/>
<classpathentry kind="lib"
path="/thirdparty/junit/lib/junit.jar"/>
@@ -15,5 +14,9 @@
<classpathentry kind="lib"
path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
<classpathentry kind="lib"
path="/thirdparty/jboss-portal/modules/test/lib/portal-test-jboss-lib.jar"/>
<classpathentry kind="lib"
path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
+ <classpathentry kind="lib"
path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar"/>
+ <classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss-j2se.jar"/>
+ <classpathentry kind="lib"
path="/thirdparty/jbossas/core-libs/lib/jboss-system-jmx.jar"/>
+ <classpathentry kind="lib"
path="/thirdparty/jboss/microcontainer/lib/jboss-kernel.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_7_AS5/server/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7_AS5/server/build.xml 2009-04-02 23:22:25 UTC (rev
13145)
+++ branches/JBoss_Portal_Branch_2_7_AS5/server/build.xml 2009-04-02 23:22:29 UTC (rev
13146)
@@ -99,8 +99,8 @@
<path refid="jboss.portal/modules/deployer.classpath"/>
<pathelement
location="${jboss.portal/modules/test.lib}/portal-test-jboss-lib.jar"/>
<path refid="dom4j.dom4j.classpath"/>
- <path refid="oswego.concurrent.classpath"/>
<path refid="jbossas/core.libs.classpath"/>
+ <path refid="jboss/common.logging.spi.classpath"/>
<path refid="jboss/jboss.metadata.classpath"/>
<path refid="jboss/jboss.deployers.classpath"/>
<path refid="apache.ant.classpath"/>
@@ -114,10 +114,7 @@
<path refid="sun.jaxb.classpath"/>
<path refid="sun.servlet.classpath"/>
<path refid="jboss.web.classpath"/>
- <pathelement location="jboss-bean-deployer.jar"/>
- <pathelement location="jboss-container.jar"/>
- <pathelement location="jboss-dependency.jar"/>
- <pathelement location="jboss-microcontainer.jar"/>
+ <path refid="jboss.microcontainer.classpath"/>
</path>
<!-- Configure modules -->
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/CannotCreatePortletWebAppException.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/CannotCreatePortletWebAppException.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/CannotCreatePortletWebAppException.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,52 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class CannotCreatePortletWebAppException extends Exception
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -6650792671320003420L;
-
- public CannotCreatePortletWebAppException()
- {
- }
-
- public CannotCreatePortletWebAppException(String message)
- {
- super(message);
- }
-
- public CannotCreatePortletWebAppException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public CannotCreatePortletWebAppException(Throwable cause)
- {
- super(cause);
- }
-}
Modified:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -22,26 +22,13 @@
******************************************************************************/
package org.jboss.portal.server.deployment;
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.common.xml.NullEntityResolver;
-import org.jboss.portal.common.xml.XMLTools;
-import org.jboss.portal.web.WebApp;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.SAXException;
+import java.net.URL;
import javax.servlet.ServletContext;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
+import org.apache.log4j.Logger;
+import org.jboss.portal.web.WebApp;
+
/**
* Encapsulate the infos needed by the portal deployment layer to create the
application.
*
@@ -55,9 +42,6 @@
protected final Logger log = Logger.getLogger(getClass());
/** . */
- private Document descriptor;
-
- /** . */
private ServletContext servletContext;
/** . */
@@ -110,100 +94,7 @@
return servletContext;
}
- public final Document getDescriptor()
- {
- return descriptor;
- }
-
- /**
- * Import a file in the war file. The file could not be created for some reasons which
are : <ul> <li>The parent dir
- * exists and is a file</li> <li>The parent dir does not exist and its
creation failed</li> <li>An underlying
- * exception occurs when writing bytes from the source
<code>Inputstream</code> to the target
- * <code>OutputStream</code></li> </ul>
- *
- * @param parentDirRelativePath the parent relative path in the web app starting from
the app root
- * @param name the name the created file should have
- * @param source the data of the target file
- * @param overwrite if false and the file already exists nothing is done
- * @return true if the file has been created
- * @throws IOException if the file cannot be created
- */
- public final boolean importFile(String parentDirRelativePath, String name, InputStream
source, boolean overwrite) throws IOException
- {
- ServletContext ctx = getServletContext();
- String contextPath = getContextPath();
-
- // Get the parent dir
- String parentAbsolutePath = ctx.getRealPath(parentDirRelativePath);
- File parentDir = new File(parentAbsolutePath);
-
- // We ensure it exists
- if (parentDir.exists())
- {
- if (parentDir.isFile())
- {
- throw new IOException("Target parent dir " + parentDirRelativePath
+ " already exists in the web application and is a file " + contextPath);
- }
- }
- else
- {
- if (!parentDir.mkdirs())
- {
- throw new IOException("Was not able to create the parent dir " +
parentDirRelativePath + " in the web application " + contextPath);
- }
- }
-
- //
- boolean done = false;
- File targetFile = new File(parentDir, name);
- if (overwrite || !targetFile.exists())
- {
- OutputStream target = null;
- try
- {
- target = IOTools.safeBufferedWrapper(new FileOutputStream(new File(parentDir,
name)));
- IOTools.copy(source, target);
- done = true;
- log.debug("Copied file" + name + " to location " +
parentDirRelativePath);
- }
- finally
- {
- IOTools.safeClose(target);
- }
- }
- return done;
- }
-
protected final void init(
- ServletContext servletContext,
- URL url,
- ClassLoader loader,
- String contextPath,
- EntityResolver jbossAppEntityResolver) throws CannotCreatePortletWebAppException
- {
- this.servletContext = servletContext;
- this.url = url;
- this.loader = loader;
- this.contextPath = contextPath;
- this.id = contextPath;
-
- //
- readJBossAppDescriptor(jbossAppEntityResolver);
-
- // Override the id if not null
- if (descriptor != null)
- {
- Element jbossAppElt = descriptor.getDocumentElement();
- Element appNameElt = XMLTools.getUniqueChild(jbossAppElt, "app-name",
false);
- if (appNameElt != null)
- {
- id = XMLTools.asString(appNameElt);
- log.debug("Detected explicit app name = " + id + " for
application under path " + getContextPath());
- }
- }
- }
-
- protected final void init(
ServletContext servletContext,
URL url,
ClassLoader loader,
@@ -216,52 +107,6 @@
this.id = contextPath;
}
- /**
- * Read jboss-portal-app.xml deployment and fetch the overriden id if it exists.
- *
- * @return the app id or null if it does not exists
- */
- private void readJBossAppDescriptor(EntityResolver jbossAppEntityResolver)
- {
- // Look for jboss-app.xml override
- InputStream in = null;
- try
- {
- in =
IOTools.safeBufferedWrapper(getServletContext().getResourceAsStream("/WEB-INF/jboss-portal-app.xml"));
- if (in != null)
- {
- DocumentBuilder builder =
XMLTools.getDocumentBuilderFactory().newDocumentBuilder();
- if (jbossAppEntityResolver == null)
- {
- log.debug("Coult not obtain entity resolver for
jboss-portal-app.xml");
- jbossAppEntityResolver = new NullEntityResolver();
- }
- else
- {
- log.debug("Obtained entity resolver " + jbossAppEntityResolver +
" for jboss-portal-app.xml");
- }
- builder.setEntityResolver(jbossAppEntityResolver);
- descriptor = builder.parse(in);
- }
- }
- catch (IOException e)
- {
- log.debug("Cannot read jboss-portal-app.xml", e);
- }
- catch (ParserConfigurationException e)
- {
- log.debug("Cannot read jboss-portal-app.xml", e);
- }
- catch (SAXException e)
- {
- log.debug("Cannot read jboss-portal-app.xml", e);
- }
- finally
- {
- IOTools.safeClose(in);
- }
- }
-
public String toString()
{
return "WebApp[" + getContextPath() + "]";
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,139 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.apache.log4j.Logger;
-import org.jboss.web.WebApplication;
-import org.xml.sax.EntityResolver;
-
-import javax.management.MBeanServer;
-import java.lang.reflect.Method;
-
-/**
- * Creates the JBossWebApp according to the JBossWeb found.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortalWebAppFactory
-{
-
- private static Logger log = Logger.getLogger(PortalWebAppFactory.class);
-
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
- private static final int UNKNOWN = 0;
- private static final int TOMCAT4 = 1;
- private static final int TOMCAT5 = 2;
- private static final int TOMCAT6 = 3;
-
- private final MBeanServer server;
-
- public PortalWebAppFactory(MBeanServer server)
- {
- this.server = server;
- }
-
- /**
- * Create a portal web application.
- *
- * @return the portal web app or null if it cannot be created.
- */
- public PortalWebApp create(WebApplication webApp, EntityResolver
jbossAppEntityResolver) throws CannotCreatePortletWebAppException
- {
- int version = getVersion();
- switch (version)
- {
- case TOMCAT4:
- return new PortalWebTomcat4App(webApp, jbossAppEntityResolver);
- case TOMCAT5:
- return new PortalWebTomcat5App(webApp, server, jbossAppEntityResolver);
- case TOMCAT6:
- return new PortalWebTomcat6App(webApp, server, jbossAppEntityResolver);
- default:
- throw new CannotCreatePortletWebAppException("JBossWeb cannot handle it
: " + version);
- }
- }
-
- /**
- * Recognize the jbossweb container and returns its version.
- *
- * @return the jbossweb detected version or <code>UNKNOWN</code>
- */
- private static int getVersion()
- {
- try
- {
- // Get the classloader
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class serverInfoClass =
cl.loadClass("org.apache.catalina.util.ServerInfo");
- Method getServerInfoMethod =
serverInfoClass.getMethod("getServerInfo", EMPTY_CLASS_ARRAY);
- String result = (String)getServerInfoMethod.invoke(null, EMPTY_OBJECT_ARRAY);
- if (result != null)
- {
- if (result.startsWith("Apache Tomcat/6"))
- {
- return TOMCAT6;
- }
- else if (result.startsWith("Apache Tomcat/5"))
- {
- return TOMCAT5;
- }
- else if (result.startsWith("Apache Tomcat/4"))
- {
- return TOMCAT4;
- }
- else if (result.startsWith("JBoss Web Server/1"))
- {
- return TOMCAT5;
- }
- else if (result.startsWith("JBossWeb/2"))
- {
- return TOMCAT6;
- }
- else if (result.startsWith("JBoss Web/2"))
- {
- return TOMCAT6;
- }
- else
- {
- log.error("Cannot handle tomcat version: " + result);
- }
- }
- }
- catch (ClassNotFoundException e)
- {
- log.error("Cannot getPortalObjectContext catalina ServerInfo class");
- }
- catch (NoSuchMethodException e)
- {
- log.error("Cannot invoke ServerInfo.getServerInfo()", e);
- }
- catch (Exception e)
- {
- log.error("Unexpected error", e);
- }
- return UNKNOWN;
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat4App.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat4App.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat4App.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,143 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.jboss.portal.web.command.CommandServlet;
-import org.jboss.web.WebApplication;
-import org.xml.sax.EntityResolver;
-
-import javax.servlet.ServletContext;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortalWebTomcat4App extends PortalWebApp
-{
-
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
-
- private final WebApplication webApp;
-
- public PortalWebTomcat4App(WebApplication webApp, EntityResolver
jbossAppEntityResolver) throws CannotCreatePortletWebAppException
- {
- try
- {
- this.webApp = webApp;
-
- //
- Object ctx = webApp.getAppData();
- String contextPath = getContextPath(ctx);
- ServletContext servletContext = getServletContext(ctx);
- URL url = webApp.getURL();
-
- //
- init(servletContext, url, null, contextPath, jbossAppEntityResolver);
- }
- catch (Exception e)
- {
- CannotCreatePortletWebAppException ex = null;
- if (e instanceof CannotCreatePortletWebAppException)
- {
- ex = (CannotCreatePortletWebAppException)e;
- }
- else
- {
- ex = new CannotCreatePortletWebAppException(e);
- }
- throw ex;
- }
- }
-
- public void instrument() throws Exception
- {
- Object ctx = webApp.getAppData();
- inject(ctx);
- }
-
- public static void inject(Object standardContext) throws Exception
- {
- try
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- Class standardContextClass = standardContext.getClass();
- Class containerBaseClass = standardContextClass.getSuperclass();
- Class containerItf = cl.loadClass("org.apache.catalina.Container");
- Class contextItf = cl.loadClass("org.apache.catalina.Context");
-
- // Inject the command servlet only one time, so we look if it exist already
- Method findChildMethod = containerItf.getMethod("findChild", new
Class[]{String.class});
- Object commandServlet = findChildMethod.invoke(standardContext, new
Object[]{"CommandServlet"});
- if (commandServlet == null)
- {
- Method createWrapperMethod =
standardContextClass.getMethod("createWrapper", EMPTY_CLASS_ARRAY);
- Object wrapper = createWrapperMethod.invoke(standardContext,
EMPTY_OBJECT_ARRAY);
- Class wrapperClass = wrapper.getClass();
- Object[] wrapperArray = (Object[])Array.newInstance(containerItf, 1);
- wrapperArray[0] = wrapper;
-
- Method setServletNameMethod =
wrapperClass.getMethod("setServletName", new Class[]{String.class});
- setServletNameMethod.invoke(wrapper, new
Object[]{"CommandServlet"});
-
- Method setServletClassMethod =
wrapperClass.getMethod("setServletClass", new Class[]{String.class});
- setServletClassMethod.invoke(wrapper, new
Object[]{CommandServlet.class.getName()});
-
- Method setLoadOnStartupMethod =
wrapperClass.getMethod("setLoadOnStartup", new Class[]{int.class});
- setLoadOnStartupMethod.invoke(wrapper, new Object[]{new Integer(0)});
-
- Method addChildMethod = containerBaseClass.getMethod("addChild",
new Class[]{containerItf});
- addChildMethod.invoke(standardContext, new Object[]{wrapper});
-
- Method addServletMapping =
contextItf.getMethod("addServletMapping", new Class[]{String.class,
String.class});
- addServletMapping.invoke(standardContext, new
Object[]{"/jbossportlet", "CommandServlet"});
-
- Method loadOnStartupMethod =
standardContextClass.getMethod("loadOnStartup", new
Class[]{wrapperArray.getClass()});
- loadOnStartupMethod.invoke(standardContext, new Object[]{wrapperArray});
- }
- }
- catch (InvocationTargetException e)
- {
- e.getTargetException().printStackTrace();
- }
- }
-
- public static ServletContext getServletContext(Object standardContext) throws
Exception
- {
- Class standardContextClass = standardContext.getClass();
- Method getServletContextMethod =
standardContextClass.getMethod("getServletContext", EMPTY_CLASS_ARRAY);
- return (ServletContext)getServletContextMethod.invoke(standardContext,
EMPTY_OBJECT_ARRAY);
- }
-
- public static String getContextPath(Object standardContext) throws Exception
- {
- Class standardContextClass = standardContext.getClass();
- Method getServletContextMethod =
standardContextClass.getMethod("getPath", EMPTY_CLASS_ARRAY);
- return (String)getServletContextMethod.invoke(standardContext,
EMPTY_OBJECT_ARRAY);
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat5App.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat5App.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat5App.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,175 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.jboss.portal.web.command.CommandServlet;
-import org.jboss.web.WebApplication;
-import org.xml.sax.EntityResolver;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.servlet.ServletContext;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortalWebTomcat5App extends PortalWebApp
-{
-
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
-
- private final Object standardContext;
- private final WebApplication webApp;
-
- public PortalWebTomcat5App(WebApplication webApp, MBeanServer server, EntityResolver
jbossAppEntityResolver) throws CannotCreatePortletWebAppException
- {
- try
- {
- ObjectName name = (ObjectName)webApp.getAppData();
-
- //
- this.webApp = webApp;
- this.standardContext = server.getAttribute(name, "managedResource");
-
- //
- String contextPath = PortalWebTomcat4App.getContextPath(standardContext);
- ServletContext servletContext =
PortalWebTomcat4App.getServletContext(standardContext);
- ClassLoader loader = getClassLoader(server, name);
- URL url = webApp.getURL();
-
- //
- init(servletContext, url, loader, contextPath, jbossAppEntityResolver);
- }
- catch (Exception e)
- {
- CannotCreatePortletWebAppException ex = null;
- if (e instanceof CannotCreatePortletWebAppException)
- {
- ex = (CannotCreatePortletWebAppException)e;
- }
- else
- {
- ex = new CannotCreatePortletWebAppException(e);
- }
- throw ex;
- }
- }
-
- public void instrument() throws Exception
- {
- // Get class loader
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- // Get some class
- Class containerItf = cl.loadClass("org.apache.catalina.Container");
-
- // Inject the command servlet only one time, so we look if it exist already
- Method findChildMethod = containerItf.getMethod("findChild", new
Class[]{String.class});
- Object commandServlet = findChildMethod.invoke(standardContext, new
Object[]{"CommandServlet"});
- if (commandServlet == null)
- {
- setRunAsListenerAssociation(webApp.getMetaData());
- try
- {
- addCommandServlet(cl);
- }
- finally
- {
- setRunAsListenerAssociation(null);
- }
- }
- }
-
- private void setRunAsListenerAssociation(Object o)
- {
- try
- {
- Class clazz =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.web.tomcat.security.RunAsListener");
-
- //
- log.debug("RunAsListener detected");
- Field field = clazz.getDeclaredField("metaDataLocal");
- ThreadLocal threadLocal = (ThreadLocal)field.get(null);
- threadLocal.set(o);
- }
- catch (ClassNotFoundException e)
- {
- log.debug("RunAsListener not detected");
- }
- catch (IllegalAccessException e)
- {
- log.error("Cannot set the RunAsListener threadlocal because of a security
manager", e);
- }
- catch (Exception e)
- {
- log.error("Unexpected exception");
- }
- }
-
- private void addCommandServlet(ClassLoader cl) throws Exception
- {
- //
- Class containerItf = cl.loadClass("org.apache.catalina.Container");
- Class standardContextClass =
cl.loadClass("org.apache.catalina.core.StandardContext");
- Class containerBaseClass =
cl.loadClass("org.apache.catalina.core.ContainerBase");
- Class contextItf = cl.loadClass("org.apache.catalina.Context");
-
- // Ask the context to create a wrapper
- Method createWrapperMethod =
standardContextClass.getMethod("createWrapper", EMPTY_CLASS_ARRAY);
- Object wrapper = createWrapperMethod.invoke(standardContext, EMPTY_OBJECT_ARRAY);
- Class wrapperClass = wrapper.getClass();
- Object[] wrapperArray = (Object[])Array.newInstance(containerItf, 1);
- wrapperArray[0] = wrapper;
-
- Method setServletNameMethod = wrapperClass.getMethod("setServletName",
new Class[]{String.class});
- setServletNameMethod.invoke(wrapper, new Object[]{"CommandServlet"});
-
- Method setServletClassMethod = wrapperClass.getMethod("setServletClass",
new Class[]{String.class});
- setServletClassMethod.invoke(wrapper, new
Object[]{CommandServlet.class.getName()});
-
- Method setLoadOnStartupMethod =
wrapperClass.getMethod("setLoadOnStartup", new Class[]{int.class});
- setLoadOnStartupMethod.invoke(wrapper, new Object[]{new Integer(0)});
-
- Method addChildMethod = containerBaseClass.getMethod("addChild", new
Class[]{containerItf});
- addChildMethod.invoke(standardContext, new Object[]{wrapper});
-
- Method addServletMapping = contextItf.getMethod("addServletMapping", new
Class[]{String.class, String.class});
- addServletMapping.invoke(standardContext, new Object[]{"/jbossportlet",
"CommandServlet"});
-
- Method loadOnStartupMethod =
standardContextClass.getMethod("loadOnStartup", new
Class[]{wrapperArray.getClass()});
- loadOnStartupMethod.invoke(standardContext, new Object[]{wrapperArray});
- }
-
- private ClassLoader getClassLoader(MBeanServer server, ObjectName name) throws
Exception
- {
- Object loader = server.getAttribute(name, "loader");
- Method getClassLoaderMethod =
loader.getClass().getMethod("getClassLoader", new Class[0]);
- return (ClassLoader)getClassLoaderMethod.invoke(loader, new Object[0]);
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat6App.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat6App.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/PortalWebTomcat6App.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,180 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.apache.catalina.deploy.SessionCookie;
-import org.jboss.portal.web.command.CommandServlet;
-import org.jboss.web.WebApplication;
-import org.xml.sax.EntityResolver;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.servlet.ServletContext;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortalWebTomcat6App extends PortalWebApp
-{
-
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
-
- private final Object standardContext;
- private final WebApplication webApp;
-
- public PortalWebTomcat6App(WebApplication webApp, MBeanServer server, EntityResolver
jbossAppEntityResolver) throws CannotCreatePortletWebAppException
- {
- try
- {
- ObjectName name = (ObjectName)webApp.getAppData();
-
- //
- this.webApp = webApp;
- this.standardContext = server.getAttribute(name, "managedResource");
-
- //
- String contextPath = PortalWebTomcat4App.getContextPath(standardContext);
- ServletContext servletContext =
PortalWebTomcat4App.getServletContext(standardContext);
- ClassLoader loader = getClassLoader(server, name);
- URL url = webApp.getURL();
-
- //
- init(servletContext, url, loader, contextPath, jbossAppEntityResolver);
- }
- catch (Exception e)
- {
- CannotCreatePortletWebAppException ex;
- if (e instanceof CannotCreatePortletWebAppException)
- {
- ex = (CannotCreatePortletWebAppException)e;
- }
- else
- {
- ex = new CannotCreatePortletWebAppException(e);
- }
- throw ex;
- }
- }
-
- public void instrument() throws Exception
- {
- // Get class loader
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- // Get some class
- Class containerItf = cl.loadClass("org.apache.catalina.Container");
-
- // Inject the command servlet only one time, so we look if it exist already
- Method findChildMethod = containerItf.getMethod("findChild", new
Class[]{String.class});
- Object commandServlet = findChildMethod.invoke(standardContext, new
Object[]{"CommandServlet"});
- if (commandServlet == null)
- {
- setRunAsListenerAssociation(webApp.getMetaData());
- try
- {
- addCommandServlet(cl);
- }
- finally
- {
- setRunAsListenerAssociation(null);
- }
- }
- }
-
- private void setRunAsListenerAssociation(Object o)
- {
- try
- {
- Class clazz =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.web.tomcat.security.RunAsListener");
-
- //
- log.debug("RunAsListener detected");
- Field field = clazz.getDeclaredField("metaDataLocal");
- ThreadLocal threadLocal = (ThreadLocal)field.get(null);
- threadLocal.set(o);
- }
- catch (ClassNotFoundException e)
- {
- log.debug("RunAsListener not detected");
- }
- catch (IllegalAccessException e)
- {
- log.error("Cannot set the RunAsListener threadlocal because of a security
manager", e);
- }
- catch (Exception e)
- {
- log.error("Unexpected exception");
- }
- }
-
- private void addCommandServlet(ClassLoader cl) throws Exception
- {
- //
- Class containerItf = cl.loadClass("org.apache.catalina.Container");
- Class standardContextClass =
cl.loadClass("org.apache.catalina.core.StandardContext");
- Class containerBaseClass =
cl.loadClass("org.apache.catalina.core.ContainerBase");
- Class contextItf = cl.loadClass("org.apache.catalina.Context");
-
- // Ask the context to create a wrapper
- Method createWrapperMethod =
standardContextClass.getMethod("createWrapper", EMPTY_CLASS_ARRAY);
- Object wrapper = createWrapperMethod.invoke(standardContext, EMPTY_OBJECT_ARRAY);
- Class wrapperClass = wrapper.getClass();
- Object[] wrapperArray = (Object[])Array.newInstance(containerItf, 1);
- wrapperArray[0] = wrapper;
-
- Method setServletNameMethod = wrapperClass.getMethod("setServletName",
new Class[]{String.class});
- setServletNameMethod.invoke(wrapper, new Object[]{"CommandServlet"});
-
- Method setServletClassMethod = wrapperClass.getMethod("setServletClass",
new Class[]{String.class});
- setServletClassMethod.invoke(wrapper, new
Object[]{CommandServlet.class.getName()});
-
- Method setLoadOnStartupMethod =
wrapperClass.getMethod("setLoadOnStartup", new Class[]{int.class});
- setLoadOnStartupMethod.invoke(wrapper, new Object[]{new Integer(0)});
-
- Method addChildMethod = containerBaseClass.getMethod("addChild", new
Class[]{containerItf});
- addChildMethod.invoke(standardContext, new Object[]{wrapper});
-
- Method getSessionCookie = contextItf.getMethod("getSessionCookie", new
Class[]{});
- SessionCookie cookie = (SessionCookie) getSessionCookie.invoke(standardContext, new
Object[]{});
- cookie.setPath("/");
-
- Method addServletMapping = contextItf.getMethod("addServletMapping", new
Class[]{String.class, String.class});
- addServletMapping.invoke(standardContext, new Object[]{"/jbossportlet",
"CommandServlet"});
-
- Method loadOnStartupMethod =
standardContextClass.getMethod("loadOnStartup", new
Class[]{wrapperArray.getClass()});
- loadOnStartupMethod.invoke(standardContext, new Object[]{wrapperArray});
- }
-
- private ClassLoader getClassLoader(MBeanServer server, ObjectName name) throws
Exception
- {
- Object loader = server.getAttribute(name, "loader");
- Method getClassLoaderMethod =
loader.getClass().getMethod("getClassLoader", new Class[0]);
- return (ClassLoader)getClassLoaderMethod.invoke(loader, new Object[0]);
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppAdapter.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppAdapter.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppAdapter.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,72 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.server.deployment.jboss.ServerDeployerMBean;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class WebAppAdapter
- extends WebAppIntercepter
-{
-
- /** The specific portal web app deployer. */
- private ServerDeployerMBean deployer;
-
- public ServerDeployerMBean getDeployer()
- {
- return deployer;
- }
-
- public void setDeployer(ServerDeployerMBean deployer)
- {
- this.deployer = deployer;
- }
-
- protected void deploy(PortalWebApp pwa)
- {
- try
- {
- deployer.deploy(pwa);
- }
- catch (DeploymentException e)
- {
-// JBossTestAgent.record(e);
- }
- }
-
- protected void undeploy(PortalWebApp pwa)
- {
- try
- {
- deployer.undeploy(pwa);
- }
- catch (DeploymentException e)
- {
-// JBossTestAgent.record(e);
- }
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppEnhancer.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppEnhancer.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppEnhancer.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,111 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.jboss.mx.util.MBeanProxy;
-import org.jboss.portal.common.xml.XMLTools;
-import org.jboss.portal.server.config.ServerConfig;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import javax.management.ObjectName;
-import java.util.Iterator;
-
-/**
- * The role of this object is to modify the web application so it is possible to invoke
it by request distpatching.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class WebAppEnhancer extends WebAppIntercepter
-{
-
- /** . */
- private ServerConfig config;
-
- public ServerConfig getConfig()
- {
- return config;
- }
-
- public void setConfig(ServerConfig config)
- {
- this.config = config;
- }
-
- protected void deploy(PortalWebApp pwa)
- {
- try
- {
- // Instrument war file first
- pwa.instrument();
-
- // Inject proxies in the servlet context
- Document desc = pwa.getDescriptor();
- if (desc != null)
- {
- Element jbossAppElt = desc.getDocumentElement();
- for (Iterator i = XMLTools.getChildren(jbossAppElt,
"service").iterator(); i.hasNext();)
- {
- Element serviceElt = (Element)i.next();
-
- //
- log.debug("About to inject a service in the servlet context of "
+ pwa.getURL());
-
- //
- Element serviceNameElt = XMLTools.getUniqueChild(serviceElt,
"service-name", true);
- Element serviceClassElt = XMLTools.getUniqueChild(serviceElt,
"service-class", true);
- Element serviceRefElt = XMLTools.getUniqueChild(serviceElt,
"service-ref", true);
- String serviceName = XMLTools.asString(serviceNameElt);
- String serviceClass = XMLTools.asString(serviceClassElt);
- String serviceRef = XMLTools.asString(serviceRefElt);
-
- //
- if (serviceRef.startsWith(":"))
- {
- log.debug("Detecting a relative service reference " +
serviceRef + " prepending it with " + config.getDomain());
- serviceRef = config.getDomain() + serviceRef;
- }
-
- //
- Class proxyClass = pwa.getClassLoader().loadClass(serviceClass);
- ObjectName objectName = ObjectName.getInstance(serviceRef);
- Object proxy = MBeanProxy.get(proxyClass, objectName, server);
-
- //
- log.debug("Want to inject " + serviceRef + " with class
" + proxy + " and name " + serviceName);
- pwa.getServletContext().setAttribute(serviceName, proxy);
- }
- }
-
- }
- catch (Exception e)
- {
- log.error("Cannot instrument the web application", e);
- }
- }
-
- protected void undeploy(PortalWebApp jwa)
- {
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppIntercepter.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppIntercepter.java 2009-04-02
23:22:25 UTC (rev 13145)
+++
branches/JBoss_Portal_Branch_2_7_AS5/server/src/main/org/jboss/portal/server/deployment/WebAppIntercepter.java 2009-04-02
23:22:29 UTC (rev 13146)
@@ -1,189 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.portal.server.deployment;
-
-import org.jboss.deployment.DeploymentInfo;
-import org.jboss.deployment.SubDeployer;
-import org.jboss.portal.deployer.portal.PortalPostWebDeployer;
-import org.jboss.portal.deployer.portal.WebDeploymentListener;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.web.WebApplication;
-import org.xml.sax.EntityResolver;
-
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Relay web deployments. When a web deployment occurs, it is abstracted into a
PortalWebApp object that provides a
- * consistent way to getPortalObjectContext informations and modify the web application.
- * <p/>
- * When this service stops it does not send undeployment notifications, therefore it is
up to the client of this service
- * to perform any cleanup task associated to a deployment web application. The purpose of
this is that most of the time
- * clients of this service will be stopped before this one and they would receive
undeployments in a not started state.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public abstract class WebAppIntercepter
- extends AbstractJBossService
- implements WebDeploymentListener
- //implements NotificationListener
-{
-
- /** WARDeployer. */
-
- /** The current deployements. */
- private Map deployments;
-
- /** The factory creating the portal web app objects. */
- private PortalWebAppFactory factory;
-
- /** The right classloader for fixing the issue with the fact that the classloader is
not good on event notifications. */
- private ClassLoader classLoader;
-
- /** The entity resolver for jboss-app.xml. */
- private EntityResolver jbossAppEntityResolver;
-
- private PortalPostWebDeployer portalDeployer;
-
- public WebAppIntercepter()
- {
- deployments = Collections.synchronizedMap(new HashMap());
- classLoader = Thread.currentThread().getContextClassLoader();
- }
-
- public EntityResolver getJBossAppEntityResolver()
- {
- return jbossAppEntityResolver;
- }
-
- public void setJBossAppEntityResolver(EntityResolver jbossAppEntityResolver)
- {
- this.jbossAppEntityResolver = jbossAppEntityResolver;
- }
-
- public void setPortalDeployer(PortalPostWebDeployer portalDeployer)
- {
- this.portalDeployer = portalDeployer;
- }
- /** Set the deployer on this service. */
- public void portalDeployed(WebApplication webapp)
- {
- ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(classLoader);
-
- PortalWebApp pwa = factory.create(webapp, jbossAppEntityResolver);
- deployments.put(webapp.getURL(), pwa);
- log.debug("Seen URL " + webapp.getURL() + " about to deploy");
- deploy(pwa);
- } catch (Exception e){
- e.printStackTrace();
- } finally
- {
- Thread.currentThread().setContextClassLoader(previousLoader);
- }
-
- /** Return the intercepted deployer. */
- }
-
- public void portalUndeployed(WebApplication webapp)
- {
-
- PortalWebApp pwa = (PortalWebApp)deployments.remove(webapp.getURL());
- if (pwa != null)
- {
- log.debug("Undeploying URL " + webapp.getURL());
- undeploy(pwa);
- }
- }
-
-// /** Set the deployer on this service. */
-// public void setInterceptedDeployer(ObjectName interceptedDeployer)
-// {
-// this.interceptedDeployer = interceptedDeployer;
-// }
-
- /** Return the intercepted deployer. */
- //public ObjectName getInterceptedDeployer()
- //{
- //return interceptedDeployer;
- //}
-
- /** Clone and return the deployed URLs. */
- public Collection getDeployedURLs()
- {
- return new ArrayList(deployments.keySet());
- }
-
-
- /** Start listening to the deployer notifications. */
- protected void startService() throws Exception
- {
- if (portalDeployer != null)
- {
- // Create factory
- factory = new PortalWebAppFactory(server);
- portalDeployer.addDeploymentListener(this);
- }
- else
- {
- throw new Exception ("PortalDeployer not present");
- }
- }
-
- /** Stop listening to the deployer notifications. */
- protected void stopService() throws Exception
- {
- if (portalDeployer != null)
- {
- for (Iterator i = deployments.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- URL keyURL = (URL)entry.getKey();
- PortalWebApp pwa = (PortalWebApp)entry.getValue();
- i.remove();
- log.debug("Removing web application with URL " + keyURL);
- undeploy(pwa);
- }
- portalDeployer.removeDeploymentListener(this);
- factory = null;
- }
- }
-
- /** Perform the deploy notification. */
- protected abstract void deploy(PortalWebApp pwa);
-
- /** Perform the undeploy notification. */
- protected abstract void undeploy(PortalWebApp pwa);
-
-}