User: lepe
Date: 01/07/21 01:55:46
Modified: src/main/org/jboss/web Tag: Branch_2_4 WebServer.java
Log:
Implemented log4j partly of what Scott did in main branch.
Since JBossCategory is not available in 2.4 both trace() and debug()
are sent to category.debug().
Revision Changes Path
No revision
No revision
1.5.4.3 +16 -10 jboss/src/main/org/jboss/web/WebServer.java
Index: WebServer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/WebServer.java,v
retrieving revision 1.5.4.2
retrieving revision 1.5.4.3
diff -u -r1.5.4.2 -r1.5.4.3
--- WebServer.java 2001/07/03 08:04:20 1.5.4.2
+++ WebServer.java 2001/07/21 08:55:46 1.5.4.3
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Properties;
+import org.apache.log4j.Category;
/**
* A mini webserver that should be embedded in another application. It can server
any file that is available from
* classloaders that are registered with it, including class-files.
@@ -34,11 +35,15 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
- * @version $Revision: 1.5.4.2 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Lennart Petersson</a>.
+ * @version $Revision: 1.5.4.3 $
*
* Revisions:
*
* 20010618 scott.stark: Fixed extraction of mime-type from file extension in
getMimeType
+ * 20010721 lennart.petersson: Implemented log4j partly of what Scott did in main
branch.
+ * Since JBossCategory is not available in 2.4 both
trace() and
+ * debug() are sent to category.debug().
*/
public class WebServer
implements Runnable
@@ -46,6 +51,7 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+ private static Category category = Category.getInstance(WebServer.class);
/** The port the web server listens on */
private int port = 8080;
/** The map of class loaders registered with the web server */
@@ -217,8 +223,8 @@
int separator = rawPath.indexOf('/');
String filePath = rawPath.substring(separator+1);
String loaderKey = rawPath.substring(0, separator+1);
- trace("WebServer: loaderKey = "+loaderKey);
- trace("WebServer: filePath = "+filePath);
+ trace("loaderKey = "+loaderKey);
+ trace("filePath = "+filePath);
ClassLoader loader = (ClassLoader) loaderMap.get(loaderKey);
/* If we did not find a class loader check to see if the raw path
begins with className + '@' + cl.hashCode() + '/' by looking for
@@ -232,16 +238,16 @@
loader = Thread.currentThread().getContextClassLoader();
}
- trace("WebServer: loader = "+loader);
+ trace("loader = "+loader);
byte[] bytes;
if( filePath.endsWith(".class") )
{
// A request for a class file
String className = filePath.substring(0,
filePath.length()-6).replace('/','.');
- trace("WebServer: loading className = "+className);
+ trace("loading className = "+className);
Class clazz = loader.loadClass(className);
URL clazzUrl =
clazz.getProtectionDomain().getCodeSource().getLocation();
- trace("WebServer: clazzUrl = "+clazzUrl);
+ trace("clazzUrl = "+clazzUrl);
if (clazzUrl.getFile().endsWith(".jar"))
clazzUrl = new URL("jar:"+clazzUrl+"!/"+filePath);
else
@@ -255,7 +261,7 @@
else // Resource
{
// Try getting resource
- trace("WebServer: loading resource = "+filePath);
+ trace("loading resource = "+filePath);
URL resourceUrl = loader.getResource(filePath);
if (resourceUrl == null)
throw new FileNotFoundException("Resource not
found:"+filePath);
@@ -330,11 +336,11 @@
protected void trace(String msg)
{
- System.out.println(msg);
+ category.debug(msg);
}
protected void debug(String msg)
{
- System.out.println(msg);
+ category.debug(msg);
}
protected void listen()
@@ -348,7 +354,7 @@
protected String getPath(BufferedReader in) throws IOException
{
String line = in.readLine();
- debug("WebServer: raw path="+line);
+ trace("raw request="+line);
// Find the request path by parsing the 'REQUEST_TYPE filePath
HTTP_VERSION' string
int start = line.indexOf(' ')+1;
int end = line.indexOf(' ', start+1);
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development