Here's what I did, which I was not happy with:
Code:
@Override
public boolean preHandle(final HttpServletRequest request,
final HttpServletResponse response,
final Object handler) {
if (log.isDebugEnabled())
requestDebug(request);
if (log.isDebugEnabled())
servletDebug();
if (request.getServletPath().compareTo("/start.zug") == 0)
return (true);
if (userPermissions.isAdmin())
return (true);
if (systemStatus.isSystemDown()) {
try {
response.sendRedirect(serviceUrl(request, systemStatus
.getSystemDownView()));
}
catch (final IOException e) {
log.error("exception: {}", e);
}
return (false);
}
return (true);
}
private String serviceUrl(final HttpServletRequest request,
final String page) {
final StringBuilder sb = new StringBuilder();
sb.append(request.getScheme());
sb.append("://");
sb.append(request.getServerName());
final int port = request.getServerPort();
if (port != 80) {
sb.append(":");
sb.append(port);
}
sb.append("/");
sb.append(request.getContextPath());
sb.append("/");
sb.append(page);
return (sb.toString());
}
private void requestDebug(final HttpServletRequest request) {
log.debug("contextPath: {}", request.getContextPath());
log.debug("pathInfo: {}", request.getPathInfo());
log.debug("pathTranslated: {}", request.getPathTranslated());
log.debug("requestUrl: {}", request.getRequestURL());
log.debug("requestUri: {}", request.getRequestURI());
log.debug("servletPath: {}", request.getServletPath());
log.debug("serverName: {}", request.getServerName());
log.debug("serverPort: {}", request.getServerPort());
log.debug("protocol: {}", request.getProtocol());
log.debug("scheme: {}", request.getScheme());
}
The method serviceUrl constructs the url to redirect to. The method systemDownView is incorrectly named; it should be systemDownFile since it's returning a file name, systemDown.jsp, not a view name. When deployed the file systemDown.jsp is in the root of the webapps/<myApp>/ directory along with the index.jsp start file.
And apparently there are security issues with using the host name that's in the HttpServletRequest object; I think it's supplied by the client (browser or nefarious hacker, as the case may be).