User: starksm
Date: 01/12/01 18:08:53
Modified: jetty/src/main/org/jboss/jetty Tag: Branch_2_4
JBossUserRealm.java Jetty.java JettyService.java
JettyServiceMBean.java
Log:
Synch up with changes for 2.4.4 and fix incorrect role type
passed to RealmMapping.doesUserHaveRole
Revision Changes Path
No revision
No revision
1.2.2.4 +190 -189 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.2.2.3
retrieving revision 1.2.2.4
diff -u -r1.2.2.3 -r1.2.2.4
--- JBossUserRealm.java 2001/10/30 22:45:12 1.2.2.3
+++ JBossUserRealm.java 2001/12/02 02:08:53 1.2.2.4
@@ -1,189 +1,190 @@
-/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
-
-// $Id: JBossUserRealm.java,v 1.2.2.3 2001/10/30 22:45:12 jules_gosnell Exp $
-
-package org.jboss.jetty;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Set;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.apache.log4j.Category;
-import org.jboss.security.EJBSecurityManager;
-import org.jboss.security.RealmMapping;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SimplePrincipal;
-import org.mortbay.http.HttpRequest;
-import org.mortbay.http.UserPrincipal;
-import org.mortbay.http.UserRealm;
-
-/** An implementation of UserRealm that integrates with the JBossSX
- * security manager associted with the web application.
- * @author [EMAIL PROTECTED]
- * @version $Revision: 1.2.2.3 $
- */
-
-public class JBossUserRealm
- implements UserRealm
-{
- private Category _log;
- private String _realmName;
- private EJBSecurityManager _securityMgr;
- private RealmMapping _realmMapping;
- private HashMap _users = new HashMap();
-
- class User
- extends SimplePrincipal
- implements UserPrincipal
- {
- User(String name)
- {
- super(name);
- _log.info("Security- created JBossUserRealm::User: "+name);
- }
-
- public boolean
- equals(Object o)
- {
- if (o==this)
- return true;
-
- if (o==null)
- return false;
-
- if (getClass()!=o.getClass())
- return false;
-
- String myName =this.getName();
- String yourName=((User)o).getName();
-
- 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
-
- // Get the JBoss security manager from the ENC context
- if(_securityMgr!=null &&_securityMgr.isValid(this, password))
- {
- authenticated = true;
- _log.info("Security- User: "+userName+" is authenticated");
- SecurityAssociation.setPrincipal(this);
- SecurityAssociation.setCredential(password.toCharArray());
- }
- else
- {
- _log.warn("Security- User: "+userName+" is NOT authenticated");
- }
-
- return authenticated;
- }
-
- public boolean
- isUserInRole(String role)
- {
- boolean isUserInRole = false;
- String userName = this.getName();
-
- // Get the JBoss security manager from the ENC context
- Set requiredRoles = Collections.singleton(role);
- if(_realmMapping.doesUserHaveRole(this, requiredRoles))
- {
- isUserInRole = true;
- _log.info("Security- User: "+userName+" is in Role: "+role);
- }
- else
- {
- _log.warn("Security- User: "+userName+" is NOT in Role: "+role);
- }
-
- return isUserInRole;
- }
-
- public UserRealm
- getUserRealm()
- {
- return JBossUserRealm.this;
- }
- }
-
- public
- JBossUserRealm(Category log, String realmName)
- {
- _log = log;
- _realmName = realmName;
- _log.info("Security- created JBossUserRealm: "+_realmName);
- }
-
- public String
- getName()
- {
- return _realmName;
- }
-
- /**
- * @deprecated
- */
- public UserPrincipal
- getUser(String userName, HttpRequest request)
- {
- return getUser(userName);
- }
-
- //----------------------------------------
-
- private synchronized User
- ensureUser(String userName)
- {
- User user = (User)_users.get(userName);
-
- if (user==null)
- {
- user=new User(userName);
- _users.put(userName, user);
- }
-
- return user;
- }
-
- public UserPrincipal
- getUser(String userName)
- {
- if (_securityMgr==null)
- {
- try
- {
- // do we really have to do this every time - is it expensive ? TODO
- InitialContext iniCtx = new InitialContext();
- // do we need the 'java:comp/env' prefix ? TODO
- _securityMgr = (EJBSecurityManager)
iniCtx.lookup("java:comp/env/security/securityMgr");
- _realmMapping = (RealmMapping)
iniCtx.lookup("java:comp/env/security/realmMapping");
- }
- catch (NamingException e)
- {
- _log.error("Security- Could not create initial Context", e);
- }
- }
-
- _log.info("Security- User: "+userName);
-
- return ensureUser(userName);
- }
-
- //----------------------------------------
-}
+/*
+ * jBoss, the OpenSource EJB server
+ *
+ * Distributable under GPL license.
+ * See terms of license at gnu.org.
+ */
+
+// $Id: JBossUserRealm.java,v 1.2.2.4 2001/12/02 02:08:53 starksm Exp $
+
+package org.jboss.jetty;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Set;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.apache.log4j.Category;
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+import org.mortbay.http.HttpRequest;
+import org.mortbay.http.UserPrincipal;
+import org.mortbay.http.UserRealm;
+
+/** An implementation of UserRealm that integrates with the JBossSX
+ * security manager associted with the web application.
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.2.2.4 $
+ */
+
+public class JBossUserRealm
+ implements UserRealm
+{
+ private Category _log;
+ private String _realmName;
+ private AuthenticationManager _securityMgr;
+ private RealmMapping _realmMapping;
+ private HashMap _users = new HashMap();
+
+ class User
+ extends SimplePrincipal
+ implements UserPrincipal
+ {
+ User(String name)
+ {
+ super(name);
+ _log.info("Security- created JBossUserRealm::User: "+name);
+ }
+
+ public boolean
+ equals(Object o)
+ {
+ if (o==this)
+ return true;
+
+ if (o==null)
+ return false;
+
+ if (getClass()!=o.getClass())
+ return false;
+
+ String myName =this.getName();
+ String yourName=((User)o).getName();
+
+ 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
+
+ // Get the JBoss security manager from the ENC context
+ if(_securityMgr!=null &&_securityMgr.isValid(this, password))
+ {
+ authenticated = true;
+ _log.info("Security- User: "+userName+" is authenticated");
+ SecurityAssociation.setPrincipal(this);
+ SecurityAssociation.setCredential(password.toCharArray());
+ }
+ else
+ {
+ _log.warn("Security- User: "+userName+" is NOT authenticated");
+ }
+
+ return authenticated;
+ }
+
+ public boolean
+ isUserInRole(String role)
+ {
+ boolean isUserInRole = false;
+ String userName = this.getName();
+
+ // Get the JBoss security manager from the ENC context
+ SimplePrincipal rolePrincipal = new SimplePrincipal(role);
+ Set requiredRoles = Collections.singleton(rolePrincipal);
+ if(_realmMapping.doesUserHaveRole(this, requiredRoles))
+ {
+ isUserInRole = true;
+ _log.info("Security- User: "+userName+" is in Role: "+role);
+ }
+ else
+ {
+ _log.warn("Security- User: "+userName+" is NOT in Role: "+role);
+ }
+
+ return isUserInRole;
+ }
+
+ public UserRealm
+ getUserRealm()
+ {
+ return JBossUserRealm.this;
+ }
+ }
+
+ public
+ JBossUserRealm(Category log, String realmName)
+ {
+ _log = log;
+ _realmName = realmName;
+ _log.info("Security- created JBossUserRealm: "+_realmName);
+ }
+
+ public String
+ getName()
+ {
+ return _realmName;
+ }
+
+ /**
+ * @deprecated
+ */
+ public UserPrincipal
+ getUser(String userName, HttpRequest request)
+ {
+ return getUser(userName);
+ }
+
+ //----------------------------------------
+
+ private synchronized User
+ ensureUser(String userName)
+ {
+ User user = (User)_users.get(userName);
+
+ if (user==null)
+ {
+ user=new User(userName);
+ _users.put(userName, user);
+ }
+
+ return user;
+ }
+
+ public UserPrincipal
+ getUser(String userName)
+ {
+ if (_securityMgr==null)
+ {
+ try
+ {
+ // do we really have to do this every time - is it expensive ? TODO
+ InitialContext iniCtx = new InitialContext();
+ // do we need the 'java:comp/env' prefix ? TODO
+ _securityMgr = (AuthenticationManager)
iniCtx.lookup("java:comp/env/security/securityMgr");
+ _realmMapping = (RealmMapping)
iniCtx.lookup("java:comp/env/security/realmMapping");
+ }
+ catch (NamingException e)
+ {
+ _log.error("Security- Could not create initial Context", e);
+ }
+ }
+
+ _log.info("Security- User: "+userName);
+
+ return ensureUser(userName);
+ }
+
+ //----------------------------------------
+}
1.9.2.7 +270 -270 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.9.2.6
retrieving revision 1.9.2.7
diff -u -r1.9.2.6 -r1.9.2.7
--- Jetty.java 2001/09/23 19:51:36 1.9.2.6
+++ Jetty.java 2001/12/02 02:08:53 1.9.2.7
@@ -1,270 +1,270 @@
-/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
-
-// $Id: Jetty.java,v 1.9.2.6 2001/09/23 19:51:36 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.util.Hashtable;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.log4j.Category;
-import org.jboss.ejb.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;
-
-public class Jetty
- extends org.mortbay.jetty.Server
-{
- Category _log;
- JettyResolver _resolver;
-
- Jetty(Category log)
- {
- super();
- _log=log;
-
- // 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");
- _resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb);
- _resolver.put("-//JBoss//DTD Web Application 2.2//EN", jbossWeb);
- }
-
- //----------------------------------------
- // jettyHome property
- //----------------------------------------
-
- synchronized void
- setJettyHome(String jettyHome) // not public
- {
- if (jettyHome!=null)
- System.setProperty("jetty.home", jettyHome);
- }
-
- public synchronized String
- getJettyHome()
- {
- return System.getProperty("jetty.home");
- }
-
- //----------------------------------------
- // unpackWars property
- //----------------------------------------
-
- boolean _unpackWars=false;
-
- public synchronized void
- setUnpackWars(boolean unpackWars)
- {
- _unpackWars=unpackWars;
- }
-
- public synchronized boolean
- getUnpackWars()
- {
- return _unpackWars;
- }
-
- //----------------------------------------
- // webDefault property
- //----------------------------------------
-
- String _webDefault;
-
- public synchronized void
- setWebDefault(String webDefault)
- {
- _webDefault=webDefault;
- }
-
- public synchronized String
- getWebDefault()
- {
- return _webDefault;
- }
-
- //----------------------------------------
- // configuration property
- //----------------------------------------
-
- String _configuration=null;
-
- public synchronized void
- setConfiguration(String configUrl)
- {
- if (configUrl==null)
- return;
-
- try
- {
- _log.info("loading config: "+configUrl);
- configure(configUrl);
- _log.info("loaded config: "+configUrl);
- _configuration=configUrl;
- }
- catch (Exception e)
- {
- _log.error("problem loading configuration: "+configUrl, e);
- }
- }
-
- public synchronized String
- getConfiguration()
- {
- return _configuration;
- }
-
- //----------------------------------------------------------------------------
- // 'deploy' interface
- //----------------------------------------------------------------------------
-
- Hashtable _deployed = new Hashtable(); // use Hashtable because is is synchronised
-
- public WebApplication
- deploy(String contextPath, String warUrl, WebDescriptorParser descriptorParser)
- throws DeploymentException
- {
- WebApplication wa=new WebApplication();
-
- try
- {
- wa.setURL(new URL(warUrl));
-
- // check whether the context already exists... - a bit hacky,
- // could be nicer...
- if (getContext(null, contextPath, 0)!=null)
- _log.warn("WARNING: A WebApplication is already deployed in context
'"+contextPath+"' - proceed at your own risk.");
-
- // deploy the WebApp
- WebApplicationContext app=new WebApplicationContext(this, contextPath);
- 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();
- 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");
- }
-
- // Add a handler to perform the JBoss integration during start()
- HttpHandler handler = new SetupHandler(_log, descriptorParser, wa);
- app.addHandler(handler);
- // finally - start the WebApp...
- app.start();
- // Remove the handler
- handler.stop();
- app.removeHandler(handler);
- handler.destroy();
-
- // keep track of deployed contexts for undeployment
- _deployed.put(warUrl, app);
-
- _log.info("successfully deployed "+warUrl+" to "+contextPath);
- }
- catch (Exception e)
- {
- _log.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();
-
- _deployed.remove(warUrl);
-
- _log.info("successfully undeployed "+warUrl);
- }
- catch (Exception e)
- {
- _log.error("problem undeploying "+warUrl, e);
- throw new DeploymentException(e.getMessage());
- }
- }
-
- public boolean
- isDeployed(String warUrl)
- {
- return _deployed.containsKey(warUrl);
- }
-
- //----------------------------------------------------------------------------
- // Utils
- //----------------------------------------------------------------------------
-
- public URL
- findResourceInJar(String sibling, String name)
- {
- URL url=null;
-
- try
- {
- url=getClass().getClassLoader().getResource(name);
- }
- catch (Exception e)
- {
- _log.error("Could not find resource: "+name, e);
- }
-
- return url;
- }
-}
+/*
+ * jBoss, the OpenSource EJB server
+ *
+ * Distributable under GPL license.
+ * See terms of license at gnu.org.
+ */
+
+// $Id: Jetty.java,v 1.9.2.7 2001/12/02 02:08:53 starksm 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.util.Hashtable;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.log4j.Category;
+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;
+
+public class Jetty
+ extends org.mortbay.jetty.Server
+{
+ Category _log;
+ JettyResolver _resolver;
+
+ Jetty(Category log)
+ {
+ super();
+ _log=log;
+
+ // 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");
+ _resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb);
+ _resolver.put("-//JBoss//DTD Web Application 2.2//EN", jbossWeb);
+ }
+
+ //----------------------------------------
+ // jettyHome property
+ //----------------------------------------
+
+ synchronized void
+ setJettyHome(String jettyHome) // not public
+ {
+ if (jettyHome!=null)
+ System.setProperty("jetty.home", jettyHome);
+ }
+
+ public synchronized String
+ getJettyHome()
+ {
+ return System.getProperty("jetty.home");
+ }
+
+ //----------------------------------------
+ // unpackWars property
+ //----------------------------------------
+
+ boolean _unpackWars=false;
+
+ public synchronized void
+ setUnpackWars(boolean unpackWars)
+ {
+ _unpackWars=unpackWars;
+ }
+
+ public synchronized boolean
+ getUnpackWars()
+ {
+ return _unpackWars;
+ }
+
+ //----------------------------------------
+ // webDefault property
+ //----------------------------------------
+
+ String _webDefault;
+
+ public synchronized void
+ setWebDefault(String webDefault)
+ {
+ _webDefault=webDefault;
+ }
+
+ public synchronized String
+ getWebDefault()
+ {
+ return _webDefault;
+ }
+
+ //----------------------------------------
+ // configuration property
+ //----------------------------------------
+
+ String _configuration=null;
+
+ public synchronized void
+ setConfiguration(String configUrl)
+ {
+ if (configUrl==null)
+ return;
+
+ try
+ {
+ _log.info("loading config: "+configUrl);
+ configure(configUrl);
+ _log.info("loaded config: "+configUrl);
+ _configuration=configUrl;
+ }
+ catch (Exception e)
+ {
+ _log.error("problem loading configuration: "+configUrl, e);
+ }
+ }
+
+ public synchronized String
+ getConfiguration()
+ {
+ return _configuration;
+ }
+
+ //----------------------------------------------------------------------------
+ // 'deploy' interface
+ //----------------------------------------------------------------------------
+
+ Hashtable _deployed = new Hashtable(); // use Hashtable because is is synchronised
+
+ public WebApplication
+ deploy(String contextPath, String warUrl, WebDescriptorParser descriptorParser)
+ throws DeploymentException
+ {
+ WebApplication wa=new WebApplication();
+
+ try
+ {
+ wa.setURL(new URL(warUrl));
+
+ // check whether the context already exists... - a bit hacky,
+ // could be nicer...
+ if (getContext(null, contextPath, 0)!=null)
+ _log.warn("WARNING: A WebApplication is already deployed in context
'"+contextPath+"' - proceed at your own risk.");
+
+ // deploy the WebApp
+ WebApplicationContext app=new WebApplicationContext(this, contextPath);
+ 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();
+ 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");
+ }
+
+ // Add a handler to perform the JBoss integration during start()
+ HttpHandler handler = new SetupHandler(_log, descriptorParser, wa);
+ app.addHandler(handler);
+ // finally - start the WebApp...
+ app.start();
+ // Remove the handler
+ handler.stop();
+ app.removeHandler(handler);
+ handler.destroy();
+
+ // keep track of deployed contexts for undeployment
+ _deployed.put(warUrl, app);
+
+ _log.info("successfully deployed "+warUrl+" to "+contextPath);
+ }
+ catch (Exception e)
+ {
+ _log.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();
+
+ _deployed.remove(warUrl);
+
+ _log.info("successfully undeployed "+warUrl);
+ }
+ catch (Exception e)
+ {
+ _log.error("problem undeploying "+warUrl, e);
+ throw new DeploymentException(e.getMessage());
+ }
+ }
+
+ public boolean
+ isDeployed(String warUrl)
+ {
+ return _deployed.containsKey(warUrl);
+ }
+
+ //----------------------------------------------------------------------------
+ // Utils
+ //----------------------------------------------------------------------------
+
+ public URL
+ findResourceInJar(String sibling, String name)
+ {
+ URL url=null;
+
+ try
+ {
+ url=getClass().getClassLoader().getResource(name);
+ }
+ catch (Exception e)
+ {
+ _log.error("Could not find resource: "+name, e);
+ }
+
+ return url;
+ }
+}
1.15.2.3 +411 -412 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.15.2.2
retrieving revision 1.15.2.3
diff -u -r1.15.2.2 -r1.15.2.3
--- JettyService.java 2001/09/18 23:04:34 1.15.2.2
+++ JettyService.java 2001/12/02 02:08:53 1.15.2.3
@@ -1,412 +1,411 @@
-/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
-
-// $Id: JettyService.java,v 1.15.2.2 2001/09/18 23:04:34 jules_gosnell Exp $
-
-package org.jboss.jetty;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Hashtable;
-import java.util.Vector;
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.apache.log4j.Category;
-import org.jboss.ejb.DeploymentException;
-import org.jboss.util.ServiceMBeanSupport;
-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.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.15.2.2 $
- */
-
-// NOTES
-
-// I could parameterise the properties file - do we still need it -
-// shouldn't it use MLET ?
-
-public class JettyService
- extends AbstractWebContainer
- implements JettyServiceMBean, MBeanRegistration
-{
- public static final String NAME = "Jetty";
-
- Category _log =
Category.getInstance(super.category.getName()+"."+getName());
- JettyMBean _mbean = null;
- Jetty _jetty = null;
- MBeanServer _server = null;
-
- public
- JettyService()
- {
- // moved this from initialise-time to construct-time to ensure
- // that logging models are connected before configure-time (via
- // MLET file) which is done before initialise-time.
- ensureLogging();
- }
-
- //----------------------------------------------------------------------------
-
- public ObjectName
- preRegister(MBeanServer server, ObjectName name)
- throws java.lang.Exception
- {
- 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
- {
- logSink.initialize(_log);
- }
- catch(Exception e)
- {
- _log.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");
- }
-
- protected void
- ensureProperties()
- throws IOException
- {
- String props="jetty.properties";
- InputStream propertiesIn =
getClass().getClassLoader().getResourceAsStream(props);
-
- if (propertiesIn == null)
- throw new IOException("failed to load "+props);
-
- System.getProperties().load(propertiesIn);
-
- _log.info("loaded properties from: "+props);
- }
-
- protected void
- ensureJetty()
- {
- // make a Jetty...
- Jetty tmp = new Jetty(_log); // tmp - until we have initialised it...
- tmp.setJettyHome(getJettyHome());
- tmp.setWebDefault(getWebDefault());
- tmp.setUnpackWars(getUnpackWars());
-
- _jetty=tmp; // now we are initialised.
-
- _log.info("instantiated and configured server");
- }
-
- protected void
- ensureConfig()
- {
- // this must be done before config is read otherwise configs
- // defined therein will not receive MBean peers.
- if (getPublishMBeans())
- {
- try
- {
- _log.info("MBean peers WILL be created for Jetty Contexts");
- _mbean = new JettyMBean(_jetty);
- _server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server)));
- }
- catch (Throwable e)
- {
- _log.error("JMX Registration problem", e);
- }
- }
- else
- {
- _log.info("MBean peers WILL NOT be created for Jetty Contexts");
- }
-
- _jetty.setConfiguration(_configuration);
- }
-
- protected void
- ensureService()
- throws Exception
- {
- ensureProperties();
- ensureJetty();
- ensureConfig();
- }
-
- //----------------------------------------------------------------------------
- // 'name' interface
- //----------------------------------------------------------------------------
-
- public ObjectName
- getObjectName(MBeanServer server, ObjectName name)
- throws javax.management.MalformedObjectNameException
- {
- return new ObjectName(OBJECT_NAME);
- }
-
- public String
- getName()
- {
- return NAME;
- }
-
- //----------------------------------------------------------------------------
- // 'service' interface
- //----------------------------------------------------------------------------
-
- public void
- initService()
- throws Exception
- {
- if (!isInitialised())
- {
- super.initService();
- try {ensureService();} catch (Exception e) {e.printStackTrace();}
- }
- else
- _log.warn("Jetty has already been initialised");
- }
-
- protected boolean _started=false;
-
- public void
- startService()
- throws Exception
- {
- if (!isStarted())
- {
- super.startService();
- _jetty.start();
- _started=true;
- }
- else
- _log.warn("Jetty has already been started");
- }
-
- public void
- stopService()
- {
- if (!isStopped())
- {
- super.stopService();
- try
- {
- _jetty.stop();
- }
- catch (Exception e)
- {
- _log.error("Could not stop Jetty", e);
- }
- _started=false;
- }
- else
- _log.warn("Jetty has already been stopped");
- }
-
- public void
- destroyService()
- {
- if (!isDestroyed())
- {
- super.destroyService();
- _jetty.destroy();
- _jetty=null;
- _mbean=null;
- }
- else
- _log.warn("Jetty has already been destroyed");
- }
-
- //----------------------------------------------------------------------------
- // 'deploy' interface
- //----------------------------------------------------------------------------
-
- public WebApplication
- performDeploy(String path, String warUrl, WebDescriptorParser parser)
- throws DeploymentException
- {
- return _jetty.deploy(path, warUrl, parser);
- }
-
- public void
- performUndeploy(String warUrl)
- throws DeploymentException
- {
- _jetty.undeploy(warUrl);
- }
-
- //----------------------------------------------------------------------------
-
- protected boolean
- isInitialised()
- {
- 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;
-
- public boolean
- getPublishMBeans()
- {
- return _publishMBeans;
- }
-
- public void
- setPublishMBeans(boolean publishMBeans)
- {
- _log.info("set PublishMBeans to "+publishMBeans);
-
- _publishMBeans=publishMBeans;
- }
-
- //----------------------------------------------------------------------------
-
- protected boolean _unpackWars=false;
-
- public boolean
- getUnpackWars()
- {
- if (isInitialised())
- return _jetty.getUnpackWars();
- else
- return _unpackWars;
- }
-
- public void
- setUnpackWars(boolean unpackWars)
- {
- _log.info("set UnpackWars to "+unpackWars);
-
- if (isInitialised())
- _jetty.setUnpackWars(unpackWars);
- else
- _unpackWars=unpackWars;
- }
-
- //----------------------------------------------------------------------------
-
- protected String _webDefault=null;
-
- public String
- getWebDefault()
- {
- if (isInitialised())
- return _jetty.getWebDefault();
- else
- return _webDefault;
- }
-
- public void
- setWebDefault(String webDefault)
- {
- _log.info("set WebDefault to "+webDefault);
-
- if (isInitialised())
- _jetty.setWebDefault(webDefault);
- else
- _webDefault=webDefault;
- }
-
- //----------------------------------------------------------------------------
-
- protected String _configuration=null;
-
- public String
- getConfiguration()
- {
- if (isInitialised())
- return _jetty.getConfiguration();
- else
- return _configuration;
- }
-
- public void
- setConfiguration(String configUrl)
- {
- _log.info("set Configuration to "+configUrl);
-
- if (isInitialised())
- _jetty.setConfiguration(configUrl);
- else
- _configuration=configUrl;
- }
-
- //----------------------------------------------------------------------------
-
- protected static String _jettyHome=null;
-
- public String
- getJettyHome()
- {
- if (isInitialised())
- return _jetty.getJettyHome();
- else
- return _jettyHome;
- }
-
- public void
- setJettyHome(String jettyHome)
- {
- _log.info("set JettyHome to "+jettyHome);
-
- if (isInitialised())
- _jetty.setJettyHome(jettyHome);
- else
- _jettyHome=jettyHome;
- }
-}
+/*
+ * jBoss, the OpenSource EJB server
+ *
+ * Distributable under GPL license.
+ * See terms of license at gnu.org.
+ */
+
+// $Id: JettyService.java,v 1.15.2.3 2001/12/02 02:08:53 starksm Exp $
+
+package org.jboss.jetty;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Vector;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.deployment.DeploymentException;
+import org.jboss.util.ServiceMBeanSupport;
+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.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.15.2.3 $
+ */
+
+// NOTES
+
+// I could parameterise the properties file - do we still need it -
+// shouldn't it use MLET ?
+
+public class JettyService
+ extends AbstractWebContainer
+ implements JettyServiceMBean, MBeanRegistration
+{
+ public static final String NAME = "Jetty";
+
+ JettyMBean _mbean = null;
+ Jetty _jetty = null;
+ MBeanServer _server = null;
+
+ public
+ JettyService()
+ {
+ // moved this from initialise-time to construct-time to ensure
+ // that logging models are connected before configure-time (via
+ // MLET file) which is done before initialise-time.
+ ensureLogging();
+ }
+
+ //----------------------------------------------------------------------------
+
+ public ObjectName
+ preRegister(MBeanServer server, ObjectName name)
+ throws java.lang.Exception
+ {
+ 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
+ {
+ logSink.initialize(log.getCategory());
+ }
+ catch(Exception e)
+ {
+ log.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");
+ }
+
+ protected void
+ ensureProperties()
+ throws IOException
+ {
+ String props="jetty.properties";
+ InputStream propertiesIn =
getClass().getClassLoader().getResourceAsStream(props);
+
+ if (propertiesIn == null)
+ throw new IOException("failed to load "+props);
+
+ System.getProperties().load(propertiesIn);
+
+ log.info("loaded properties from: "+props);
+ }
+
+ protected void
+ ensureJetty()
+ {
+ // make a Jetty...
+ Jetty tmp = new Jetty(log.getCategory()); // tmp - until we have initialised
it...
+ tmp.setJettyHome(getJettyHome());
+ tmp.setWebDefault(getWebDefault());
+ tmp.setUnpackWars(getUnpackWars());
+
+ _jetty=tmp; // now we are initialised.
+
+ log.info("instantiated and configured server");
+ }
+
+ protected void
+ ensureConfig()
+ {
+ // this must be done before config is read otherwise configs
+ // defined therein will not receive MBean peers.
+ if (getPublishMBeans())
+ {
+ try
+ {
+ log.info("MBean peers WILL be created for Jetty Contexts");
+ _mbean = new JettyMBean(_jetty);
+ _server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server)));
+ }
+ catch (Throwable e)
+ {
+ log.error("JMX Registration problem", e);
+ }
+ }
+ else
+ {
+ log.info("MBean peers WILL NOT be created for Jetty Contexts");
+ }
+
+ _jetty.setConfiguration(_configuration);
+ }
+
+ protected void
+ ensureService()
+ throws Exception
+ {
+ ensureProperties();
+ ensureJetty();
+ ensureConfig();
+ }
+
+ //----------------------------------------------------------------------------
+ // 'name' interface
+ //----------------------------------------------------------------------------
+
+ public ObjectName
+ getObjectName(MBeanServer server, ObjectName name)
+ throws javax.management.MalformedObjectNameException
+ {
+ return new ObjectName(OBJECT_NAME);
+ }
+
+ public String
+ getName()
+ {
+ return NAME;
+ }
+
+ //----------------------------------------------------------------------------
+ // 'service' interface
+ //----------------------------------------------------------------------------
+
+ public void
+ initService()
+ throws Exception
+ {
+ if (!isInitialised())
+ {
+ super.initService();
+ try {ensureService();} catch (Exception e) {e.printStackTrace();}
+ }
+ else
+ log.warn("Jetty has already been initialised");
+ }
+
+ protected boolean _started=false;
+
+ public void
+ startService()
+ throws Exception
+ {
+ if (!isStarted())
+ {
+ super.startService();
+ _jetty.start();
+ _started=true;
+ }
+ else
+ log.warn("Jetty has already been started");
+ }
+
+ public void
+ stopService()
+ {
+ if (!isStopped())
+ {
+ super.stopService();
+ try
+ {
+ _jetty.stop();
+ }
+ catch (Exception e)
+ {
+ log.error("Could not stop Jetty", e);
+ }
+ _started=false;
+ }
+ else
+ log.warn("Jetty has already been stopped");
+ }
+
+ public void
+ destroyService()
+ {
+ if (!isDestroyed())
+ {
+ super.destroyService();
+ _jetty.destroy();
+ _jetty=null;
+ _mbean=null;
+ }
+ else
+ log.warn("Jetty has already been destroyed");
+ }
+
+ //----------------------------------------------------------------------------
+ // 'deploy' interface
+ //----------------------------------------------------------------------------
+
+ public WebApplication
+ performDeploy(String path, String warUrl, WebDescriptorParser parser)
+ throws DeploymentException
+ {
+ return _jetty.deploy(path, warUrl, parser);
+ }
+
+ public void
+ performUndeploy(String warUrl)
+ throws DeploymentException
+ {
+ _jetty.undeploy(warUrl);
+ }
+
+ //----------------------------------------------------------------------------
+
+ protected boolean
+ isInitialised()
+ {
+ 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;
+
+ public boolean
+ getPublishMBeans()
+ {
+ return _publishMBeans;
+ }
+
+ public void
+ setPublishMBeans(boolean publishMBeans)
+ {
+ log.info("set PublishMBeans to "+publishMBeans);
+
+ _publishMBeans=publishMBeans;
+ }
+
+ //----------------------------------------------------------------------------
+
+ protected boolean _unpackWars=false;
+
+ public boolean
+ getUnpackWars()
+ {
+ if (isInitialised())
+ return _jetty.getUnpackWars();
+ else
+ return _unpackWars;
+ }
+
+ public void
+ setUnpackWars(boolean unpackWars)
+ {
+ log.info("set UnpackWars to "+unpackWars);
+
+ if (isInitialised())
+ _jetty.setUnpackWars(unpackWars);
+ else
+ _unpackWars=unpackWars;
+ }
+
+ //----------------------------------------------------------------------------
+
+ protected String _webDefault=null;
+
+ public String
+ getWebDefault()
+ {
+ if (isInitialised())
+ return _jetty.getWebDefault();
+ else
+ return _webDefault;
+ }
+
+ public void
+ setWebDefault(String webDefault)
+ {
+ log.info("set WebDefault to "+webDefault);
+
+ if (isInitialised())
+ _jetty.setWebDefault(webDefault);
+ else
+ _webDefault=webDefault;
+ }
+
+ //----------------------------------------------------------------------------
+
+ protected String _configuration=null;
+
+ public String
+ getConfiguration()
+ {
+ if (isInitialised())
+ return _jetty.getConfiguration();
+ else
+ return _configuration;
+ }
+
+ public void
+ setConfiguration(String configUrl)
+ {
+ log.info("set Configuration to "+configUrl);
+
+ if (isInitialised())
+ _jetty.setConfiguration(configUrl);
+ else
+ _configuration=configUrl;
+ }
+
+ //----------------------------------------------------------------------------
+
+ protected static String _jettyHome=null;
+
+ public String
+ getJettyHome()
+ {
+ if (isInitialised())
+ return _jetty.getJettyHome();
+ else
+ return _jettyHome;
+ }
+
+ public void
+ setJettyHome(String jettyHome)
+ {
+ log.info("set JettyHome to "+jettyHome);
+
+ if (isInitialised())
+ _jetty.setJettyHome(jettyHome);
+ else
+ _jettyHome=jettyHome;
+ }
+}
1.5.2.2 +47 -47 contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java
Index: JettyServiceMBean.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- JettyServiceMBean.java 2001/09/15 13:14:59 1.5.2.1
+++ JettyServiceMBean.java 2001/12/02 02:08:53 1.5.2.2
@@ -1,47 +1,47 @@
-/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
-
-// $Id: JettyServiceMBean.java,v 1.5.2.1 2001/09/15 13:14:59 jules_gosnell Exp $
-
-package org.jboss.jetty;
-
-import org.jboss.ejb.DeploymentException;
-
-/**
- * <description>
- *
- * @see <related>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.5.2.1 $
- */
-public interface JettyServiceMBean
- extends org.jboss.web.AbstractWebContainerMBean
-{
-
- // Constants -----------------------------------------------------
- public static final String OBJECT_NAME = ":service=Jetty";
-
- // Public --------------------------------------------------------
-
- public void setConfiguration(String configUrl);
- public String getConfiguration();
-
- // public void setProperty(String property);
- // public String getProperty();
-
- public boolean getPublishMBeans();
- public void setPublishMBeans(boolean publishMBeans);
-
- public boolean getUnpackWars();
- public void setUnpackWars(boolean unpackWars);
-
- public String getWebDefault();
- public void setWebDefault(String webDefault);
-
- public void setJettyHome(String jettyHome);
- public String getJettyHome();
-}
+/*
+ * jBoss, the OpenSource EJB server
+ *
+ * Distributable under GPL license.
+ * See terms of license at gnu.org.
+ */
+
+// $Id: JettyServiceMBean.java,v 1.5.2.2 2001/12/02 02:08:53 starksm Exp $
+
+package org.jboss.jetty;
+
+import org.jboss.deployment.DeploymentException;
+
+/**
+ * <description>
+ *
+ * @see <related>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
+ * @version $Revision: 1.5.2.2 $
+ */
+public interface JettyServiceMBean
+ extends org.jboss.web.AbstractWebContainerMBean
+{
+
+ // Constants -----------------------------------------------------
+ public static final String OBJECT_NAME = ":service=Jetty";
+
+ // Public --------------------------------------------------------
+
+ public void setConfiguration(String configUrl);
+ public String getConfiguration();
+
+ // public void setProperty(String property);
+ // public String getProperty();
+
+ public boolean getPublishMBeans();
+ public void setPublishMBeans(boolean publishMBeans);
+
+ public boolean getUnpackWars();
+ public void setUnpackWars(boolean unpackWars);
+
+ public String getWebDefault();
+ public void setWebDefault(String webDefault);
+
+ public void setJettyHome(String jettyHome);
+ public String getJettyHome();
+}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development