User: jules_gosnell
Date: 01/12/04 13:12:51
Modified: jetty/src/main/org/jboss/jetty
JBossWebApplicationContext.java Jetty.java
Log:
rationalisation and clean-up of ENC and AppContext code
Revision Changes Path
1.8 +117 -94
contrib/jetty/src/main/org/jboss/jetty/JBossWebApplicationContext.java
Index: JBossWebApplicationContext.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JBossWebApplicationContext.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JBossWebApplicationContext.java 2001/12/04 01:14:11 1.7
+++ JBossWebApplicationContext.java 2001/12/04 21:12:51 1.8
@@ -5,35 +5,27 @@
* See terms of license at gnu.org.
*/
-// $Id: JBossWebApplicationContext.java,v 1.7 2001/12/04 01:14:11 jules_gosnell Exp
$
+// $Id: JBossWebApplicationContext.java,v 1.8 2001/12/04 21:12:51 jules_gosnell Exp
$
// A Jetty HttpServer with the interface expected by JBoss'
// J2EEDeployer...
package org.jboss.jetty;
+import java.io.FileNotFoundException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import javax.xml.parsers.DocumentBuilder;
import org.apache.log4j.Category;
import org.jboss.web.AbstractWebContainer.WebDescriptorParser;
import org.jboss.web.WebApplication;
+import org.mortbay.http.ContextLoader;
import org.mortbay.http.HttpServer;
+import org.mortbay.http.handler.SecurityHandler;
import org.mortbay.jetty.servlet.WebApplicationContext;
+import org.mortbay.util.Resource;
import org.w3c.dom.Element;
-import org.mortbay.http.handler.SecurityHandler;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.jboss.security.RealmMapping;
-import org.jboss.security.SimplePrincipal;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SubjectSecurityManager;
-
-import org.mortbay.http.UserPrincipal;
-import org.mortbay.http.UserRealm;
-
-import org.mortbay.http.ContextLoader;
-
public class
JBossWebApplicationContext
extends WebApplicationContext
@@ -41,44 +33,22 @@
Category _log;
WebDescriptorParser _descriptorParser;
WebApplication _webApp;
+ DocumentBuilder _parser;
public
JBossWebApplicationContext(HttpServer httpServer,
String contextPathSpec,
Category log,
WebDescriptorParser descriptorParser,
- WebApplication webApp)
+ WebApplication webApp,
+ DocumentBuilder parser)
{
super(httpServer, contextPathSpec);
_log = log;
_descriptorParser = descriptorParser;
_webApp = webApp;
-
- // try
- // {
- // initClassLoader();
- // }
- // catch (Exception e)
- // {
- // _log.error("ERROR: BAD CLASSLOADER - ", e);
- // }
- //
- // ClassLoader loader = getClassLoader();
- //
- // // sanity check - the classloader with which we are called
- // // (i.e. the one that Jetty has used for the webapps context)
- // // should be either the one we specified, or a descendent of it.
- // {
- // ClassLoader cl = loader;
- // while (cl!=null && cl!=_webApp.getClassLoader())
- // cl=cl.getParent();
- //
- // if (cl==null)
- // _log.warn("WARNING: WebApp Context's ClassLoader is of incorrect
descent:"+loader);
- // else
- // _log.info("WebApp Context's ClassLoader is of correct
descent:"+loader);
- // }
+ _parser = parser;
}
/* ------------------------------------------------------------ */
@@ -95,31 +65,6 @@
public void start()
throws Exception
{
- // ClassLoader loader = getHttpContext().getClassLoader();
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- // Thread.currentThread().setContextClassLoader(loader);
-
- // sanity check - the classloader with which we are called
- // (i.e. the one that Jetty has used for the webapps context)
- // should be either the one we specified, or a descendent of it.
-
- {
- ClassLoader cl = loader;
- while (cl!=null && cl!=_webApp.getClassLoader())
- cl=cl.getParent();
-
- if (cl==null)
- _log.warn("WARNING: WebApp Context's ClassLoader is of incorrect
descent:"+loader);
- // else
- // _log.info("WebApp Context's ClassLoader is of correct
descent:"+loader);
- }
-
- // Parse descriptors and set up the JNDI environment
- // Element webAppDD = _webApp.getWebApp();
- // Element jbossDD = _webApp.getJbossWeb();
- // _descriptorParser.parseWebAppDescriptors(loader, webAppDD, jbossDD);
-
// Add the JBoss security realm
String realmName = getRealm();
if (realmName!=null)
@@ -171,14 +116,6 @@
super.initWebXmlElement(element, node);
}
- // public boolean
- // handle(org.mortbay.http.HttpRequest request, org.mortbay.http.HttpResponse
response)
- // throws org.mortbay.http.HttpException, java.io.IOException
- // {
- // Thread.currentThread().setContextClassLoader(getClassLoader());
- // return super.handle(request, response);
- // }
-
// hack our class loader to be Java2 compliant - i.e. always
// delegate upwards before looking locally. This will be changed to
// a non-compliant strategy later when JBoss' new ClassLoader is
@@ -197,44 +134,101 @@
// copy our superclass' version of this, but ensure that servlet
// api and jasper jars are appended to it...
- public String getFileClassPath()
- throws IllegalStateException
+ public String
+ getFileClassPath()
{
- ClassLoader loader = getClassLoader();
- if (loader==null)
- throw new IllegalStateException("Context classloader not initialized");
-
String separator=System.getProperty("path.separator");
+
+ String classpath="";
+ for (ClassLoader cl=getClassLoader();
+ cl.getParent()!=null;
+ cl=cl.getParent())
+ {
+ if (cl instanceof URLClassLoader)
+ {
+ URL[] urls=((URLClassLoader)cl).getURLs();
+ for (int i=0; i<urls.length; i++)
+ {
+ URL url=urls[i];
+ if (url.getProtocol().equals("file"))
+ classpath+=(classpath.length()==0?"":separator)+url.getPath();
+ else
+ _log.warn("WARNING: non-file URL encountered in ClassLoader - jsp
compilation may fail");
+ }
+ }
+ else
+ {
+ _log.warn("WARNING: non URLClassLoader("+cl+") encountered - jsp compilation
may fail");
+ }
+ }
- String fileClassPath =
- ((loader instanceof ContextLoader)
- ? ((ContextLoader)loader).getFileClassPath()
- : getClassPath())+separator+System.getProperty("java.class.path");
+ // we should report non-file urls and non URLClassLoader
+ // ClassLoaders here...
+ // and now - let's hack a bit...
try
{
- String jar=findJarByResource("javax/servlet/resources/web-app_2_3.dtd");
- fileClassPath+=separator+jar;
+ String jar=findJarByResource("javax/servlet/resources/web-app_2_3.dtd");
+ classpath+=separator+jar;
}
catch (Exception e)
{
- _log.warn("WARNING: could not find Servlet API jar", e);
+ _log.warn("WARNING: could not find Servlet API jar", e);
}
try
{
- String jar=findJarByResource("org/apache/jasper/resources/jsp12.dtd");
- fileClassPath+=separator+jar;
+ String jar=findJarByResource("org/apache/jasper/resources/jsp12.dtd");
+ classpath+=separator+jar;
}
catch (Exception e)
{
- _log.warn("WARNING: could not find Jasper jar", e);
+ _log.warn("WARNING: could not find Jasper jar", e);
}
- _log.info("default JSP CLASSPATH:"+fileClassPath);
- return fileClassPath;
+ _log.info("default JSP CLASSPATH:"+classpath);
+
+ return classpath;
}
+ // public String getFileClassPath()
+ // throws IllegalStateException
+ // {
+ // ClassLoader loader = getClassLoader();
+ // if (loader==null)
+ // throw new IllegalStateException("Context classloader not initialized");
+ //
+ // String separator=System.getProperty("path.separator");
+ //
+ // String fileClassPath =
+ // ((loader instanceof ContextLoader)
+ // ? ((ContextLoader)loader).getFileClassPath()
+ // : getClassPath())+separator+System.getProperty("java.class.path");
+ //
+ // try
+ // {
+ // String
jar=findJarByResource("javax/servlet/resources/web-app_2_3.dtd");
+ // fileClassPath+=separator+jar;
+ // }
+ // catch (Exception e)
+ // {
+ // _log.warn("WARNING: could not find Servlet API jar", e);
+ // }
+ //
+ // try
+ // {
+ // String jar=findJarByResource("org/apache/jasper/resources/jsp12.dtd");
+ // fileClassPath+=separator+jar;
+ // }
+ // catch (Exception e)
+ // {
+ // _log.warn("WARNING: could not find Jasper jar", e);
+ // }
+ //
+ // _log.info("default JSP CLASSPATH:"+fileClassPath);
+ // return fileClassPath;
+ // }
+
// given a resource name, find the jar file that contains that resource...
protected String
findJarByResource(String resource)
@@ -248,7 +242,36 @@
protected void
setUpENC()
{
- _log.info("CLASSLOADER: "+Thread.currentThread().getContextClassLoader());
+ _webApp.setClassLoader(Thread.currentThread().getContextClassLoader());
+ _webApp.setName(getDisplayName());
+ _webApp.setAppData(this);
+
+ try
+ {
+ // MANDATORY - web.xml
+ Resource web=getResource("/WEB-INF/web.xml");
+ _webApp.setWebApp(_parser.parse(web.getInputStream()).getDocumentElement());
+ }
+ catch (Exception e)
+ {
+ _log.error("ERROR: problem locating web.xml");
+ }
+
+ try
+ {
+ // OPTIONAL - jboss-web.xml
+ Resource jbossWeb=getResource("/WEB-INF/jboss-web.xml");
+ if (jbossWeb!=null)
+
_webApp.setJbossWeb(_parser.parse(jbossWeb.getInputStream()).getDocumentElement());
+ }
+ catch (FileNotFoundException e)
+ {
+ _log.info("no jboss-web.xml found");
+ }
+ catch (Exception e)
+ {
+ _log.error("ERROR: problem locating jboss-web.xml");
+ }
try
{
1.28 +25 -48 contrib/jetty/src/main/org/jboss/jetty/Jetty.java
Index: Jetty.java
===================================================================
RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/Jetty.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Jetty.java 2001/12/04 01:14:11 1.27
+++ Jetty.java 2001/12/04 21:12:51 1.28
@@ -5,15 +5,13 @@
* See terms of license at gnu.org.
*/
-// $Id: Jetty.java,v 1.27 2001/12/04 01:14:11 jules_gosnell Exp $
+// $Id: Jetty.java,v 1.28 2001/12/04 21:12:51 jules_gosnell Exp $
// A Jetty HttpServer with the interface expected by JBoss'
// J2EEDeployer...
package org.jboss.jetty;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.net.URL;
import java.util.Hashtable;
import javax.xml.parsers.DocumentBuilder;
@@ -22,16 +20,14 @@
import org.jboss.deployment.DeploymentException;
import org.jboss.web.AbstractWebContainer.WebDescriptorParser;
import org.jboss.web.WebApplication;
-import org.mortbay.http.HttpHandler;
import org.mortbay.jetty.servlet.WebApplicationContext;
-import org.mortbay.util.Resource;
/**
* <description>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.27 $
+ * @version $Revision: 1.28 $
*
* <p><b>Revisions:</b>
*
@@ -47,8 +43,9 @@
public class Jetty
extends org.mortbay.jetty.Server
{
- Category _log;
- JettyResolver _resolver;
+ static DocumentBuilderFactory _factory=DocumentBuilderFactory.newInstance();
+ DocumentBuilder _parser;
+ Category _log;
Jetty(Category log)
{
@@ -56,18 +53,30 @@
_log=log;
// resolver should be populated from a configuration file.
- _resolver=new JettyResolver(_log);
+ JettyResolver resolver=new JettyResolver(_log);
// populate dtd resulver
URL stdWeb22=findResourceInJar("javax/servlet/resources/web-app_2_2.dtd");
- _resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
stdWeb22);
+ resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
stdWeb22);
URL stdWeb23=findResourceInJar("javax/servlet/resources/web-app_2_3.dtd");
- _resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
stdWeb23);
+ resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
stdWeb23);
URL jbossWeb=findResourceInJar("org/jboss/metadata/jboss-web.dtd");
- _resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb);
- _resolver.put("-//JBoss//DTD Web Application 2.2//EN", jbossWeb);
+ resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb);
+ resolver.put("-//JBoss//DTD Web Application 2.2//EN", jbossWeb);
+ try
+ {
+ _parser=_factory.newDocumentBuilder();
+ _parser.setEntityResolver(resolver);
+ // _parser.setErrorHandler();
+ }
+ catch (Exception e)
+ {
+ _log.error("ERROR: problem building descriptor parser", e);
+ }
+
+
// check support for JSP compilation...
if
(findResourceInJar("com/sun/tools/javac/v8/resources/javac.properties")==null)
_log.warn("WARNING: JSP compilation requires $JAVA_HOME/lib/tools.jar on your
JBOSS_CLASSPATH");
@@ -181,46 +190,14 @@
if (getContext(null, contextPath, 0)!=null)
_log.warn("WARNING: A WebApplication is already deployed in context
'"+contextPath+"' - proceed at your own risk.");
- ClassLoader cl=Thread.currentThread().getContextClassLoader();
- // Greg now retrieves this for himself...
- // app.setClassLoader(cl);
- wa.setClassLoader(cl);
-
// deploy the WebApp
- WebApplicationContext app=new JBossWebApplicationContext(this, contextPath,
_log, descriptorParser, wa);
- // Use the same ClassLoader as JBoss - this allows optimisation
- // of calls to EJBs...
- wa.setAppData(app);
+ WebApplicationContext app=new JBossWebApplicationContext(this, contextPath,
_log, descriptorParser, wa, _parser);
- addContext(null, app);
+ String virtualHost=null;
+ addContext(virtualHost, app);
String fixedWarUrl=warUrl+(warUrl.endsWith("/")?"":"/");
app.initialize(fixedWarUrl, getWebDefault(), getUnpackWars());
-
- wa.setName(app.getDisplayName());
-
- DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
- DocumentBuilder parser=factory.newDocumentBuilder();
-
- // locate and register $JETTY_HOME//etc/dtd/web.dtd
- // parser.setErrorHandler();
- parser.setEntityResolver(_resolver);
-
- // MANDATORY - web.xml
- Resource web=app.getResource("/WEB-INF/web.xml");
- wa.setWebApp(parser.parse(web.getInputStream()).getDocumentElement());
-
- try
- {
- // OPTIONAL - jboss-web.xml
- Resource jbossWeb=app.getResource("/WEB-INF/jboss-web.xml");
- if (jbossWeb!=null)
- wa.setJbossWeb(parser.parse(jbossWeb.getInputStream()).getDocumentElement());
- }
- catch (FileNotFoundException e)
- {
- _log.info("no jboss-web.xml found");
- }
// finally start the app
app.start();
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development