[jboss-cvs] JBossAS SVN: r99507 - trunk/server/src/main/java/org/jboss/web.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 16 09:45:15 EST 2010


Author: bstansberry at jboss.com
Date: 2010-01-16 09:45:15 -0500 (Sat, 16 Jan 2010)
New Revision: 99507

Modified:
   trunk/server/src/main/java/org/jboss/web/WebServer.java
Log:
[JBAS-7626] Set the TCL

Modified: trunk/server/src/main/java/org/jboss/web/WebServer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/WebServer.java	2010-01-16 05:18:08 UTC (rev 99506)
+++ trunk/server/src/main/java/org/jboss/web/WebServer.java	2010-01-16 14:45:15 UTC (rev 99507)
@@ -34,9 +34,12 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URL;
+import java.security.AccessController;
 import java.util.Properties;
 import java.util.concurrent.Executor;
 import org.jboss.logging.Logger;
+import org.jboss.util.loading.ContextClassLoaderSwitcher;
+import org.jboss.util.loading.ContextClassLoaderSwitcher.SwitchContext;
 
 /**
  * A mini webserver that should be embedded in another application. It can
@@ -111,7 +114,17 @@
     * The thread pool used to manage listening threads
     */
    private Executor executor;
+   
+   private final ContextClassLoaderSwitcher tclSwitcher;
+   
+   // Constructors --------------------------------------------------
 
+   public WebServer()
+   {
+      @SuppressWarnings("unchecked")
+      ContextClassLoaderSwitcher clSwitcher = (ContextClassLoaderSwitcher) AccessController.doPrivileged(ContextClassLoaderSwitcher.INSTANTIATOR);
+      this.tclSwitcher = clSwitcher;
+   }
    // Public --------------------------------------------------------
 
    /**
@@ -368,56 +381,68 @@
             }
             log.trace("loader = " + loader);
             byte[] bytes = {};
-            if (loader != null && filePath.endsWith(".class"))
+            SwitchContext tclSwitchContext = null; 
+            try
             {
-               // A request for a class file
-               String className = filePath.substring(0, filePath.length() - 6).replace('/', '.');
-               log.trace("loading className = " + className);
-               Class clazz = loader.loadClass(className);
-               URL clazzUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
-               log.trace("clazzUrl = " + clazzUrl);
-               if (clazzUrl == null)
+               tclSwitchContext = this.tclSwitcher.getSwitchContext(this.getClass().getClassLoader());
+               if (loader != null && filePath.endsWith(".class"))
                {
-                  // Does the WebClassLoader of clazz
-                  // have the ability to obtain the bytecodes of clazz?
-                  bytes = ((WebClassLoader) clazz.getClassLoader()).getBytes(clazz);
-                  if (bytes == null)
-                     throw new Exception("Class not found: " + className);
-               }
-               else
-               {
-                  if (clazzUrl.getFile().endsWith("/") == false)
+                  // A request for a class file
+                  String className = filePath.substring(0, filePath.length() - 6).replace('/', '.');
+                  log.trace("loading className = " + className);
+                  Class<?> clazz = loader.loadClass(className);
+                  URL clazzUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
+                  log.trace("clazzUrl = " + clazzUrl);
+                  if (clazzUrl == null)
                   {
-                     clazzUrl = new URL("jar:" + clazzUrl + "!/" + filePath);
+                     // Does the WebClassLoader of clazz
+                     // have the ability to obtain the bytecodes of clazz?
+                     bytes = ((WebClassLoader) clazz.getClassLoader()).getBytes(clazz);
+                     if (bytes == null)
+                        throw new Exception("Class not found: " + className);
                   }
-                  // this is a hack for the AOP ClassProxyFactory
-                  else if (clazzUrl.getFile().indexOf("/org_jboss_aop_proxy$") < 0)
+                  else
                   {
-                     clazzUrl = new URL(clazzUrl, filePath);
+                     if (clazzUrl.getFile().endsWith("/") == false)
+                     {
+                        clazzUrl = new URL("jar:" + clazzUrl + "!/" + filePath);
+                     }
+                     // this is a hack for the AOP ClassProxyFactory
+                     else if (clazzUrl.getFile().indexOf("/org_jboss_aop_proxy$") < 0)
+                     {
+                        clazzUrl = new URL(clazzUrl, filePath);
+                     }
+   
+                     // Retrieve bytecodes
+                     log.trace("new clazzUrl: " + clazzUrl);
+                     bytes = getBytes(clazzUrl);
                   }
-
-                  // Retrieve bytecodes
-                  log.trace("new clazzUrl: " + clazzUrl);
-                  bytes = getBytes(clazzUrl);
                }
-            }
-            else if (loader != null && filePath.length() > 0 && downloadServerClasses && downloadResources)
-            {
-               // Try getting resource
-               log.trace("loading resource = " + filePath);
-               URL resourceURL = loader.getResource(filePath);
-               if (resourceURL == null)
-                  httpCode = "404 Resource not found:" + filePath;
+               else if (loader != null && filePath.length() > 0 && downloadServerClasses && downloadResources)
+               {
+                  // Try getting resource
+                  log.trace("loading resource = " + filePath);
+                  URL resourceURL = loader.getResource(filePath);
+                  if (resourceURL == null)
+                     httpCode = "404 Resource not found:" + filePath;
+                  else
+                  {
+                     // Retrieve bytes
+                     log.trace("resourceURL = " + resourceURL);
+                     bytes = getBytes(resourceURL);
+                  }
+               }
                else
                {
-                  // Retrieve bytes
-                  log.trace("resourceURL = " + resourceURL);
-                  bytes = getBytes(resourceURL);
+                  httpCode = "404 Not Found";
                }
             }
-            else
+            finally
             {
-               httpCode = "404 Not Found";
+               if (tclSwitchContext != null)
+               {
+                  tclSwitchContext.reset();
+               }
             }
 
 
@@ -454,6 +479,10 @@
                // Ignore
             }
          }
+         finally
+         {
+            
+         }
       }
       catch (IOException ex)
       {




More information about the jboss-cvs-commits mailing list