User: jules_gosnell Date: 01/11/21 15:13:01 Modified: jetty/src/main/org/jboss/jetty JBossLogSink.java JBossUserRealm.java Jetty.java JettyMBean.java JettyResolver.java JettyService.java SetupHandler.java Added: jetty/src/main/org/jboss/jetty JBossWebApplicationContext.java Log: my first cut of the JBoss3/Jetty4 integration - enjoy ! Revision Changes Path 1.7 +9 -8 contrib/jetty/src/main/org/jboss/jetty/JBossLogSink.java Index: JBossLogSink.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JBossLogSink.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JBossLogSink.java 2001/10/03 22:27:02 1.6 +++ JBossLogSink.java 2001/11/21 23:13:01 1.7 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: JBossLogSink.java,v 1.6 2001/10/03 22:27:02 jules_gosnell Exp $ +// $Id: JBossLogSink.java,v 1.7 2001/11/21 23:13:01 jules_gosnell Exp $ package org.jboss.jetty; @@ -22,7 +22,7 @@ * This class bidges the API between Jetty and Log4J. * * @author <a href="mailto:">Jules Gosnell</a> - * @version $Id: JBossLogSink.java,v 1.6 2001/10/03 22:27:02 jules_gosnell Exp $ + * @version $Id: JBossLogSink.java,v 1.7 2001/11/21 23:13:01 jules_gosnell Exp $ * @since 1.0 * @see org.mortbay.util.LogSink */ @@ -34,7 +34,7 @@ HashMap _dispatch = new HashMap(); interface Logger {void log(String s);} - + public JBossLogSink() { @@ -65,6 +65,7 @@ throws InterruptedException { _started = false; + //_log=null; } public void @@ -101,10 +102,10 @@ { // is it possible to translate these into JBoss logging options...? } - + public void setOptions(String logOptions) - { + { // setOptions((logOptions.indexOf(OPT_TIMESTAMP) >= 0), // (logOptions.indexOf(OPT_LABEL) >= 0), // (logOptions.indexOf(OPT_TAG) >= 0), @@ -112,7 +113,7 @@ // (logOptions.indexOf(OPT_STACKTRACE) >= 0), // (logOptions.indexOf(OPT_ONELINE) >= 0)); } - + public String getOptions() { @@ -125,7 +126,7 @@ // (_logOneLine?"O":""); return ""; } - + /* ------------------------------------------------------------ */ /** Log a message. * This method formats the log information as a string and calls @@ -158,7 +159,7 @@ /** Log a message. * The formatted log string is written to the log sink. The default * implementation writes the message to a PrintWriter. - * @param formattedLog + * @param formattedLog */ public synchronized void log(String formattedLog) 1.8 +131 -79 contrib/jetty/src/main/org/jboss/jetty/JBossUserRealm.java Index: JBossUserRealm.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JBossUserRealm.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JBossUserRealm.java 2001/09/17 23:07:47 1.7 +++ JBossUserRealm.java 2001/11/21 23:13:01 1.8 @@ -5,13 +5,17 @@ * See terms of license at gnu.org. */ -// $Id: JBossUserRealm.java,v 1.7 2001/09/17 23:07:47 jules_gosnell Exp $ +// $Id: JBossUserRealm.java,v 1.8 2001/11/21 23:13:01 jules_gosnell Exp $ package org.jboss.jetty; -import java.util.HashSet; +import java.util.Collections; +import java.util.HashMap; +import java.util.Set; +import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import javax.security.auth.Subject; import org.apache.log4j.Category; import org.jboss.security.EJBSecurityManager; import org.jboss.security.RealmMapping; @@ -25,106 +29,103 @@ /** An implementation of UserRealm that integrates with the JBossSX * security manager associted with the web application. * @author [EMAIL PROTECTED] - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ + +// TODO + public class JBossUserRealm implements UserRealm { - private String _realmName; - private Category _log; - - //---------------------------------------- - - class User - extends SimplePrincipal - implements UserPrincipal - { - HttpRequest _request; - - User(String name, HttpRequest request) + class JBossUserPrincipal + extends SimplePrincipal // The JBoss API + implements UserPrincipal // The Jetty API + { + JBossUserPrincipal(String name) { super(name); - _request = request; + _log.info("Security- created JBossUserRealm::JBossUserPrincipal: "+name); } - + public boolean - authenticate(String password) + equals(Object o) { - boolean authenticated = false; - String username = this.getName(); // needs disambiguation + if (o==this) + return true; - _log.info("Authenticating access, username: " + username/* + " " + _request*/); - - try - { - // Get the JBoss security manager from the ENC context - InitialContext iniCtx = new InitialContext(); - EJBSecurityManager securityMgr = (EJBSecurityManager) iniCtx.lookup("java:comp/env/security/securityMgr"); + if (o==null) + return false; - if(securityMgr.isValid(this, password)) - { - authenticated = true; - _request.setAttribute(UserPrincipal.__ATTR, this); + if (getClass()!=o.getClass()) + return false; - _log.info("User: "+username+" is authenticated"); + String myName =this.getName(); + String yourName=((JBossUserPrincipal)o).getName(); - SecurityAssociation.setPrincipal(this); - SecurityAssociation.setCredential(password.toCharArray()); - /* - if( useJAAS == true && securityMgr instanceof SubjectSecurityManager ) - { - SubjectSecurityManager subjectMgr = (SubjectSecurityManager) securityMgr; - Subject subject = subjectMgr.getActiveSubject(); - _request.setAttribute(subjectAttributeName, subject); - } - */ - } - else + if (myName==null && yourName==null) + return true; + + if (myName!=null && myName.equals(yourName)) + return true; + + return false; + } + + public boolean + authenticate(String password, HttpRequest request) + { + boolean authenticated = false; + String userName = this.getName(); // needs disambiguation because our outer class.... + + if (password==null) + password=""; + + char[] passwordChars = password.toCharArray(); + _log.info("Security- authenticating: Name:"+userName+" Password:"+password); + if(_securityMgr!=null &&_securityMgr.isValid(this, passwordChars)) + { + _log.info("Security- JBossUserPrincipal: "+userName+" is authenticated"); + SecurityAssociation.setPrincipal(this); + SecurityAssociation.setCredential(passwordChars); + authenticated=true; + + // This doesn't mean anything to Jetty - but may to some + // Servlets - confirm later... + if (_subjectMgr!=null) { - _log.info("User: "+username+" is NOT authenticated"); + Subject subject = _subjectMgr.getActiveSubject(); + request.setAttribute(_subjectAttributeName, subject); } + } - catch(NamingException e) + else { - _log.error("Error during authenticate", e); + _log.warn("WARNING: Security- JBossUserPrincipal: "+userName+" is NOT authenticated"); } - + return authenticated; } - + public boolean isUserInRole(String role) { boolean isUserInRole = false; - String username = this.getName(); + String userName = this.getName(); - _log.info("Authorizing access, username: " + username/* + " " + _request*/); - - try + Set requiredRoles = Collections.singleton(new SimplePrincipal(role)); + if(_realmMapping!=null && _realmMapping.doesUserHaveRole(this, requiredRoles)) { - // Get the JBoss security manager from the ENC context - InitialContext iniCtx = new InitialContext(); - RealmMapping securityMgr = (RealmMapping) iniCtx.lookup("java:comp/env/security/realmMapping"); - HashSet requiredRoles = new HashSet(); - - requiredRoles.add(new SimplePrincipal(role)); - if(securityMgr.doesUserHaveRole(this, requiredRoles)) - { - isUserInRole = true; - _log.info("User: "+username+" is authorized"); - } - else - { - _log.warn("User: "+username+" is NOT authorized, requiredRoles="+requiredRoles); - } + _log.info("Security- JBossUserPrincipal: "+userName+" is in Role: "+role); + isUserInRole = true; } - catch(NamingException e) + else { - _log.error("Error during authorization", e); + _log.warn("WARNING: Security- JBossUserPrincipal: "+userName+" is NOT in Role: "+role); } + return isUserInRole; } - + public UserRealm getUserRealm() { @@ -132,14 +133,37 @@ } } - //---------------------------------------- - + private Category _log=Category.getInstance("Jetty"); + private String _realmName; + private EJBSecurityManager _securityMgr; + private RealmMapping _realmMapping; + private HashMap _users = new HashMap(); + private String _subjectAttributeName = "j_subject"; // needs accessors - TODO + private SubjectSecurityManager _subjectMgr = null; + public - JBossUserRealm(Category log, String realmName) + JBossUserRealm(String realmName) { - _log = log; _realmName = realmName; - _log.info("+++ Created JBossUserRealm, realmName="+_realmName); + _log.info("Security- created JBossUserRealm: "+_realmName); + + try + { + // can I get away with just doing this lookup once per webapp ? + InitialContext iniCtx = new InitialContext(); + // do we need the 'java:comp/env' prefix ? TODO + Context securityCtx =(Context) iniCtx.lookup("java:comp/env/security"); + _securityMgr =(EJBSecurityManager) securityCtx.lookup("securityMgr"); + _realmMapping =(RealmMapping) securityCtx.lookup("realmMapping"); + iniCtx=null; + + if (_securityMgr instanceof SubjectSecurityManager) + _subjectMgr = (SubjectSecurityManager) _securityMgr; + } + catch (NamingException e) + { + _log.error("ERROR: Security- Could not create initial Context", e); + } } public String @@ -148,10 +172,38 @@ return _realmName; } + //---------------------------------------- + + // this is going to cause contention - TODO + private synchronized JBossUserPrincipal + ensureUser(String userName) + { + JBossUserPrincipal user = (JBossUserPrincipal)_users.get(userName); + + if (user==null) + { + user=new JBossUserPrincipal(userName); + _users.put(userName, user); + } + + return user; + } + public UserPrincipal - getUser(String username, HttpRequest request) + getUser(String userName) { - _log.info("+++ JBossUserRealm.getUser, username="+username); - return new User(username, request); + _log.info("Security- JBossUserPrincipal: "+userName); + return ensureUser(userName); } + + /** + * @deprecated + */ + public UserPrincipal + getUser(String userName, HttpRequest request) + { + return getUser(userName); + } + + //---------------------------------------- } 1.19 +43 -46 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Jetty.java 2001/09/23 19:42:32 1.18 +++ Jetty.java 2001/11/21 23:13:01 1.19 @@ -4,12 +4,12 @@ * Distributable under GPL license. * See terms of license at gnu.org. */ - -// $Id: Jetty.java,v 1.18 2001/09/23 19:42:32 jules_gosnell Exp $ +// $Id: Jetty.java,v 1.19 2001/11/21 23:13:01 jules_gosnell Exp $ + // A Jetty HttpServer with the interface expected by JBoss' // J2EEDeployer... - + package org.jboss.jetty; import java.io.FileNotFoundException; @@ -24,13 +24,13 @@ import org.mortbay.http.HttpHandler; import org.mortbay.jetty.servlet.WebApplicationContext; import org.mortbay.util.Resource; - + public class Jetty extends org.mortbay.jetty.Server { Category _log; JettyResolver _resolver; - + Jetty(Category log) { super(); @@ -38,11 +38,13 @@ // resolver should be populated from a configuration file. _resolver=new JettyResolver(_log); - - URL stdWeb=findResourceInJar("org.mortbay.http.HttpServer","org/mortbay/jetty/servlet/web.dtd"); - _resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", stdWeb); - - URL jbossWeb=findResourceInJar("org.jboss.web.AbstractWebContainer","org/jboss/metadata/jboss-web.dtd"); + + URL stdWeb22=findResourceInJar("javax/servlet/resources/web-app_2_2.dtd"); + _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); + + 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); } @@ -75,7 +77,7 @@ { _unpackWars=unpackWars; } - + public synchronized boolean getUnpackWars() { @@ -93,7 +95,7 @@ { _webDefault=webDefault; } - + public synchronized String getWebDefault() { @@ -103,15 +105,15 @@ //---------------------------------------- // configuration property //---------------------------------------- - + String _configuration=null; - + public synchronized void setConfiguration(String configUrl) { if (configUrl==null) return; - + try { _log.info("loading config: "+configUrl); @@ -121,16 +123,16 @@ } catch (Exception e) { - _log.error("problem loading configuration: "+configUrl, e); + _log.error("ERROR: problem loading configuration: "+configUrl, e); } } - + public synchronized String getConfiguration() { return _configuration; } - + //---------------------------------------------------------------------------- // 'deploy' interface //---------------------------------------------------------------------------- @@ -152,21 +154,22 @@ 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 WebApplicationContext(this, contextPath); + 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); addContext(null, app); - // Use the same ClassLoader as JBoss - this allows optimisation - // of calls to EJBs... - ClassLoader cl=Thread.currentThread().getContextClassLoader(); - app.setClassLoader(cl); - wa.setClassLoader(cl); - String fixedWarUrl=warUrl+(warUrl.endsWith("/")?"":"/"); app.initialize(fixedWarUrl, getWebDefault(), getUnpackWars()); - + wa.setName(app.getDisplayName()); DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); @@ -175,11 +178,11 @@ // 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 @@ -192,15 +195,8 @@ _log.info("no jboss-web.xml found"); } - // Add a handler to perform the JBoss integration during start() - HttpHandler handler = new SetupHandler(_log, descriptorParser, wa); - app.addHandler(handler); - // finally - start the WebApp... + // finally start the app app.start(); - // Remove the handler - handler.stop(); - app.removeHandler(handler); - handler.destroy(); // keep track of deployed contexts for undeployment _deployed.put(warUrl, app); @@ -209,26 +205,27 @@ } catch (Exception e) { - _log.error("problem deploying "+warUrl+" to "+contextPath, e); + _log.error("ERROR: problem deploying "+warUrl+" to "+contextPath, e); throw new DeploymentException(e.getMessage()); } return wa; } - + public void undeploy(String warUrl) throws DeploymentException { // find the WebApp Context in the repository WebApplicationContext app = (WebApplicationContext)_deployed.get(warUrl); - + try { app.stop(); removeContext(app); - app.destroy(); + // app.destroy(); + app=null; _deployed.remove(warUrl); @@ -236,11 +233,11 @@ } catch (Exception e) { - _log.error("problem undeploying "+warUrl, e); + _log.error("ERROR: problem undeploying "+warUrl, e); throw new DeploymentException(e.getMessage()); } } - + public boolean isDeployed(String warUrl) { @@ -252,19 +249,19 @@ //---------------------------------------------------------------------------- public URL - findResourceInJar(String sibling, String name) + findResourceInJar(String name) { URL url=null; - + try { url=getClass().getClassLoader().getResource(name); } catch (Exception e) { - _log.error("Could not find resource: "+name, e); + _log.error("ERROR: Could not find resource: "+name, e); } - + return url; } } 1.5 +3 -3 contrib/jetty/src/main/org/jboss/jetty/JettyMBean.java Index: JettyMBean.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyMBean.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JettyMBean.java 2001/09/17 23:07:47 1.4 +++ JettyMBean.java 2001/11/21 23:13:01 1.5 @@ -13,10 +13,10 @@ import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.mortbay.jetty.jmx.HttpServerMBean; +import org.mortbay.jetty.jmx.JettyServerMBean; public class JettyMBean - extends HttpServerMBean + extends JettyServerMBean { public JettyMBean(Jetty jetty) throws MBeanException, InstanceNotFoundException 1.5 +8 -8 contrib/jetty/src/main/org/jboss/jetty/JettyResolver.java Index: JettyResolver.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyResolver.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JettyResolver.java 2001/09/18 23:06:49 1.4 +++ JettyResolver.java 2001/11/21 23:13:01 1.5 @@ -4,7 +4,7 @@ * Distributable under GPL license. * See terms of license at gnu.org. */ - + // $Id$ package org.jboss.jetty; @@ -22,27 +22,27 @@ // revisited. public class JettyResolver - implements EntityResolver + implements EntityResolver { protected Category _log; protected HashMap _map=new HashMap(); - + public JettyResolver(Category log) { _log=log; } - + public InputSource resolveEntity (String publicId, String systemId) { _log.info("resolving "+publicId+" : "+systemId); - + URL url=(URL)_map.get(publicId); - + if (url==null) { - _log.info("no resolution for "+publicId); + _log.warn("WARNING: no resolution for "+publicId+" - are you using a supported JSDK version?"); } else { @@ -54,7 +54,7 @@ } catch (IOException e) { - _log.error("bad resolution "+publicId+" : "+url, e); + _log.error("ERROR: bad resolution "+publicId+" : "+url, e); } } 1.27 +44 -45 contrib/jetty/src/main/org/jboss/jetty/JettyService.java Index: JettyService.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyService.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- JettyService.java 2001/11/12 06:36:50 1.26 +++ JettyService.java 2001/11/21 23:13:01 1.27 @@ -4,9 +4,9 @@ * Distributable under GPL license. * See terms of license at gnu.org. */ - -// $Id: JettyService.java,v 1.26 2001/11/12 06:36:50 d_jencks Exp $ +// $Id: JettyService.java,v 1.27 2001/11/21 23:13:01 jules_gosnell Exp $ + package org.jboss.jetty; import java.io.File; @@ -25,19 +25,18 @@ import org.jboss.web.AbstractWebContainer.WebDescriptorParser; import org.jboss.web.AbstractWebContainer; import org.jboss.web.WebApplication; -import org.mortbay.http.HandlerContext; import org.mortbay.http.HttpServer; -import org.mortbay.jetty.jmx.HttpServerMBean; +import org.mortbay.jetty.jmx.JettyServerMBean; import org.mortbay.jetty.servlet.WebApplicationContext; import org.mortbay.util.Log; import org.mortbay.xml.XmlConfiguration; /** * A service to launch jetty from JMX. - * + * * @see <related> * @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a> - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ */ // NOTES @@ -50,7 +49,7 @@ implements JettyServiceMBean, MBeanRegistration { public static final String NAME = "Jetty"; - + Category _log = Category.getInstance(super.category.getName()+"."+getName()); JettyMBean _mbean = null; Jetty _jetty = null; @@ -73,18 +72,18 @@ { name = getObjectName(server, name); _server = server; - + return name; } //---------------------------------------------------------------------------- - + protected void ensureLogging() { // sort out a JBossLogSink for use by Jetty. This will bridge the // API between Jetty and Log4J... - + JBossLogSink logSink = new JBossLogSink(); try { @@ -92,24 +91,24 @@ } catch(Exception e) { - _log.error("Could not initialise logging bridge", e); + _log.error("ERROR: Could not initialise logging bridge", e); } logSink.start(); Log.instance().disableLog(); // remove default logger Log.instance().add(logSink); - + // why doesn't this work? - investigate... // _jetty.setLogSink(logSink); - + _log.info("connected JBoss and Jetty Log models"); } - + /** the usual path separators we know */ protected final static String KNOWN_PATH_SEPARATORS=":;"; - + /** tiny helper that converts classpath properties to the target platform */ - protected String convertPath(String original) + protected String convertPath(String original) { // should be set, but who knows String separator=System.getProperty("path.separator",";"); @@ -121,17 +120,17 @@ result.append(separator); } else { first=false; - } + } result.append(tokenizer.nextToken()); } return result.toString(); } - + /** this is the property in which Jasper expects the additional classpath */ protected final static String TC_PATH_ADD="tc_path_add"; - - /** + + /** * enter the jetty.properties file to the system properties such that * Jasper will find the right jars to compile */ @@ -141,15 +140,15 @@ { String props="jetty.properties"; InputStream propertiesIn = getClass().getClassLoader().getResourceAsStream(props); - + if (propertiesIn == null) throw new IOException("failed to load "+props); - + System.getProperties().load(propertiesIn); - + // make sure that the tc_path_add property is correctly set - System.setProperty(TC_PATH_ADD,convertPath(System.getProperty(TC_PATH_ADD,""))); - + // System.setProperty(TC_PATH_ADD,convertPath(System.getProperty(TC_PATH_ADD,""))); + _log.info("loaded properties from: "+props); } @@ -182,7 +181,7 @@ } catch (Throwable e) { - _log.error("JMX Registration problem", e); + _log.error("ERROR: JMX Registration problem", e); } } else @@ -201,7 +200,7 @@ ensureJetty(); ensureConfig(); } - + //---------------------------------------------------------------------------- // 'name' interface //---------------------------------------------------------------------------- @@ -212,7 +211,7 @@ { return new ObjectName(OBJECT_NAME); } - + public String getName() { @@ -222,8 +221,8 @@ //---------------------------------------------------------------------------- // 'service' interface //---------------------------------------------------------------------------- + - protected boolean _started=false; public void @@ -235,7 +234,7 @@ try {ensureService();} catch (Exception e) {e.printStackTrace();} } else - _log.warn("Jetty has already been initialised"); + _log.warn("WARNING: Jetty has already been initialised"); if (!isStarted()) { @@ -243,9 +242,9 @@ _started=true; } else - _log.warn("Jetty has already been started"); + _log.warn("WARNING: Jetty has already been started"); } - + public void stopService() { @@ -257,23 +256,22 @@ } catch (Exception e) { - _log.error("Could not stop Jetty", e); + _log.error("ERROR: Could not stop Jetty", e); } _started=false; } else - _log.warn("Jetty has already been stopped"); + _log.warn("WARNING: Jetty has already been stopped"); if (!isDestroyed()) { - _jetty.destroy(); + // _jetty.destroy(); _jetty=null; _mbean=null; } else - _log.warn("Jetty has already been destroyed"); + _log.warn("WARNING: Jetty has already been destroyed"); } - //---------------------------------------------------------------------------- // 'deploy' interface //---------------------------------------------------------------------------- @@ -282,9 +280,10 @@ performDeploy(String path, String warUrl, WebDescriptorParser parser) throws DeploymentException { + _log.info("about to deploy to "+path); return _jetty.deploy(path, warUrl, parser); } - + public void performUndeploy(String warUrl) throws DeploymentException @@ -299,25 +298,25 @@ { return (_jetty!=null); } - + protected boolean isStarted() { return (_jetty!=null && _started); } - + protected boolean isStopped() { return (!_started); } - + protected boolean isDestroyed() { return (_jetty==null); } - + //---------------------------------------------------------------------------- protected boolean _publishMBeans=false; @@ -361,7 +360,7 @@ } //---------------------------------------------------------------------------- - + protected String _webDefault=null; public String @@ -385,7 +384,7 @@ } //---------------------------------------------------------------------------- - + protected String _configuration=null; public String @@ -407,7 +406,7 @@ else _configuration=configUrl; } - + //---------------------------------------------------------------------------- protected static String _jettyHome=null; 1.11 +3 -82 contrib/jetty/src/main/org/jboss/jetty/SetupHandler.java Index: SetupHandler.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/SetupHandler.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SetupHandler.java 2001/10/03 22:27:02 1.10 +++ SetupHandler.java 2001/11/21 23:13:01 1.11 @@ -4,89 +4,10 @@ * Distributable under GPL license. * See terms of license at gnu.org. */ - -// $Id: SetupHandler.java,v 1.10 2001/10/03 22:27:02 jules_gosnell Exp $ -package org.jboss.jetty; +// $Id: SetupHandler.java,v 1.11 2001/11/21 23:13:01 jules_gosnell Exp $ -import java.io.IOException; -import org.apache.log4j.Category; -import org.jboss.web.AbstractWebContainer.WebDescriptorParser; -import org.jboss.web.WebApplication; -import org.mortbay.http.HttpException; -import org.mortbay.http.HttpRequest; -import org.mortbay.http.HttpResponse; -import org.mortbay.http.HttpServer; -import org.mortbay.http.handler.NullHandler; -import org.w3c.dom.Element; +package org.jboss.jetty; -/** - * An HttpHandler that simply hooks into the web application startup - * so that is sees the correct class loader and security realm name. - * - * @author [EMAIL PROTECTED] - * @version $Revision: 1.10 $ - */ public class SetupHandler - extends NullHandler -{ - Category _log; - WebDescriptorParser _descriptorParser; - WebApplication _webApp; - - //---------------------------------------------------------------------- - - public - SetupHandler(Category log, - WebDescriptorParser descriptorParser, - WebApplication webApp) - { - _log = log; - _descriptorParser = descriptorParser; - _webApp = webApp; - } - - //---------------------------------------------------------------------- - - public void - start() - throws Exception - { - ClassLoader loader = getHandlerContext().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("WebApp Context's ClassLoader is of incorrect descent:"+loader); - } - - // Setup the JNDI environment - Element webAppDD = _webApp.getWebApp(); - Element jbossDD = _webApp.getJbossWeb(); - _descriptorParser.parseWebAppDescriptors(loader, webAppDD, jbossDD); - - // Add the JBoss security realm - HttpServer server = getHandlerContext().getHttpServer(); - String realmName = getHandlerContext().getRealm(); - server.addRealm(new JBossUserRealm(_log, realmName)); - - super.start(); - } - - //---------------------------------------------------------------------- - - /** - * Does nothing - we are only interested in {@link #start}. - */ - public void - handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) - throws HttpException, IOException - { - } -} +{} 1.1 contrib/jetty/src/main/org/jboss/jetty/JBossWebApplicationContext.java Index: JBossWebApplicationContext.java =================================================================== /* * jBoss, the OpenSource EJB server * * Distributable under GPL license. * See terms of license at gnu.org. */ // $Id: JBossWebApplicationContext.java,v 1.1 2001/11/21 23:13:01 jules_gosnell Exp $ // A Jetty HttpServer with the interface expected by JBoss' // J2EEDeployer... package org.jboss.jetty; import org.apache.log4j.Category; import org.jboss.web.AbstractWebContainer.WebDescriptorParser; import org.jboss.web.WebApplication; import org.mortbay.http.HttpServer; import org.mortbay.jetty.servlet.WebApplicationContext; import org.w3c.dom.Element; import org.mortbay.http.handler.SecurityHandler; import javax.naming.Context; import javax.naming.InitialContext; import org.jboss.security.EJBSecurityManager; 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 { Category _log; WebDescriptorParser _descriptorParser; WebApplication _webApp; public JBossWebApplicationContext(HttpServer httpServer, String contextPathSpec, Category log, WebDescriptorParser descriptorParser, WebApplication webApp) { 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); // } } /* ------------------------------------------------------------ */ /** Get the context SecurityHandler. * Conveniance method. If no SecurityHandler exists, a new one is added to * the context at position 0. * @return SecurityHandler */ class JBossSXSecurityHandler extends SecurityHandler { 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); _log.info("WebApp Descriptors parsed"); // Add the JBoss security realm String realmName = getRealm(); if (realmName!=null) { _log.info("WebApp Realm initialised"); // these need to be cached and reused by name... - TODO getHttpContext().getHttpServer().addRealm(new JBossUserRealm(realmName)); } // this is causing a printout which implies a separate // SecurityHandler has also started... super.start(); } } /** * return the first JBossSXSecurityHandler, inserting one at the * beginning of the list, if no other can be found. * * @return a <code>SecurityHandler</code> value */ public SecurityHandler getSecurityHandler() { SecurityHandler securityHandler=null; securityHandler=(SecurityHandler)getHttpHandler(JBossSXSecurityHandler.class); if (securityHandler==null) { securityHandler=new JBossSXSecurityHandler(); addHttpHandler(0,securityHandler); } return securityHandler; } // avoid Jetty maoning about things that it doesn't bu AbstractWebContainer does do... protected void initWebXmlElement(String element, org.mortbay.xml.XmlParser.Node node) throws Exception { // these are handled by AbstractWebContainer if ("resource-ref".equals(element) || "env-entry".equals(element) || "ejb-ref".equals(element)) { //_log.info("Don't moan : "+element); } // these are handled by Jetty else super.initWebXmlElement(element, node); } //--debugging 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); } protected void initClassLoader() throws java.net.MalformedURLException, java.io.IOException { super.initClassLoader(); ClassLoader _loader=getClassLoader(); if (_loader instanceof org.mortbay.http.ContextLoader) ((org.mortbay.http.ContextLoader)_loader).setJava2Compliant(true); } public String getFileClassPath() throws IllegalStateException { ClassLoader loader = getClassLoader(); if (loader==null) throw new IllegalStateException("Context classloader not initialized"); String fileClassPath = ((loader instanceof ContextLoader) ? ((ContextLoader)loader).getFileClassPath() : getClassPath())+ System.getProperty("path.separator")+ System.getProperty("java.class.path"); try { String dtd="javax/servlet/resources/web-app_2_3.dtd"; String path=getClass().getClassLoader().getResource(dtd).toString(); String jarPath=path.substring(0,path.length()-(dtd.length()+2)); // lose final '!/class...' jarPath=jarPath.substring("jar:file:".length(),jarPath.length()); fileClassPath+=jarPath; } catch (Exception e) { _log.warn("WARNING: could not find Servlet API jar", e); } try { String dtd="org/apache/jasper/resources/jsp12.dtd"; String path=getClass().getClassLoader().getResource(dtd).toString(); String jarPath=path.substring(0,path.length()-(dtd.length()+2)); // lose final '!/class...' jarPath=jarPath.substring("jar:file:".length(),jarPath.length()); fileClassPath+=":"+jarPath; } catch (Exception e) { _log.warn("WARNING: could not find Servlet API jar", e); } _log.info("default JSP CLASSPATH:"+fileClassPath); return fileClassPath; } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development