backport 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/branches/branch-2@1384456 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uma Maheswara Rao G 2012-09-13 18:27:53 +00:00
parent ae71fc2a24
commit 93134626fb
3 changed files with 33 additions and 0 deletions

View File

@ -24,6 +24,9 @@ Release 2.0.3-alpha - Unreleased
HADOOP-8795. BASH tab completion doesn't look in PATH, assumes path to HADOOP-8795. BASH tab completion doesn't look in PATH, assumes path to
executable is specified. (Sean Mackrory via atm) 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 Release 2.0.2-alpha - 2012-09-07
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -676,6 +676,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 (Exception e) { } catch (Exception 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 {
@ -174,4 +175,24 @@ public class TestServletFilter extends HttpServerFunctionalTest {
"Problem in starting http server. Server handlers failed")); "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);
}
}
} }