From bdcbc2d1ef0fba999170ba748176ad0f496ccf2c Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Tue, 11 Sep 2012 06:37:17 +0000 Subject: [PATCH] HADOOP-8786. HttpServer continues to start even if AuthenticationFilter fails to init. Contributed by Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1383254 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/http/HttpServer.java | 9 +++++++ .../apache/hadoop/http/TestServletFilter.java | 24 ++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c7848aaad08..08a8d1240df 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -202,6 +202,9 @@ Trunk (Unreleased) HADOOP-8684. Deadlock between WritableComparator and WritableComparable. (Jing Zhao via suresh) + HADOOP-8786. HttpServer continues to start even if AuthenticationFilter + fails to init (todd) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java index 77e9e1601aa..0de1806a4d5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java @@ -677,6 +677,15 @@ public void start() throws IOException { "Problem in starting http server. Server handlers failed"); } } + // Make sure there are no errors initializing the context. + Throwable unavailableException = webAppContext.getUnavailableException(); + if (unavailableException != null) { + // Have to stop the webserver, or else its non-daemon threads + // will hang forever. + webServer.stop(); + throw new IOException("Unable to initialize WebAppContext", + unavailableException); + } } catch (IOException e) { throw e; } catch (InterruptedException e) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestServletFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestServletFilter.java index a4d32531cef..e5392396d5f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestServletFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestServletFilter.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; public class TestServletFilter extends HttpServerFunctionalTest { @@ -163,7 +164,7 @@ public void initFilter(FilterContainer container, Configuration conf) { @Test public void testServletFilterWhenInitThrowsException() throws Exception { Configuration conf = new Configuration(); - // start a http server with CountingFilter + // start a http server with ErrorFilter conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY, ErrorFilter.Initializer.class.getName()); HttpServer http = createTestServer(conf); @@ -174,4 +175,25 @@ public void testServletFilterWhenInitThrowsException() throws Exception { assertTrue( e.getMessage().contains("Problem in starting http server. Server handlers failed")); } } + + /** + * Similar to the above test case, except that it uses a different API to add the + * filter. Regression test for HADOOP-8786. + */ + @Test + public void testContextSpecificServletFilterWhenInitThrowsException() + throws Exception { + Configuration conf = new Configuration(); + HttpServer http = createTestServer(conf); + http.defineFilter(http.webAppContext, + "ErrorFilter", ErrorFilter.class.getName(), + null, null); + try { + http.start(); + fail("expecting exception"); + } catch (IOException e) { + GenericTestUtils.assertExceptionContains("Unable to initialize WebAppContext", e); + } + } + }