@Override public String apply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException { String location = response.encodeRedirectURL(_location); response.setHeader("Location",RedirectUtil.toRedirectURL(request,location)); response.setStatus(_statusCode); response.getOutputStream().flush(); // no output / content response.getOutputStream().close(); return target; }
@Override public String matchAndApply(String target, HttpServletRequest request, HttpServletResponse response) throws IOException { Matcher matcher = regex.matcher(request.getRequestURL()); boolean matches = matcher.matches(); if (matches) { String location = response.encodeRedirectURL(replacement); response.setHeader("Location", RedirectUtil.toRedirectURL(request, location)); response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.getOutputStream().flush(); // no output / content response.getOutputStream().close(); return location; } return null; }
@Override protected String apply(String target, HttpServletRequest request, HttpServletResponse response, Matcher matcher) throws IOException { target=_location; for (int g=1;g<=matcher.groupCount();g++) { String group = matcher.group(g); target=target.replaceAll("\\$"+g,group); } target = response.encodeRedirectURL(target); response.setHeader("Location",RedirectUtil.toRedirectURL(request,target)); response.setStatus(_statusCode); response.getOutputStream().flush(); // no output / content response.getOutputStream().close(); return target; }