User: starksm 
  Date: 01/09/20 10:53:43

  Modified:    src/main/org/jboss/web Tag: Branch_2_4 WebServer.java
  Log:
  Don't display resource for a request for /
  Only load resources and classes from the thread context class loader if
  downloadServerClasses is true
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.5.4.5   +23 -13    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.4
  retrieving revision 1.5.4.5
  diff -u -r1.5.4.4 -r1.5.4.5
  --- WebServer.java    2001/08/20 22:12:53     1.5.4.4
  +++ WebServer.java    2001/09/20 17:53:43     1.5.4.5
  @@ -38,7 +38,7 @@
    *
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - *   @version $Revision: 1.5.4.4 $
  + *   @version $Revision: 1.5.4.5 $
    *
    *   Revisions:
    *   
  @@ -260,6 +260,7 @@
               DataOutputStream out = new DataOutputStream(socket.getOutputStream());
               try 
               {
  +               String httpCode = "200 OK";
                   // Get the requested item from the HTTP header
                   BufferedReader in = new BufferedReader(new 
InputStreamReader(socket.getInputStream()));
                   String rawPath = getPath(in);
  @@ -275,15 +276,15 @@
                    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 )
  +                if( loader == null && rawPath.indexOf('@') < 0 && 
downloadServerClasses )
                   {
                      filePath = rawPath;
                      category.trace("No loader, reset filePath = "+filePath);
                      loader = Thread.currentThread().getContextClassLoader();
                   }
                   category.trace("loader = "+loader);
  -                byte[] bytes;
  -                if( filePath.endsWith(".class") )
  +                byte[] bytes = {};
  +                if( loader != null && filePath.endsWith(".class") )
                   {
                       // A request for a class file
                       String className = filePath.substring(0, 
filePath.length()-6).replace('/','.');
  @@ -301,23 +302,31 @@
                       // Retrieve bytecodes
                       bytes = getBytes(clazzUrl);
                   }
  -                else // Resource
  +                else if( loader != null && filePath.length() > 0 && 
downloadServerClasses )
                   {
                       // Try getting resource
                       category.trace("loading resource = "+filePath);
  -                    URL resourceUrl = loader.getResource(filePath);             
  -                    if (resourceUrl == null)
  -                        throw new FileNotFoundException("Resource not 
found:"+filePath);
  -
  -                    // Retrieve bytes
  -                    bytes = getBytes(resourceUrl);
  +                    URL resourceURL = loader.getResource(filePath);             
  +                    if (resourceURL == null)
  +                        httpCode = "404 Resource not found:"+filePath;
  +                    else
  +                    {
  +                       // Retrieve bytes
  +                       category.trace("resourceURL = "+resourceURL);
  +                       bytes = getBytes(resourceURL);
  +                    }
  +                }
  +                else
  +                {
  +                   httpCode = "404 Not Found";
                   }
   
                   // Send bytecodes/resource data in response (assumes HTTP/1.0 or 
later)
                   try 
                   {
  +                    category.trace("HTTP code="+httpCode+", Content-Length: " + 
bytes.length);
                       // The HTTP 1.0 header
  -                    out.writeBytes("HTTP/1.0 200 OK\r\n");
  +                    out.writeBytes("HTTP/1.0 "+httpCode+"\r\n");
                       out.writeBytes("Content-Length: " + bytes.length + "\r\n");
                       out.writeBytes("Content-Type: "+getMimeType(filePath));
                       out.writeBytes("\r\n\r\n");
  @@ -334,8 +343,9 @@
               {
                   try
                   {
  +                   category.trace("HTTP code=404 " + e.getMessage());
                      // Write out error response
  -                   out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n");
  +                   out.writeBytes("HTTP/1.0 404 " + e.getMessage() + "\r\n");
                      out.writeBytes("Content-Type: text/html\r\n\r\n");
                      out.flush();
                   } catch (IOException ex)
  
  
  

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

Reply via email to