@Test public void shouldIncrementAllCountersAndResetThem() { assertThat(Statistics.getError404s(), is(equalTo(0l))); assertThat(Statistics.getError500s(), is(equalTo(0l))); assertThat(Statistics.getRequestsHandled(), is(equalTo(0l))); Statistics.incrementError404(); assertThat(Statistics.getError404s(), is(equalTo(1l))); Statistics.incrementError500(); assertThat(Statistics.getError500s(), is(equalTo(1l))); Statistics.incrementRequestHandled(); assertThat(Statistics.getRequestsHandled(), is(equalTo(1l))); Statistics.incrementError404(); assertThat(Statistics.getError404s(), is(equalTo(2l))); Statistics.incrementError500(); assertThat(Statistics.getError500s(), is(equalTo(2l))); Statistics.incrementRequestHandled(); assertThat(Statistics.getRequestsHandled(), is(equalTo(2l))); Statistics.reset(); assertThat(Statistics.getError404s(), is(equalTo(0l))); assertThat(Statistics.getError500s(), is(equalTo(0l))); assertThat(Statistics.getRequestsHandled(), is(equalTo(0l))); }
/** * Returns resolved handler for given exception. * * @param e * @return */ @Override public HttpErrorHandler getHandler(final RuntimeException e) { Throwable fallbackException; try { if (e instanceof ProtocolException) { return getProtocolExceptionHandler((ProtocolException) e); } else if (e instanceof AccessDeniedException) { return new HttpError403Handler(serverConfig.getErrorDocument403Path()); } else if (e instanceof NotFoundException) { Statistics.incrementError404(); return new HttpError404Handler(serverConfig.getErrorDocument404Path()); } else if (e instanceof MethodNotAllowedException) { return new HttpError405Handler(getAllowedMethods()); } else { fallbackException = e; } } catch (Throwable handlingException) { fallbackException = handlingException; } Statistics.incrementError500(); return new HttpError500Handler().setReason(fallbackException); }