[Red5commits] [red5 commit] r3504 - in java/server/branches/dominick_multithreaded_application_adapter: . src/org/red5/classl...

codesite-noreply at google.com codesite-noreply at google.com
Tue Feb 3 00:28:05 PST 2009


Author: mondain
Date: Mon Feb  2 23:55:15 2009
New Revision: 3504

Modified:
    java/server/branches/dominick_multithreaded_application_adapter/build.xml
     
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ChildFirstClassLoader.java
     
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ClassLoaderBuilder.java
     
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/Bootstrap.java
     
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/api/Red5.java
     
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/tomcat/TomcatLoader.java

Log:
Fixed the classloader problems (exposed by spring security). This change is  
not on trunk and is targeted for RC3.

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/build.xml
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/build.xml	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/build.xml	 
Mon Feb  2 23:55:15 2009
@@ -526,6 +526,10 @@
  	<target name="jar" description="Make Archive"  
depends="jar-determine-classpath">
  		<jar destfile="${red5.filename}.jar">
  			<fileset dir="${classes.dir}">
+				<exclude name="**/org/red5/server/Bootstrap.class"/>
+				<exclude name="**/org/red5/server/Shutdown.class"/>
+                <exclude name="**/org/red5/server/LoaderMBean"/>
+				<exclude name="**/org/red5/classloading/**"/>
  				<include name="**/org/**"/>
  				<include name="**/META-INF**"/>
  			</fileset>
@@ -533,13 +537,31 @@
  				<attribute name="Red5-Version" value="${red5.version}"/>
  				<attribute name="Built-By" value="${red5.fullname}"/>
  				<attribute name="Built-On" value="${build.TODAY}"/>
+			</manifest>
+			<metainf dir="${src.dir}/META-INF">
+				<include name="**"/>
+			</metainf>
+		</jar>
+		<!-- Bootstrap, Shutdown, and classloaders -->
+		<jar destfile="boot.jar">
+			<fileset dir="${classes.dir}">
+				<include name="**/org/red5/server/Bootstrap.class"/>
+				<include name="**/org/red5/server/Shutdown.class"/>
+                <include name="**/org/red5/server/LoaderMBean"/>
+				<include name="**/org/red5/classloading/**"/>
+				<include name="**/META-INF**"/>
+			</fileset>
+			<manifest>
+				<attribute name="Red5-Version" value="${red5.version}"/>
+				<attribute name="Built-By" value="${red5.fullname}"/>
+				<attribute name="Built-On" value="${build.TODAY}"/>
  				<attribute name="Main-Class" value="org.red5.server.Bootstrap"/>
  				<attribute name="Class-Path" value="${jar.classpath}"/>
  			</manifest>
  			<metainf dir="${src.dir}/META-INF">
  				<include name="**"/>
  			</metainf>
-		</jar>
+		</jar>		
  	</target>

  	<target name="dist" description="Create binary distribution"  
depends="jar">
@@ -561,6 +583,7 @@
  		<copy todir="${dist.dir}">
  			<fileset dir="./">
  				<include name="${red5.filename}.jar"/>
+				<include name="boot.jar"/>
  				<include name="red5.bat"/>
  				<include name="red5-shutdown.bat"/>
  				<include name="red5.sh"/>

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ChildFirstClassLoader.java
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ChildFirstClassLoader.java	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ChildFirstClassLoader.java	 
Mon Feb  2 23:55:15 2009
@@ -49,14 +49,16 @@
  		super(urls, parent);
  		this.parent = parent;
  		system = getSystemClassLoader();		
