diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index d1364a983a9..43368c08c4b 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -24,6 +24,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-8795. BASH tab completion doesn't look in PATH, assumes path to executable is specified. (Sean Mackrory via atm) + HADOOP-8786. HttpServer continues to start even if AuthenticationFilter + fails to init. (Todd Lipcon via umamahesh) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES 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 3afc1e9c902..1b193cba195 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 @@ -676,6 +676,15 @@ public class HttpServer implements FilterContainer { "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 (Exception 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 c2ecbf39730..3c01320c218 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 javax.servlet.http.HttpServletRequest; 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 { @@ -174,4 +175,24 @@ public class TestServletFilter extends HttpServerFunctionalTest { "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); + } + } }