User: starksm
Date: 02/04/04 00:26:21
Modified: src/main/org/jboss/web Tag: Branch_2_4
AbstractWebContainer.java WebApplication.java
Log:
Add support for setting the context-root of a standalone war and support
for setting the virtual host of the war.
Revision Changes Path
No revision
No revision
1.4.4.10 +162 -40 jboss/src/main/org/jboss/web/AbstractWebContainer.java
Index: AbstractWebContainer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/AbstractWebContainer.java,v
retrieving revision 1.4.4.9
retrieving revision 1.4.4.10
diff -u -r1.4.4.9 -r1.4.4.10
--- AbstractWebContainer.java 4 Dec 2001 18:40:58 -0000 1.4.4.9
+++ AbstractWebContainer.java 4 Apr 2002 08:26:20 -0000 1.4.4.10
@@ -1,5 +1,10 @@
package org.jboss.web;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -12,6 +17,7 @@
import javax.naming.Name;
import javax.naming.NameNotFoundException;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.jboss.deployment.DeploymentException;
@@ -20,6 +26,7 @@
import org.jboss.metadata.ResourceEnvRefMetaData;
import org.jboss.metadata.ResourceRefMetaData;
import org.jboss.metadata.WebMetaData;
+import org.jboss.metadata.XmlFileLoader;
import org.jboss.naming.Util;
import org.jboss.security.plugins.NullSecurityManager;
import org.jboss.util.ServiceMBeanSupport;
@@ -35,7 +42,8 @@
- ejb-ref
- security-domain
-Subclasses need to implement the {@link #performDeploy(String, String,
WebDescriptorParser) performDeploy()}
+Subclasses need to implement the {@link #performDeploy(WebApplication, String,
+ WebDescriptorParser) performDeploy()}
and {@link #performUndeploy(String) performUndeploy()} methods to perform the
container specific steps and return the web application info required by the
AbstractWebContainer class.
@@ -113,7 +121,7 @@
@see org.jboss.security.SecurityAssociation;
@author [EMAIL PROTECTED]
-@version $Revision: 1.4.4.9 $
+@version $Revision: 1.4.4.10 $
*/
public abstract class AbstractWebContainer extends ServiceMBeanSupport implements
AbstractWebContainerMBean
{
@@ -140,7 +148,7 @@
@param jbossWeb, the root element of thw jboss-web.xml descriptor. May be
null
to indicate that no jboss-web.xml descriptor exists.
*/
- public void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception;
+ public void parseWebAppDescriptors(ClassLoader loader, WebMetaData
metaData) throws Exception;
}
/** A mapping of deployed warUrl strings to the WebApplication object */
@@ -168,7 +176,7 @@
thread.setContextClassLoader(appClassLoader);
The subclass performDeploy() implementation needs to invoke
- webAppParser.parseWebAppDescriptors(loader, webApp, jbossWeb) to have the
+ webAppParser.parseWebAppDescriptors(loader, metaData) to have the
JNDI java:comp/env namespace setup before any web app component can access
this namespace.
@@ -177,34 +185,37 @@
if war was is not being deployed as part of an enterprise application.
@param warUrl, The string for the URL of the web application war.
*/
- public synchronized void deploy(String ctxPath, String warUrl) throws
DeploymentException
- {
- Thread thread = Thread.currentThread();
- ClassLoader appClassLoader = thread.getContextClassLoader();
- try
- {
- // Create a classloader for the war to ensure a unique ENC
- URL[] empty = {};
- URLClassLoader warLoader = URLClassLoader.newInstance(empty,
appClassLoader);
- thread.setContextClassLoader(warLoader);
- WebDescriptorParser webAppParser = new DescriptorParser();
- WebApplication warInfo = performDeploy(ctxPath, warUrl, webAppParser);
- deploymentMap.put(warUrl, warInfo);
- }
- catch(DeploymentException e)
- {
- throw (DeploymentException) e.fillInStackTrace();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw new DeploymentException("Error during deploy", e);
- }
- finally
- {
- thread.setContextClassLoader(appClassLoader);
- }
- }
+ public synchronized void deploy(String ctxPath, String warUrl) throws
DeploymentException
+ {
+ Thread thread = Thread.currentThread();
+ ClassLoader appClassLoader = thread.getContextClassLoader();
+ try
+ {
+ // Create a classloader for the war to ensure a unique ENC
+ URL[] empty = {};
+ URLClassLoader warLoader = URLClassLoader.newInstance(empty,
appClassLoader);
+ thread.setContextClassLoader(warLoader);
+ WebDescriptorParser webAppParser = new DescriptorParser();
+ // Parse the web.xml and jboss-web.xml descriptors
+ WebMetaData metaData = parseMetaData(ctxPath, warUrl);
+ WebApplication warInfo = new WebApplication();
+ warInfo.setMetaData(metaData);
+ performDeploy(warInfo, warUrl, webAppParser);
+ deploymentMap.put(warUrl, warInfo);
+ }
+ catch(DeploymentException e)
+ {
+ throw (DeploymentException) e.fillInStackTrace();
+ }
+ catch(Exception e)
+ {
+ throw new DeploymentException("Error during deploy", e);
+ }
+ finally
+ {
+ thread.setContextClassLoader(appClassLoader);
+ }
+ }
/** This method is called by the deploy() method template and must be overriden
by
subclasses to perform the web container specific deployment steps.
@@ -219,7 +230,7 @@
@return WebApplication, the web application information required by the
AbstractWebContainer class to track the war deployment status.
*/
- protected abstract WebApplication performDeploy(String ctxPath, String warUrl,
+ protected abstract void performDeploy(WebApplication webApp, String warUrl,
WebDescriptorParser webAppParser) throws Exception;
/** A template pattern implementation of the undeploy() method. This method
@@ -299,13 +310,9 @@
@param jbossWeb, the root element of thw jboss-web.xml descriptor. May be null
to indicate that no jboss-web.xml descriptor exists.
*/
- protected void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception
+ protected void parseWebAppDescriptors(ClassLoader loader, WebMetaData metaData)
throws Exception
{
log.debug("AbstractWebContainer.parseWebAppDescriptors, Begin");
- WebMetaData metaData = new WebMetaData();
- metaData.importXml(webApp);
- if( jbossWeb != null )
- metaData.importXml(jbossWeb);
InitialContext iniCtx = new InitialContext();
Context envCtx = null;
@@ -461,14 +468,129 @@
}
}
+ /** This method creates a context-root string from either the
+ WEB-INF/jboss-web.xml context-root element is one exists, or the
+ filename portion of the warURL. It is called if the DeploymentInfo
+ webContext value is null which indicates a standalone war deployment.
+ A war name of ROOT.war is handled as a special case of a war that
+ should be installed as the default web context.
+ */
+ protected WebMetaData parseMetaData(String ctxPath, String warUrl)
+ throws MalformedURLException
+ {
+ WebMetaData metaData = new WebMetaData();
+ URL warURL = new URL(warUrl);
+ InputStream jbossWebIS = null;
+ InputStream webIS = null;
+
+ try
+ {
+ // See if the warUrl is a directory
+ File warDir = new File(warURL.getFile());
+ if( warURL.getProtocol().equals("file") && warDir.isDirectory() == true )
+ {
+ File webDD = new File(warDir, "WEB-INF/web.xml");
+ if( webDD.exists() == true )
+ webIS = new FileInputStream(webDD);
+ File jbossWebDD = new File(warDir, "WEB-INF/jboss-web.xml");
+ if( jbossWebDD.exists() == true )
+ jbossWebIS = new FileInputStream(jbossWebDD);
+ }
+ else
+ {
+ // First check for a WEB-INF/web.xml and a WEB-INF/jboss-web.xml
+ InputStream warIS = warURL.openStream();
+ java.util.zip.ZipInputStream zipIS = new
java.util.zip.ZipInputStream(warIS);
+ java.util.zip.ZipEntry entry;
+ byte[] buffer = new byte[512];
+ int bytes;
+ while( (entry = zipIS.getNextEntry()) != null )
+ {
+ if( entry.getName().equals("WEB-INF/web.xml") )
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ while( (bytes = zipIS.read(buffer)) > 0 )
+ {
+ baos.write(buffer, 0, bytes);
+ }
+ webIS = new ByteArrayInputStream(baos.toByteArray());
+ }
+ else if( entry.getName().equals("WEB-INF/jboss-web.xml") )
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ while( (bytes = zipIS.read(buffer)) > 0 )
+ {
+ baos.write(buffer, 0, bytes);
+ }
+ jbossWebIS = new ByteArrayInputStream(baos.toByteArray());
+ }
+ }
+ zipIS.close();
+ }
+
+ try
+ {
+ XmlFileLoader xmlLoader = new XmlFileLoader();
+ if( webIS != null )
+ {
+ Document webDoc = xmlLoader.getDocument(webIS, "WEB-INF/web.xml");
+ Element web = webDoc.getDocumentElement();
+ metaData.importXml(web);
+ }
+ if( jbossWebIS != null )
+ {
+ Document jbossWebDoc = xmlLoader.getDocument(jbossWebIS,
"WEB-INF/jboss-web.xml");
+ Element jbossWeb = jbossWebDoc.getDocumentElement();
+ metaData.importXml(jbossWeb);
+ }
+ }
+ catch(Exception e)
+ {
+ }
+
+ }
+ catch(Exception e)
+ {
+ log.trace("Failed to parse descriptors for war("+warUrl+")", e);
+ }
+
+ String webContext = ctxPath;
+ if( webContext == null )
+ webContext = metaData.getContextRoot();
+ if( webContext == null )
+ {
+ // Build the context from the war name, strip the .war suffix
+ webContext = warUrl;
+ webContext = webContext.replace('\\', '/');
+ if( webContext.endsWith("/") )
+ webContext = webContext.substring(0, webContext.length()-1);
+ int prefix = webContext.lastIndexOf('/');
+ if( prefix > 0 )
+ webContext = webContext.substring(prefix+1);
+ int suffix = webContext.indexOf(".war");
+ if( suffix > 0 )
+ webContext = webContext.substring(0, suffix);
+ // Special hanling for a war file named ROOT
+ if( webContext.equals("ROOT") )
+ webContext = "";
+ }
+
+ // Servlet containers are anal about the web context starting with '/'
+ if( webContext.length() > 0 && webContext.charAt(0) != '/' )
+ webContext = "/" + webContext;
+ metaData.setContextRoot(webContext);
+
+ return metaData;
+ }
+
/** An inner class that maps the WebDescriptorParser.parseWebAppDescriptors()
onto the protected parseWebAppDescriptors() AbstractWebContainer method.
*/
private class DescriptorParser implements WebDescriptorParser
{
- public void parseWebAppDescriptors(ClassLoader loader, Element webApp,
Element jbossWeb) throws Exception
+ public void parseWebAppDescriptors(ClassLoader loader, WebMetaData
metaData) throws Exception
{
- AbstractWebContainer.this.parseWebAppDescriptors(loader, webApp,
jbossWeb);
+ AbstractWebContainer.this.parseWebAppDescriptors(loader, metaData);
}
}
1.2.6.1 +22 -35 jboss/src/main/org/jboss/web/WebApplication.java
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/WebApplication.java,v
retrieving revision 1.2
retrieving revision 1.2.6.1
diff -u -r1.2 -r1.2.6.1
--- WebApplication.java 10 May 2001 04:09:36 -0000 1.2
+++ WebApplication.java 4 Apr 2002 08:26:21 -0000 1.2.6.1
@@ -11,12 +11,14 @@
import org.w3c.dom.Element;
+import org.jboss.metadata.WebMetaData;
+
/** A WebApplication represents the information for a war deployment.
@see AbstractWebContainer
@author [EMAIL PROTECTED]
-@version $Revision: 1.2 $
+@version $Revision: 1.2.6.1 $
*/
public class WebApplication
{
@@ -26,10 +28,8 @@
String name = "";
/** URL where this application was deployed from */
URL url;
- /** The root element of thw web-app.xml descriptor. */
- Element webApp;
- /** The root element of thw jboss-web.xml descriptor. */
- Element jbossWeb;
+ /** The web app metadata from the web.xml and jboss-web.xml descriptors */
+ WebMetaData metaData;
/** Arbitary data object for storing application specific data */
Object data;
@@ -102,36 +102,6 @@
this.url = url;
}
- /** Getter for property webApp.
- * @return Value of property webApp.
- */
- public Element getWebApp()
- {
- return webApp;
- }
- /** Setter for property webApp.
- * @param webApp New value of property webApp.
- */
- public void setWebApp(Element webApp)
- {
- this.webApp = webApp;
- }
-
- /** Getter for property jbossWeb.
- * @return Value of property jbossWeb.
- */
- public Element getJbossWeb()
- {
- return jbossWeb;
- }
- /** Setter for property jbossWeb.
- * @param jbossWeb New value of property jbossWeb.
- */
- public void setJbossWeb(Element jbossWeb)
- {
- this.jbossWeb = jbossWeb;
- }
-
public Object getAppData()
{
return data;
@@ -154,4 +124,21 @@
buffer.append('}');
return buffer.toString();
}
+
+ /** Getter for property metaData.
+ * @return Value of property metaData.
+ */
+ public WebMetaData getMetaData()
+ {
+ return metaData;
+ }
+
+ /** Setter for property metaData.
+ * @param metaData New value of property metaData.
+ */
+ public void setMetaData(WebMetaData metaData)
+ {
+ this.metaData = metaData;
+ }
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development