-		//if we have a parent of the parent and its not the system classloader
-		parentParent = this.parent.getParent() != system ?  
this.parent.getParent() : null;
-
+		if (parent != null) {
+    		//if we have a parent of the parent and its not the system  
classloader
+    		parentParent = this.parent.getParent() != system ?  
this.parent.getParent() : null;
+		}
  		dumpClassLoaderNames();
  	}
  	
  	private void dumpClassLoaderNames() {
-		System.out.printf("[ChildFirstClassLoader]  
Classloaders:\nSystem %s\nParents Parent %s\nParent %s\nTCL %s\n\n",  
system, parentParent, this.parent,  
Thread.currentThread().getContextClassLoader());
+		System.out.printf("[ChildFirstClassLoader]  
Classloaders:\nSystem %s\nParents Parent %s\nParent %s\nThis  
class %s\nTCL %s\n\n",
+				system, parentParent, this.parent,  
ChildFirstClassLoader.class.getClassLoader(),  
Thread.currentThread().getContextClassLoader());
  	}

  	@Override
@@ -105,26 +107,26 @@
  				c = this.parent.loadClass(name);
  			} catch (Exception e) {
  				//ignore the Spring "BeanInfo" class lookup errors
-				if (e.getMessage().indexOf("BeanInfo") == -1) {
-					e.printStackTrace();
-				}
+				//if (e.getMessage().indexOf("BeanInfo") == -1) {
+				//	e.printStackTrace();
+				//}
  			}
  			if (c == null && parentParent != null) {
      			try {
      				c = parentParent.loadClass(name);
      			} catch (Exception e) {
-    				if (e.getMessage().indexOf("BeanInfo") == -1) {
-    					e.printStackTrace();
-    				}
+    				//if (e.getMessage().indexOf("BeanInfo") == -1) {
+    				//	e.printStackTrace();
+    				//}
      			}
  			}
  			if (c == null) {
  				try {
  					c = system.loadClass(name);
  				} catch (Exception e) {
-					if (e.getMessage().indexOf("BeanInfo") == -1) {
-						e.printStackTrace();
-					}
+					//if (e.getMessage().indexOf("BeanInfo") == -1) {
+					//	e.printStackTrace();
+					//}
  				}
  			}
  		}
@@ -156,4 +158,4 @@
  		}
  		return url;
  	}
-}
\ No newline at end of file
+}

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ClassLoaderBuilder.java
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ClassLoaderBuilder.java	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/classloading/ClassLoaderBuilder.java	 
Mon Feb  2 23:55:15 2009
@@ -36,8 +36,6 @@
  import java.util.jar.JarInputStream;
  import java.util.regex.Pattern;

-import org.springframework.util.StringUtils;
-
  /**
   * Class used to get the Servlet Class loader. The class loader returned  
is a
   * child first class loader.
@@ -57,27 +55,22 @@
  	 */
  	
  	/**
-	 * Use the current class loader to load the servlet and the libraries.
-	 */
-	public static final int USE_CURRENT_CLASSPATH = 1;
-
-	/**
  	 * Load the Servlet code from the WAR file and use the current classpath  
for
  	 * the libraries.
  	 */
-	public static final int USE_CLASSPATH_LIB = 2;
+	public static final int USE_CLASSPATH_LIB = 1;

  	/**
  	 * Load the servlet code from the WAR file and try to find the libraries  
in
  	 * the common red5 lib directory.
  	 */
-	public static final int USE_RED5_LIB = 3;
+	public static final int USE_RED5_LIB = 2;

  	/**
  	 * Load the servlet code and the libraries from the WAR file. This may  
take
  	 * some time as the libraries need to be extracted from the WAR file.
  	 */
-	public static final int USE_WAR_LIB = 4;
+	public static final int USE_WAR_LIB = 3;
  	
  	/**
  	 * Filters jar files
@@ -96,6 +89,15 @@
  	}	
  	
  	/**
+	 * Default build uses Red5 common lib without a parent classloader.
+	 *
+	 * @return
+	 */
+	public static ClassLoader build() {
+		return ClassLoaderBuilder.build(null, USE_RED5_LIB, null);
+	}
+	
+	/**
  	 * Gets a class loader based on mode.
  	 *
  	 * @param path the directory or file containing classes
@@ -112,10 +114,6 @@
  	 *
  	 */
  	public static ClassLoader build(File path, int mode, ClassLoader parent) {
-				
-		if (mode == USE_CURRENT_CLASSPATH) {
-			return ClassLoaderBuilder.class.getClassLoader();
-		}

  		JarFileFilter jarFileFilter = new JarFileFilter();
  		
@@ -273,15 +271,15 @@
          	loader = new ChildFirstClassLoader(urls, parent);	
          	
  		}
