User: starksm 
  Date: 01/06/27 21:08:13

  Modified:    src/main/org/jboss/web WebServer.java WebService.java
                        WebServiceMBean.java
  Log:
  Restore ability to download from the server classpath if no loader key is found
  amd downloadServerClasses is true.
  
  Added downloadServerClasses attribute to WebServiceMBean
  
  Revision  Changes    Path
  1.9       +48 -22    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WebServer.java    2001/06/20 04:04:49     1.8
  +++ WebServer.java    2001/06/28 04:08:13     1.9
  @@ -36,32 +36,38 @@
    *
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - *   @version $Revision: 1.8 $
  + *   @version $Revision: 1.9 $
    *
    *   Revisions:
    *   
    *   20010619 scott.stark: Use log4j JBossCategory to enable trace level msgs
    *   20010618 scott.stark: Fixed extraction of mime-type from file extension in 
getMimeType
  + *   20010627 scott.stark: Restore ability to download from the server classpath if 
no loader key is found
  +      amd downloadServerClasses is true
    */
   public class WebServer
        implements Runnable
   {
  -    // Constants -----------------------------------------------------
  +   // Constants -----------------------------------------------------
   
  -    // Attributes ----------------------------------------------------
  +   // Attributes ----------------------------------------------------
      private static JBossCategory category = 
(JBossCategory)JBossCategory.getInstance(WebServer.class);
  -    /** The port the web server listens on */
  -    private int port = 8080;
  -    /** The map of class loaders registered with the web server */
  -    private HashMap loaderMap = new HashMap();
  -    /** The web server http listening socket */
  -    private ServerSocket server = null;
  -
  -    /** The class wide mapping of type suffixes(class, txt) to their mime
  -     type string used as the Content-Type header for the vended classes/resources */
  -    private static Properties mimeTypes = new Properties();
  -    /** The thread pool used to manage listening threads */
  -    private ThreadPool threadPool = new ThreadPool();
  +   /** The port the web server listens on */
  +   private int port = 8080;
  +   /** The map of class loaders registered with the web server */
  +   private HashMap loaderMap = new HashMap();
  +   /** The web server http listening socket */
  +   private ServerSocket server = null;
  +   /** A flag indicating if the server should attempt to download classes from
  +    thread context class loader when a request arrives that does not have a
  +    class loader key prefix.
  +    */
  +   private boolean downloadServerClasses = true;
  +   /** The class wide mapping of type suffixes(class, txt) to their mime
  +   type string used as the Content-Type header for the vended classes/resources */
  +   private static Properties mimeTypes = new Properties();
  +   /** The thread pool used to manage listening threads */
  +   private ThreadPool threadPool = new ThreadPool();
   
      // Public --------------------------------------------------------
       /** Set the http listening port
  @@ -78,6 +84,15 @@
           return port; 
       }
   
  +   public boolean getDownloadServerClasses()
  +   {
  +      return downloadServerClasses;
  +   }
  +   public void setDownloadServerClasses(boolean flag)
  +   {
  +      downloadServerClasses = flag;
  +   }
  +
       /** Augment the type suffix to mime type mappings
        @param extension, the type extension without a
           period(class, txt)
  @@ -214,19 +229,30 @@
                   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);
  -                trace("WebServer: loader = "+loader);
  +                /* If we did not find a class loader check to see if the raw path
  +                 begins with className + '@' + cl.hashCode() + '/' by looking for
  +                 an '@' char. If it does not and downloadServerClasses is true use
  +                 the thread context class loader and set filePath to the rawPath
  +                */
  +                if( loader == null && rawPath.indexOf('@') < 0 )
  +                {
  +                   filePath = rawPath;
  +                   trace("No loader, reset filePath = "+filePath);
  +                   loader = Thread.currentThread().getContextClassLoader();
  +                }
  +                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
  @@ -240,7 +266,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);
  @@ -333,7 +359,7 @@
       protected String getPath(BufferedReader in) throws IOException
       {
           String line = in.readLine();
  -        trace("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);
  
  
  
  1.6       +15 -1     jboss/src/main/org/jboss/web/WebService.java
  
  Index: WebService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/WebService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WebService.java   2001/06/18 20:01:29     1.5
  +++ WebService.java   2001/06/28 04:08:13     1.6
  @@ -24,7 +24,7 @@
   
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>.
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - *   @version $Revision: 1.5 $
  + *   @version $Revision: 1.6 $
    */
   public class WebService
      extends ServiceMBeanSupport
  @@ -124,6 +124,20 @@
      {
        return server.getPort();
      }
  + 
  +   /** A flag indicating if the server should attempt to download classes from
  +    * thread context class loader when a request arrives that does not have a
  +    * class loader key prefix.
  +    */
  +   public boolean getDownloadServerClasses()
  +   {
  +      return server.getDownloadServerClasses();
  +   }
  +   public void setDownloadServerClasses(boolean flag)
  +   {
  +      server.setDownloadServerClasses(flag);
  +   }
  +   
      // Protected -----------------------------------------------------
   }
   
  
  
  
  1.5       +7 -1      jboss/src/main/org/jboss/web/WebServiceMBean.java
  
  Index: WebServiceMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/web/WebServiceMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WebServiceMBean.java      2001/06/18 20:01:29     1.4
  +++ WebServiceMBean.java      2001/06/28 04:08:13     1.5
  @@ -14,7 +14,7 @@
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>.
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    */
   public interface WebServiceMBean
      extends org.jboss.util.ServiceMBean
  @@ -30,4 +30,10 @@
        public void setPort(int port);
        
      public int getPort();
  +   /** A flag indicating if the server should attempt to download classes from
  +    thread context class loader when a request arrives that does not have a
  +    class loader key prefix.
  +    */
  +   public boolean getDownloadServerClasses();
  +   public void setDownloadServerClasses(boolean flag);
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to