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
This commit is contained in:
Todd Lipcon 2012-09-11 06:37:17 +00:00
parent 1d42944962
commit bdcbc2d1ef
3 changed files with 35 additions and 1 deletions

View File

@ -202,6 +202,9 @@ Trunk (Unreleased)
HADOOP-8684. Deadlock between WritableComparator and WritableComparable. HADOOP-8684. Deadlock between WritableComparator and WritableComparable.
(Jing Zhao via suresh) (Jing Zhao via suresh)
HADOOP-8786. HttpServer continues to start even if AuthenticationFilter
fails to init (todd)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-7761. Improve the performance of raw comparisons. (todd) HADOOP-7761. Improve the performance of raw comparisons. (todd)

View File

@ -677,6 +677,15 @@ public class HttpServer implements FilterContainer {
"Problem in starting http server. Server handlers failed"); "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) { } catch (IOException e) {
throw e; throw e;
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
public class TestServletFilter extends HttpServerFunctionalTest { public class TestServletFilter extends HttpServerFunctionalTest {
@ -163,7 +164,7 @@ public class TestServletFilter extends HttpServerFunctionalTest {
@Test @Test
public void testServletFilterWhenInitThrowsException() throws Exception { public void testServletFilterWhenInitThrowsException() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
// start a http server with CountingFilter // start a http server with ErrorFilter
conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY, conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY,
ErrorFilter.Initializer.class.getName()); ErrorFilter.Initializer.class.getName());
HttpServer http = createTestServer(conf); HttpServer http = createTestServer(conf);
@ -174,4 +175,25 @@ public class TestServletFilter extends HttpServerFunctionalTest {
assertTrue( e.getMessage().contains("Problem in starting http server. Server handlers failed")); 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);
}
}
} }