+		
+		Thread.currentThread().setContextClassLoader(loader);
  						
  		//loop thru all the current urls
  		//System.out.printf("Classpath for %s:\n", loader);
  		//for (URL url : urls) {
  			//System.out.println(url.toExternalForm());
  		//}
-		
-		//System.out.printf("Classloaders:\nThread %s\nCurrent Loader %s\nNew  
Loader %s\n", Thread.currentThread().getContextClassLoader(),  
ClassLoaderBuilder.class.getClassLoader(), loader);
-		
+
  		return loader;
  	}

@@ -452,13 +450,16 @@
      			
      			//check major
      			String[] topVersion = punct.split(topVers);
-    			
-                //System.err.println("topVersion (" + topVers + "): " +  
topVersion[0]);
-    			//check 3rd part of version for letters
+                //System.out.println("topVersion (" + topVers + "): " +  
topVersion[0] + " length: " + topVersion.length);
+                if (!topVersion[0].matches("[\\d].*")) {
+                	continue;
+                }
+
+                //check 3rd part of version for letters
      			if (topVersion.length > 2) {
      				String v = topVersion[2].toLowerCase();
      				if (v.length() > 1) {
-    					topVersion[2] = StringUtils.deleteAny(v, ALPHABET);
+    					topVersion[2] = deleteAny(v, ALPHABET);
      				} else {
      					//if is a only a letter use its index as a version
      					char ch = v.charAt(0);
@@ -467,13 +468,17 @@
      					}
      				}
      			}
+
+    			int topVersionNumber = Integer.valueOf(topVersion[0] +  
topVersion[1] + (topVersion.length > 2 ? topVersion[2] : '0')).intValue();
      			
      			String[] checkVersion = punct.split(checkVers);
-    			//check 3rd part of version for letters
+                //System.out.println("checkVersion (" + checkVers + "): "  
+ checkVersion[0] + " length: " + checkVersion.length);
+
+                //check 3rd part of version for letters
      			if (checkVersion.length > 2) {
      				String v = checkVersion[2].toLowerCase();
      				if (v.length() > 1) {
-    					checkVersion[2] = StringUtils.deleteAny(v, ALPHABET);
+    					checkVersion[2] = deleteAny(v, ALPHABET);
      				} else {
      					//if is a only a letter use its index as a version
      					char ch = v.charAt(0);
@@ -482,8 +487,7 @@
      					}
      				}
      			}
-    			
-    			int topVersionNumber = Integer.valueOf(topVersion[0] +  
topVersion[1] + (topVersion.length > 2 ? topVersion[2] : '0')).intValue();
+
      			int checkVersionNumber = Integer.valueOf(checkVersion[0] +  
checkVersion[1] + (checkVersion.length > 2 ?  
checkVersion[2] : '0')).intValue();
      			
      			if (topVersionNumber >= checkVersionNumber) {
@@ -515,5 +519,19 @@
  		libName = libName.substring(0, libName.length() - 4);
  		return libName;
  	}	
-	
+
+	private static String deleteAny(String str, String removalChars) {
+		StringBuilder sb = new StringBuilder(str);
+		//System.out.println("Before alpha delete: " + sb.toString());
+		String[] chars = removalChars.split("");
+		//System.out.println("Chars length: " + chars.length);
+		for (String c : chars) {
+			int index = -1;
+			while ((index = sb.indexOf(c)) > 0) {
+				sb.deleteCharAt(index);
+			}
+		}
+		//System.out.println("After alpha delete: " + sb.toString());
+		return sb.toString();
+	}
  }

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/Bootstrap.java
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/Bootstrap.java	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/Bootstrap.java	 
Mon Feb  2 23:55:15 2009
@@ -25,12 +25,6 @@
  import java.lang.reflect.Method;

  import org.red5.classloading.ClassLoaderBuilder;
