/******************************************************************************************************************* * * Returns the current year reading it from the path params, or by default from the calendar. * ******************************************************************************************************************/ @Nonnegative private int getCurrentYear (final @Nonnull String pathParams) throws HttpStatusException { try { return "".equals(pathParams) ? new DateTime().getYear() : Integer.parseInt(pathParams.replaceAll("/$", "").replaceAll("^/", "")); // return "".equals(pathParams) ? new DateTime().getYear() : Integer.parseInt(pathParams.replaceAll("/", "")); } catch (NumberFormatException e) { throw new HttpStatusException(404); } } }
throw HttpStatusException.permanentRedirect(site, newRelativeUri);
/******************************************************************************************************************* * * If relativeUri doesn't end with a trailing slash, send a redirect to the proper Uri. * FIXME: could be dropped and replaced with a configurable redirect? * ******************************************************************************************************************/ private void enforceTrailingSlash (final @Nonnull String relativeUri, final @Nonnull Site site) throws HttpStatusException { final String originalRelativeUri = requestHolder.get().getOriginalRelativeUri(); if (!relativeUri.contains(".") && !originalRelativeUri.endsWith("/")) { throw HttpStatusException.temporaryRedirect(site, relativeUri); // TODO: temporary or permanent? } } }
throw new HttpStatusException(404);
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_call_some_RequestProcessors_when_HttpStatusException_with_generic_Http_status() throws Exception { final HttpStatusException e = new HttpStatusException(SC_NOT_ACCEPTABLE); mockRequestProcessor3.setThrowable(e); commonExceptionTestSequence(); verify(responseBuilder).forException(same(e)); // inOrder.verifyNoMoreInteractions(); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_call_some_RequestProcessors_when_HttpStatusException_with_SC_FOUND() throws Exception { final HttpStatusException e = new HttpStatusException(SC_FOUND); mockRequestProcessor3.setThrowable(e); commonExceptionTestSequence(); verify(responseBuilder).forException(same(e)); // inOrder.verifyNoMoreInteractions(); }