User: jules_gosnell
Date: 01/08/09 13:57:22
Modified: jetty/src/main/org/jboss/jetty JBossLogSink.java
JBossUserRealm.java Jetty.java JettyService.java
SetupHandler.java
Added: jetty/src/main/org/jboss/jetty JettyMBean.java
JettyResolver.java
Log:
split README - it was getting too unwieldy
split out some inner classes into their own files
move logging properly onto Log4J
fix deployment into '/' context
general tidy up
Revision Changes Path
1.3 +71 -72 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JBossLogSink.java 2000/12/11 20:01:48 1.2
+++ JBossLogSink.java 2001/08/09 20:57:22 1.3
@@ -1,5 +1,5 @@
// ========================================================================
-// $Id: JBossLogSink.java,v 1.2 2000/12/11 20:01:48 jules Exp $
+// $Id: JBossLogSink.java,v 1.3 2001/08/09 20:57:22 jules_gosnell Exp $
// ========================================================================
/*
* jBoss, the OpenSource EJB server
@@ -10,29 +10,49 @@
package org.jboss.jetty;
+import com.mortbay.Util.Code;
+import com.mortbay.Util.Frame;
+import com.mortbay.Util.Log;
+import com.mortbay.Util.LogSink;
+import java.util.HashMap;
+import org.apache.log4j.Category;
+
/* ------------------------------------------------------------ */
-/** A Log sink.
- * This class represents both a concrete or abstract sink of
- * Log data. The default implementation logs to a PrintWriter, but
- * derived implementations may log to files, syslog, or other
- * logging APIs.
+
+/**
+ * This class bidges the API between Jetty and Log4J.
*
- * @see
- * @version $Id: JBossLogSink.java,v 1.2 2000/12/11 20:01:48 jules Exp $
- * @author Jules Gosnell (jules)
+ * @author <a href="mailto:">Jules Gosnell</a>
+ * @version $Id: JBossLogSink.java,v 1.3 2001/08/09 20:57:22 jules_gosnell Exp $
+ * @since 1.0
+ * @see com.mortbay.Util.LogSink
*/
public class JBossLogSink
- implements com.mortbay.Util.LogSink
+ implements LogSink
{
- org.jboss.logging.Log _log;
- boolean _started = false;
+ Category _log;
+ boolean _started = false;
+ HashMap _dispatch = new HashMap();
+ interface Logger {void log(String s);}
+
+ public
+ JBossLogSink()
+ {
+ // populate the dispatch map...
+ _dispatch.put(Log.DEBUG, new Logger(){public void log(String
s){_log.debug(s);}});
+ _dispatch.put(Log.EVENT, new Logger(){public void log(String
s){_log.info(s);}});
+ _dispatch.put(Log.WARN, new Logger(){public void log(String
s){_log.warn(s);}});
+ _dispatch.put(Log.ASSERT, new Logger(){public void log(String
s){_log.error(s);}});
+ _dispatch.put(Log.FAIL, new Logger(){public void log(String
s){_log.error(s);}});
+ }
+
// 'LifeCycle' interface
public void
initialize(Object log)
throws InterruptedException
{
- _log = (org.jboss.logging.Log) log;
+ _log = (Category) log;
}
public void
@@ -65,16 +85,20 @@
{
return (_log==null);
}
+
+ //----------------------------------------------------------------------
+ // Options interface - NYI - probably never will be...
+ //----------------------------------------------------------------------
- public void
- setOptions(String dateFormat,
- String timezone,
- boolean logTimeStamps,
- boolean logLabels,
- boolean logTags,
- boolean logStackSize,
- boolean logStackTrace,
- boolean logOneLine)
+ public void
+ setOptions(String dateFormat,
+ String timezone,
+ boolean logTimeStamps,
+ boolean logLabels,
+ boolean logTags,
+ boolean logStackSize,
+ boolean logStackTrace,
+ boolean logOneLine)
{
// is it possible to translate these into JBoss logging options...?
}
@@ -82,24 +106,24 @@
public void
setOptions(String logOptions)
{
-// setOptions((logOptions.indexOf(OPT_TIMESTAMP) >= 0),
-// (logOptions.indexOf(OPT_LABEL) >= 0),
-// (logOptions.indexOf(OPT_TAG) >= 0),
-// (logOptions.indexOf(OPT_STACKSIZE) >= 0),
-// (logOptions.indexOf(OPT_STACKTRACE) >= 0),
-// (logOptions.indexOf(OPT_ONELINE) >= 0));
+ // setOptions((logOptions.indexOf(OPT_TIMESTAMP) >= 0),
+ // (logOptions.indexOf(OPT_LABEL) >= 0),
+ // (logOptions.indexOf(OPT_TAG) >= 0),
+ // (logOptions.indexOf(OPT_STACKSIZE) >= 0),
+ // (logOptions.indexOf(OPT_STACKTRACE) >= 0),
+ // (logOptions.indexOf(OPT_ONELINE) >= 0));
}
public String
getOptions()
{
-// return
-// (_logTimeStamps?"t":"")+
-// (_logLabels?"L":"")+
-// (_logTags?"T":"")+
-// (_logStackSize?"s":"")+
-// (_logStackTrace?"S":"")+
-// (_logOneLine?"O":"");
+ // return
+ // (_logTimeStamps?"t":"")+
+ // (_logLabels?"L":"")+
+ // (_logTags?"T":"")+
+ // (_logStackSize?"s":"")+
+ // (_logStackTrace?"S":"")+
+ // (_logOneLine?"O":"");
return "";
}
@@ -114,40 +138,23 @@
* @param frame The frame that generated the message.
* @param time The time stamp of the message.
*/
- public void log(String tag,
- Object msg,
- com.mortbay.Util.Frame frame,
- long time)
+ public void
+ log(String tag, Object msg, Frame frame, long time)
{
- if (tag.equals(com.mortbay.Util.Log.WARN))
- {
- _log.warning(msg+(com.mortbay.Util.Code.debug()?", "+frame:""));
- return;
- }
- else if (tag.equals(com.mortbay.Util.Log.EVENT))
- {
- _log.log(msg+(com.mortbay.Util.Code.debug()?", "+frame:""));
- return;
- }
- else if (tag.equals(com.mortbay.Util.Log.DEBUG))
- {
- _log.debug(msg+(com.mortbay.Util.Code.debug()?", "+frame:""));
- return;
- }
- else if (tag.equals(com.mortbay.Util.Log.ASSERT))
+ boolean debugging=Code.debug();
+
+ Logger logger=(Logger)_dispatch.get(tag);
+ if (logger!=null)
{
- _log.error(msg+(com.mortbay.Util.Code.debug()?", "+frame:""));
- return;
+ logger.log(msg+(debugging?", "+frame:""));
}
- else if (tag.equals(com.mortbay.Util.Log.FAIL))
+ else
{
- _log.error(msg+(com.mortbay.Util.Code.debug()?", "+frame:""));
- return;
+ log(msg+" - "+tag+(debugging?", "+frame:""));
+ _log.warn("WARNING: JBossLogSink doesn't understand tag: '"+tag+"'");
}
-
- log(msg+" - "+tag+(com.mortbay.Util.Code.debug()?", "+frame:""));
}
-
+
/* ------------------------------------------------------------ */
/** Log a message.
* The formatted log string is written to the log sink. The default
@@ -157,14 +164,6 @@
public synchronized void
log(String formattedLog)
{
- _log.log(formattedLog);
+ _log.info(formattedLog);
}
};
-
-
-
-
-
-
-
-
1.4 +122 -101 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JBossUserRealm.java 2001/07/08 10:40:18 1.3
+++ JBossUserRealm.java 2001/08/09 20:57:22 1.4
@@ -1,128 +1,149 @@
package org.jboss.jetty;
-import java.util.HashSet;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
import com.mortbay.HTTP.HttpRequest;
import com.mortbay.HTTP.UserPrincipal;
import com.mortbay.HTTP.UserRealm;
-
+import java.util.HashSet;
+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.SimplePrincipal;
import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
import org.jboss.security.SubjectSecurityManager;
/** An implementation of UserRealm that integrates with the JBossSX security
manager associted with the web application.
* @author [EMAIL PROTECTED]
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public class JBossUserRealm implements UserRealm
+public class JBossUserRealm
+ implements UserRealm
{
- private String realmName;
+ private String _realmName;
+ private Category _log;
- class User extends SimplePrincipal implements UserPrincipal
- {
- HttpRequest request;
- User(String name, HttpRequest request)
- {
- super(name);
- this.request = request;
- }
-
- public boolean authenticate(String password)
- {
- boolean authenticated = false;
- String username = this.getName();
- // System.out.println("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( securityMgr.isValid(this, password) )
- {
- authenticated = true;
- request.setAttribute(UserPrincipal.__ATTR, this);
- System.out.println("User: "+username+" is authenticated");
- 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
- {
- System.out.println("User: "+username+" is NOT authenticated");
- }
- }
- catch(NamingException e)
- {
- System.err.println("Error during authenticate");
- e.printStackTrace();
- }
-
- return authenticated;
- }
- public boolean isUserInRole(String role)
- {
- boolean isUserInRole = false;
- String username = this.getName();
- // System.out.println("Authorizing access, username: " +
username + " " +request);
- try
- {
- // 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;
- System.out.println("User: "+username+" is authorized");
- }
- else
- {
- System.out.println("User: "+username+" is NOT authorized,
requiredRoles="+requiredRoles);
- }
- }
- catch(NamingException e)
- {
- System.err.println("Error during authorization");
- e.printStackTrace();
- }
- return isUserInRole;
- }
- public UserRealm getUserRealm()
- {
- return JBossUserRealm.this;
- }
- }
+ //----------------------------------------
- /** Creates new JBossUserRealm */
- public JBossUserRealm(String realmName)
+ class User
+ extends SimplePrincipal
+ implements UserPrincipal
+ {
+ HttpRequest _request;
+
+ User(String name, HttpRequest request)
{
- this.realmName = realmName;
- System.out.println("+++ Created JBossUserRealm, realmName="+realmName);
+ super(name);
+ _request = request;
}
-
- public String getName()
+
+ public boolean
+ authenticate(String password)
{
- return realmName;
+ boolean authenticated = false;
+ String username = this.getName(); // needs disambiguation
+
+ _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(securityMgr.isValid(this, password))
+ {
+ authenticated = true;
+ _request.setAttribute(UserPrincipal.__ATTR, this);
+
+ _log.info("User: "+username+" is authenticated");
+
+ 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
+ {
+ _log.info("User: "+username+" is NOT authenticated");
+ }
+ }
+ catch(NamingException e)
+ {
+ _log.error("Error during authenticate", e);
+ }
+
+ return authenticated;
}
+
+ public boolean
+ isUserInRole(String role)
+ {
+ boolean isUserInRole = false;
+ String username = this.getName();
- public UserPrincipal getUser(String username, HttpRequest request)
+ _log.info("Authorizing access, username: " + username/* + " " + _request*/);
+
+ try
+ {
+ // 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);
+ }
+ }
+ catch(NamingException e)
+ {
+ _log.error("Error during authorization", e);
+ }
+ return isUserInRole;
+ }
+
+ public UserRealm
+ getUserRealm()
{
- System.out.println("+++ JBossUserRealm.getUser, username="+username);
- return new User(username, request);
+ return JBossUserRealm.this;
}
+ }
+ //----------------------------------------
+
+ public
+ JBossUserRealm(Category log, String realmName)
+ {
+ _log = log;
+ _realmName = realmName;
+ _log.info("+++ Created JBossUserRealm, realmName="+_realmName);
+ }
+
+ public String
+ getName()
+ {
+ return _realmName;
+ }
+
+ public UserPrincipal
+ getUser(String username, HttpRequest request)
+ {
+ _log.info("+++ JBossUserRealm.getUser, username="+username);
+ return new User(username, request);
+ }
}
1.13 +32 -73 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Jetty.java 2001/07/08 10:43:52 1.12
+++ Jetty.java 2001/08/09 20:57:22 1.13
@@ -13,74 +13,28 @@
import com.mortbay.HTTP.HttpHandler;
import com.mortbay.Jetty.Servlet.WebApplicationContext;
-import com.mortbay.Util.Code;
-import com.mortbay.Util.Log;
import com.mortbay.Util.Resource;
-import com.mortbay.XML.XmlConfiguration;
-import com.mortbay.XML.XmlParser;
-
-import java.io.*;
+import java.io.FileNotFoundException;
import java.net.URL;
-import java.util.Hashtable;
-
+import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-
+import org.apache.log4j.Category;
import org.jboss.ejb.DeploymentException;
-
-import org.jboss.web.WebApplication;
import org.jboss.web.AbstractWebContainer.WebDescriptorParser;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-
-class JettyResolver
- implements EntityResolver
-{
- protected Hashtable _table=new Hashtable();
-
- public InputSource
- resolveEntity (String publicId, String systemId)
- {
- Log.event("resolving "+publicId+" : "+systemId);
-
- URL url=(URL)_table.get(publicId);
-
- if (url==null)
- {
- Log.event("no resolution for "+publicId);
- }
- else
- {
- Log.event("resolved "+publicId+" : "+url);
- try
- {
- InputSource is=new InputSource(url.openConnection().getInputStream());
- return is;
- }
- catch (IOException e)
- {
- Log.event("bad resolution "+publicId+" : "+url);
- }
- }
-
- return null;
- }
-
- public void
- put(String key, URL val)
- {
- _table.put(key, val);
- }
-}
+import org.jboss.web.WebApplication;
-class Jetty extends com.mortbay.Jetty.Server
+public class Jetty
+ extends com.mortbay.Jetty.Server
{
- JettyResolver _resolver=new JettyResolver();
+ Category _log;
+ JettyResolver _resolver;
- Jetty()
+ Jetty(Category log)
{
super();
+ _log=log;
+ _resolver=new JettyResolver(_log);
URL
stdWeb=findResourceInJar("com.mortbay.HTTP.HttpServer","com/mortbay/Jetty/Servlet/web.dtd");
_resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", stdWeb);
@@ -156,14 +110,14 @@
try
{
- com.mortbay.Util.Log.event("loading config: "+configUrl);
+ _log.info("loading config: "+configUrl);
configure(configUrl);
- com.mortbay.Util.Log.event("loaded config: "+configUrl);
+ _log.info("loaded config: "+configUrl);
_configuration=configUrl;
}
catch (Exception e)
{
- Log.event("problem loading configuration: "+configUrl);
+ _log.info("problem loading configuration: "+configUrl);
e.printStackTrace();
}
}
@@ -178,10 +132,10 @@
// 'deploy' interface
//----------------------------------------------------------------------------
- Hashtable _deployed = new Hashtable();
+ HashMap _deployed = new HashMap();
public WebApplication
- deploy(String path, String warUrl, WebDescriptorParser descriptorParser)
+ deploy(String contextPath, String warUrl, WebDescriptorParser descriptorParser)
throws DeploymentException
{
WebApplication wa=new WebApplication();
@@ -190,10 +144,13 @@
{
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
-
- String fixedPath=path+"/*";
- WebApplicationContext app=new WebApplicationContext(this, fixedPath);
+ WebApplicationContext app=new WebApplicationContext(this, contextPath);
wa.setAppData(app);
addContext(null, app);
@@ -229,26 +186,27 @@
}
catch (FileNotFoundException e)
{
- Log.event("no jboss-web.xml found");
+ _log.info("no jboss-web.xml found");
}
// Add a handler to perform the JBoss integration during start()
- HttpHandler handler = new SetupHandler(descriptorParser, wa);
+ 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.event("successfully deployed "+warUrl+" to "+path);
+ _log.info("successfully deployed "+warUrl+" to "+contextPath);
}
catch (Exception e)
{
- Log.event("problem deploying "+warUrl+" to "+path);
+ _log.info("problem deploying "+warUrl+" to "+contextPath);
e.printStackTrace();
throw new DeploymentException(e.getMessage());
}
@@ -268,14 +226,15 @@
app.stop();
removeContext(app);
+ app.destroy();
_deployed.remove(warUrl);
- Log.event("successfully undeployed "+warUrl);
+ _log.info("successfully undeployed "+warUrl);
}
catch (Exception e)
{
- Log.event("problem undeploying "+warUrl);
+ _log.info("problem undeploying "+warUrl);
throw new DeploymentException(e.getMessage());
}
}
@@ -290,7 +249,7 @@
// Utils
//----------------------------------------------------------------------------
- static public URL
+ public URL
findResourceInJar(String sibling, String name)
{
URL url=null;
@@ -302,7 +261,7 @@
}
catch (Exception e)
{
- Log.event("Could not find resource: "+name);
+ _log.info("Could not find resource: "+name);
}
return url;
1.19 +62 -98 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JettyService.java 2001/07/08 10:47:23 1.18
+++ JettyService.java 2001/08/09 20:57:22 1.19
@@ -7,97 +7,51 @@
package org.jboss.jetty;
-import java.net.URL;
+import com.mortbay.HTTP.HandlerContext;
+import com.mortbay.HTTP.HttpServer;
+import com.mortbay.Jetty.JMX.HttpServerMBean;
+import com.mortbay.Jetty.Servlet.WebApplicationContext;
+import com.mortbay.Util.Log;
+import com.mortbay.XML.XmlConfiguration;
import java.io.File;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.util.Hashtable;
import java.util.Vector;
-
-import javax.management.*;
-
-import org.jboss.web.AbstractWebContainer;
+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.jboss.logging.Log;
-import org.jboss.logging.Logger;
-import org.jboss.util.ServiceMBeanSupport;
-import org.jboss.ejb.DeploymentException;
-import com.mortbay.HTTP.HttpServer;
-import com.mortbay.HTTP.HandlerContext;
-import com.mortbay.Jetty.Servlet.WebApplicationContext;
-import com.mortbay.XML.XmlConfiguration;
-
-import com.mortbay.Jetty.JMX.HttpServerMBean;
-
/**
* A service to launch jetty from JMX.
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a>
- * @version $Revision: 1.18 $
+ * @version $Revision: 1.19 $
*/
-class JettyMBean extends HttpServerMBean
-{
- public JettyMBean(Jetty jetty)
- throws MBeanException, InstanceNotFoundException
- {
- super(jetty);
- }
-
- protected String
- newObjectName(MBeanServer server)
- {
- return super.newObjectName(server);
- }
- // protected String
- // newObjectName(String prefix, MBeanServer server)
- // {
- // return uniqueObjectName(server, prefix);
- // }
-}
-
-class JettyLog extends Log
-{
- Object _source=null; // should really be in same package as Log
-
- public
- JettyLog()
- {
- super();
- }
-
- public
- JettyLog(Object source)
- {
- super(source);
- _source=source; // hack
- }
-
- public void
- log(String type, String message)
- {
- Logger.getLogger().fireNotification(type, _source, message);
- }
-}
-
// NOTES
-// Logging is in serious need of tidying up...
-// I could parameterise the properties file - do we still need it - shouldn't it
use MLET ?
+// I could parameterise the properties file - do we still need it -
+// shouldn't it use MLET ?
-public class JettyService extends AbstractWebContainer
+public class JettyService
+ extends AbstractWebContainer
implements JettyServiceMBean, MBeanRegistration
{
public static final String NAME = "Jetty";
- Log _log = new JettyLog(getName());
- JBossLogSink _logSink = new JBossLogSink();
- JettyMBean _mbean = null;
- Jetty _jetty = null;
- MBeanServer _server = null;
+ Category _log =
Category.getInstance(super.category.getName()+"."+getName());
+ JettyMBean _mbean = null;
+ Jetty _jetty = null;
+ MBeanServer _server = null;
public
JettyService()
@@ -125,12 +79,27 @@
protected void
ensureLogging()
{
- try{_logSink.initialize(_log);}catch(Exception e){e.printStackTrace();}
- _logSink.start();
- com.mortbay.Util.Log.instance().disableLog(); // remove default logger
- com.mortbay.Util.Log.instance().add(_logSink);
+ // sort out a JBossLogSink for use by Jetty. This will bridge the
+ // API between Jetty and Log4J...
- com.mortbay.Util.Log.event("connected JBoss and Jetty Log models");
+ 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
@@ -145,26 +114,21 @@
System.getProperties().load(propertiesIn);
- com.mortbay.Util.Log.event("loaded properties from: "+props);
+ _log.info("loaded properties from: "+props);
}
protected void
ensureJetty()
{
// make a Jetty...
- Jetty jetty = new Jetty(); // tmp - until we have initialised it...
-
- jetty.setJettyHome(getJettyHome());
- jetty.setWebDefault(getWebDefault());
- jetty.setUnpackWars(getUnpackWars());
-
- _jetty=jetty; // now we are initialised.
+ Jetty tmp = new Jetty(_log); // tmp - until we have initialised it...
+ tmp.setJettyHome(getJettyHome());
+ tmp.setWebDefault(getWebDefault());
+ tmp.setUnpackWars(getUnpackWars());
- com.mortbay.Util.Log.event("instantiated and configured server");
+ _jetty=tmp; // now we are initialised.
- // unset log for the main thread.
- // tomcat's child threads have a copy of it anyway.
- Log.unsetLog();
+ _log.info("instantiated and configured server");
}
protected void
@@ -176,7 +140,7 @@
{
try
{
- com.mortbay.Util.Log.event("MBean peers WILL be created for Jetty Contexts");
+ _log.info("MBean peers WILL be created for Jetty Contexts");
_mbean = new JettyMBean(_jetty);
_server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server)));
}
@@ -191,7 +155,7 @@
}
else
{
- com.mortbay.Util.Log.event("MBean peers WILL NOT be created for Jetty
Contexts");
+ _log.info("MBean peers WILL NOT be created for Jetty Contexts");
}
_jetty.setConfiguration(_configuration);
@@ -237,7 +201,7 @@
try {ensureService();} catch (Exception e) {e.printStackTrace();}
}
else
- com.mortbay.Util.Log.warning("Jetty has already been initialised");
+ _log.warn("Jetty has already been initialised");
}
protected boolean _started=false;
@@ -253,7 +217,7 @@
_started=true;
}
else
- com.mortbay.Util.Log.warning("Jetty has already been started");
+ _log.warn("Jetty has already been started");
}
public void
@@ -266,7 +230,7 @@
_started=false;
}
else
- com.mortbay.Util.Log.warning("Jetty has already been stopped");
+ _log.warn("Jetty has already been stopped");
}
public void
@@ -280,7 +244,7 @@
_mbean=null;
}
else
- com.mortbay.Util.Log.warning("Jetty has already been destroyed");
+ _log.warn("Jetty has already been destroyed");
}
//----------------------------------------------------------------------------
@@ -340,7 +304,7 @@
public void
setPublishMBeans(boolean publishMBeans)
{
- com.mortbay.Util.Log.event("set PublishMBeans to "+publishMBeans);
+ _log.info("set PublishMBeans to "+publishMBeans);
_publishMBeans=publishMBeans;
}
@@ -361,7 +325,7 @@
public void
setUnpackWars(boolean unpackWars)
{
- com.mortbay.Util.Log.event("set UnpackWars to "+unpackWars);
+ _log.info("set UnpackWars to "+unpackWars);
if (isInitialised())
_jetty.setUnpackWars(unpackWars);
@@ -385,7 +349,7 @@
public void
setWebDefault(String webDefault)
{
- com.mortbay.Util.Log.event("set WebDefault to "+webDefault);
+ _log.info("set WebDefault to "+webDefault);
if (isInitialised())
_jetty.setWebDefault(webDefault);
@@ -409,7 +373,7 @@
public void
setConfiguration(String configUrl)
{
- com.mortbay.Util.Log.event("set Configuration to "+configUrl);
+ _log.info("set Configuration to "+configUrl);
if (isInitialised())
_jetty.setConfiguration(configUrl);
@@ -433,7 +397,7 @@
public void
setJettyHome(String jettyHome)
{
- com.mortbay.Util.Log.event("set JettyHome to "+jettyHome);
+ _log.info("set JettyHome to "+jettyHome);
if (isInitialised())
_jetty.setJettyHome(jettyHome);
1.5 +57 -46 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SetupHandler.java 2001/06/13 23:02:57 1.4
+++ SetupHandler.java 2001/08/09 20:57:22 1.5
@@ -1,60 +1,71 @@
package org.jboss.jetty;
-import java.io.IOException;
-
-import org.w3c.dom.Element;
-
+import com.mortbay.HTTP.Handler.NullHandler;
import com.mortbay.HTTP.HandlerContext;
import com.mortbay.HTTP.HttpException;
import com.mortbay.HTTP.HttpRequest;
import com.mortbay.HTTP.HttpResponse;
import com.mortbay.HTTP.HttpServer;
-import com.mortbay.HTTP.Handler.NullHandler;
-
-import org.jboss.web.WebApplication;
+import java.io.IOException;
+import org.apache.log4j.Category;
import org.jboss.web.AbstractWebContainer.WebDescriptorParser;
+import org.jboss.web.WebApplication;
+import org.w3c.dom.Element;
-/** An HttpHandler that simply hooks into the web application startup so that
-is sees the correct class loader and security realm name.
+/** 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.4 $
+ * @version $Revision: 1.5 $
*/
-public class SetupHandler extends NullHandler
+public class SetupHandler
+ extends NullHandler
{
- WebDescriptorParser descriptorParser;
- WebApplication webApp;
-
- /** Creates new SetupHandler */
- public SetupHandler(WebDescriptorParser descriptorParser, WebApplication webApp)
- {
- this.descriptorParser = descriptorParser;
- this.webApp = webApp;
- }
-
- /* ------------------------------------------------------------ */
- public void start() throws Exception
- {
- ClassLoader loader = getHandlerContext().getClassLoader();
- if (webApp.getClassLoader()!=loader.getParent())
- com.mortbay.Util.Code.warning("WebApp ClassLoader is not child of
J2EEDeployer's ClassLoader");
-
- // 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(realmName));
-
- super.start();
- }
-
- public void handle(String pathInContext, HttpRequest request, HttpResponse
response)
- throws HttpException, IOException
- {
- }
-
+ 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();
+ if (_webApp.getClassLoader()!=loader.getParent())
+ _log.warn("WARNING: WebApp ClassLoader is not child of J2EEDeployer's
ClassLoader");
+
+ // 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 start()...
+
+ public void
+ handle(String pathInContext, HttpRequest request, HttpResponse response)
+ throws HttpException, IOException
+ {
+ }
}
1.1 contrib/jetty/src/main/org/jboss/jetty/JettyMBean.java
Index: JettyMBean.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jetty;
import com.mortbay.Jetty.JMX.HttpServerMBean;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
public class JettyMBean
extends HttpServerMBean
{
public JettyMBean(Jetty jetty)
throws MBeanException, InstanceNotFoundException
{
super(jetty);
}
protected String
newObjectName(MBeanServer server)
{
//return super.newObjectName(server);
return uniqueObjectName(server, "Jetty"+":");
}
}
1.1 contrib/jetty/src/main/org/jboss/jetty/JettyResolver.java
Index: JettyResolver.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jetty;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import org.apache.log4j.Category;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
public class JettyResolver
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);
}
else
{
_log.info("resolved "+publicId+" : "+url);
try
{
InputSource is=new InputSource(url.openConnection().getInputStream());
return is;
}
catch (IOException e)
{
_log.info("bad resolution "+publicId+" : "+url);
}
}
return null;
}
public void
put(String key, URL val)
{
_map.put(key, val);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development