-import org.red5.logging.Red5LoggerFactory;
-import org.red5.server.api.Red5;
-import org.slf4j.Logger;
-import org.slf4j.bridge.SLF4JBridgeHandler;
-import org.slf4j.impl.StaticLoggerBinder;
-import org.springframework.context.support.FileSystemXmlApplicationContext;

  /**
   * Boot-straps Red5 using the latest available jars found in  
<i>red5.home/lib</i> directory.
@@ -102,14 +96,11 @@
  	    }
  		*/
  		
-		// pass urls to the ClassLoader
-		ClassLoader loader = ClassLoaderBuilder.build(null,  
ClassLoaderBuilder.USE_RED5_LIB, null);
-					
-		// set the classloader to the current thread
-		Thread.currentThread().setContextClassLoader(loader);
-		
+		// build a ClassLoader
+		ClassLoader loader = ClassLoaderBuilder.build();
+							
  		// create a new instance of this class using new classloader
-		Object boot = Class.forName("org.red5.server.Bootstrap", true,  
loader).newInstance();
+		Object boot = Class.forName("org.red5.server.Launcher", false,  
loader).newInstance();
  	
  		Method m1 = boot.getClass().getMethod("launch", (Class[]) null);
  		m1.invoke(boot, (Object[]) null);
@@ -173,38 +164,6 @@
  		
  		System.out.printf("Red5 root: %s\n", root);
  		return root;
-	}
-	
-	/**
-	 * Launch Red5 under it's own classloader
-	 *
-	 */
-	public void launch() {
-		try {	
-			ClassLoader loader = Thread.currentThread().getContextClassLoader();
-			//System.out.printf("Launch - Thread classloader: %s\n", loader);
-
-			//create red5 app context
-			FileSystemXmlApplicationContext ctx = new  
FileSystemXmlApplicationContext(new String[]{
-					"classpath:/red5.xml"}, false);
-			ctx.setClassLoader(loader);			
-			
-			//install the slf4j bridge (mostly for JUL logging)
-			SLF4JBridgeHandler.install();
-			//we create the logger here so that it is instanced inside the expected
-			//classloader
-			Logger log = Red5LoggerFactory.getLogger(Bootstrap.class);
-		    //version info banner
-			log.info("{} (http://www.osflash.org/red5)", Red5.getVersion());
-			//see which logger binder has been instanced
-			log.trace("Logger binder: {}",  
StaticLoggerBinder.getSingleton().getClass().getName());
-
-			//refresh must be called before accessing the bean factory
-			ctx.refresh();
-			
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
  	}
  	
  }

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/api/Red5.java
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/api/Red5.java	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/api/Red5.java	 
Mon Feb  2 23:55:15 2009
@@ -57,7 +57,7 @@
  	public IConnection conn;

      /**
-     * Current server version with revision
+     * Current server version with revision
       */
      public static final String VERSION = "Red5 Server 0.8.0-RC2  
$Revision$";

@@ -177,4 +177,4 @@
  	    return START_TIME - System.currentTimeMillis();
  	}	

-}
\ No newline at end of file
+}

Modified:  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/tomcat/TomcatLoader.java
==============================================================================
---  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/tomcat/TomcatLoader.java	 
(original)
+++  
java/server/branches/dominick_multithreaded_application_adapter/src/org/red5/server/tomcat/TomcatLoader.java	 
Mon Feb  2 23:55:15 2009
@@ -162,7 +162,6 @@
  		if (c != null) {
  			//ClassLoader classLoader = new ChildFirstClassLoader(new URL[]{},  
Thread.currentThread().getContextClassLoader());
  			ClassLoader classLoader =  
Thread.currentThread().getContextClassLoader();
-			//log.debug("Classloaders - Parent {}\nTCL {}\n\n", new Object[]  
{classLoader.getParent(), classLoader});
  			c.setParentClassLoader(classLoader);
  			//
  			Object ldr = c.getLoader();
@@ -826,4 +825,4 @@
  		}
  	}

-}
\ No newline at end of file
+}



More information about the Red5commits mailing list