(backport from trunk) HADOOP-7688. When a servlet filter throws an exception in init(..), the Jetty server failed silently. Contributed by Uma Maheswara Rao G.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1384416 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
042f9102fe
commit
9441c3e242
|
@ -18,6 +18,9 @@ Release 2.0.3-alpha - Unreleased
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
|
HADOOP-7688. When a servlet filter throws an exception in init(..), the Jetty server failed silently.
|
||||||
|
(umamahesh)
|
||||||
|
|
||||||
Release 2.0.2-alpha - 2012-09-07
|
Release 2.0.2-alpha - 2012-09-07
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -668,6 +668,14 @@ public class HttpServer implements FilterContainer {
|
||||||
LOG.info("HttpServer.start() threw a MultiException", ex);
|
LOG.info("HttpServer.start() threw a MultiException", ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
// Make sure there is no handler failures.
|
||||||
|
Handler[] handlers = webServer.getHandlers();
|
||||||
|
for (int i = 0; i < handlers.length; i++) {
|
||||||
|
if (handlers[i].isFailed()) {
|
||||||
|
throw new IOException(
|
||||||
|
"Problem in starting http server. Server handlers failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -141,4 +141,37 @@ public class TestServletFilter extends HttpServerFunctionalTest {
|
||||||
http.stop();
|
http.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public class ErrorFilter extends SimpleFilter {
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig arg0) throws ServletException {
|
||||||
|
throw new ServletException("Throwing the exception from Filter init");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configuration for the filter */
|
||||||
|
static public class Initializer extends FilterInitializer {
|
||||||
|
public Initializer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initFilter(FilterContainer container, Configuration conf) {
|
||||||
|
container.addFilter("simple", ErrorFilter.class.getName(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testServletFilterWhenInitThrowsException() throws Exception {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
// start a http server with CountingFilter
|
||||||
|
conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY,
|
||||||
|
ErrorFilter.Initializer.class.getName());
|
||||||
|
HttpServer http = createTestServer(conf);
|
||||||
|
try {
|
||||||
|
http.start();
|
||||||
|
fail("expecting exception");
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertTrue(e.getMessage().contains(
|
||||||
|
"Problem in starting http server. Server handlers failed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue