ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-10913 - Slider View: 404 error on slider view instance creation (tbeerbower)
Date Tue, 05 May 2015 13:18:19 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.maint 68289c47c -> 8fb01a804


AMBARI-10913 - Slider View: 404 error on slider view instance creation (tbeerbower)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8fb01a80
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8fb01a80
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8fb01a80

Branch: refs/heads/branch-2.0.maint
Commit: 8fb01a804fabfaab808386f9233751e22216601e
Parents: 68289c4
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Tue May 5 09:14:09 2015 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue May 5 09:17:48 2015 -0400

----------------------------------------------------------------------
 .../ambari/server/view/ViewClassLoader.java     | 75 +++-----------------
 .../ambari/server/view/ViewExtractor.java       |  3 +-
 .../ambari/server/view/ViewClassLoaderTest.java |  6 ++
 3 files changed, 19 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8fb01a80/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
index 7c8f7bd..ad8c805 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
@@ -18,16 +18,18 @@
 
 package org.apache.ambari.server.view;
 
-import java.net.URL;
-import java.net.URLClassLoader;
+import org.eclipse.jetty.webapp.WebAppClassLoader;
+import org.eclipse.jetty.webapp.WebAppContext;
 
+import java.io.IOException;
+import java.net.URL;
 
 /**
  * Class loader used to load classes and resources from a search path of URLs referring to
both JAR files
  * and directories.  The URLs will be searched in the order specified for classes and resources
before
  * searching the parent class loader.
  */
-public class ViewClassLoader extends URLClassLoader {
+public class ViewClassLoader extends WebAppClassLoader {
 
   // ----- Constructors ------------------------------------------------------
 
@@ -38,7 +40,7 @@ public class ViewClassLoader extends URLClassLoader {
    *
    * @param urls  the URLs from which to load classes and resources
    */
-  public ViewClassLoader(URL[] urls) {
+  public ViewClassLoader(URL[] urls) throws IOException {
     this(null, urls);
   }
 
@@ -50,69 +52,14 @@ public class ViewClassLoader extends URLClassLoader {
    * @param parent  the parent class loader
    * @param urls    the URLs from which to load classes and resources
    */
-  public ViewClassLoader(ClassLoader parent, URL[] urls) {
-    super(new URL[]{}, selectParentClassLoader(parent));
+  public ViewClassLoader(ClassLoader parent, URL[] urls) throws IOException {
+    // Use no-arg web app context to initialize the class loader.  For now we are just using
the default context
+    // values for things like parent loader priority and server classes.  In the future we
may allow overrides at
+    // the view level.
+    super(parent, new WebAppContext());
 
     for (URL url : urls) {
       addURL(url);
     }
   }
-
-
-  // ----- ClassLoader -------------------------------------------------------
-
-  @Override
-  public synchronized URL getResource(String name) {
-    URL resource = this.findResource(name);
-
-    if (resource == null) {
-      ClassLoader parentClassLoader = getParent();
-      if (parentClassLoader != null) {
-        resource = parentClassLoader.getResource(name);
-      }
-    }
-    return resource;
-  }
-
-  @Override
-  protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException
{
-    Class clazz = findLoadedClass(name);
-
-    if (clazz == null) {
-      try {
-        clazz = this.findClass(name);
-      } catch (ClassNotFoundException e) {
-        ClassLoader parentClassLoader = getParent();
-        if (parentClassLoader != null) {
-          clazz = parentClassLoader.loadClass(name);
-        }
-
-        if (clazz == null) {
-          throw e;
-        }
-      }
-    }
-
-    if (resolve) {
-      resolveClass(clazz);
-    }
-    return clazz;
-  }
-
-
-  // ----- helper methods ----------------------------------------------------
-
-  // Get an appropriate parent class loader.
-  private static ClassLoader selectParentClassLoader(ClassLoader parentClassLoader) {
-
-    if (parentClassLoader == null) {
-
-      parentClassLoader = Thread.currentThread().getContextClassLoader();
-
-      if (parentClassLoader == null) {
-        parentClassLoader = ViewClassLoader.class.getClassLoader();
-      }
-    }
-    return parentClassLoader;
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8fb01a80/ambari-server/src/main/java/org/apache/ambari/server/view/ViewExtractor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewExtractor.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewExtractor.java
index 73b0059..43efc7d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewExtractor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewExtractor.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
 import javax.inject.Inject;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.LinkedList;
@@ -180,7 +181,7 @@ public class ViewExtractor {
 
   // get a class loader for the given archive directory
   private ClassLoader getArchiveClassLoader(File archiveDir)
-      throws MalformedURLException {
+      throws MalformedURLException, IOException {
 
     String    archivePath = archiveDir.getAbsolutePath();
     List<URL> urlList     = new LinkedList<URL>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/8fb01a80/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
index 1f1ae9b..3a9ecd3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
@@ -70,6 +70,7 @@ public class ViewClassLoaderTest {
     expect(parentClassLoader.getPackage("org.apache.ambari.server.view")).andReturn(null).anyTimes();
     expect(parentClassLoader.loadClass("java.lang.Object")).andReturn(parentClass).anyTimes();
     expect(parentClassLoader.loadClass("ParentClass")).andReturn(parentClass).once();
+    expect(parentClassLoader.loadClass("javax.xml.parsers.SAXParserFactory")).andReturn(parentClass).once();
 
     replay(parentClassLoader);
 
@@ -89,6 +90,11 @@ public class ViewClassLoaderTest {
     Assert.assertNotNull(clazz);
     Assert.assertSame(parentClass, clazz);
 
+    clazz = classLoader.loadClass("javax.xml.parsers.SAXParserFactory");
+
+    Assert.assertNotNull(clazz);
+    Assert.assertSame(parentClass, clazz);
+
     verify(parentClassLoader);
   }
 


Mime
View raw message