public int parseRequest(HttpServletRequest req, HttpServletResponse res, RequestContext context) { String resourcePath = context.getResourcePath(); if (resourcePath.endsWith(".html")) { resourcePath = resourcePath.substring(0, resourcePath.length() - 5) + ".jsp"; context.setResourcePath(resourcePath); return FORWARD; } else { return OK; } }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (null != request.getAttribute("FLAG")) { chain.doFilter(request, response); return; } request.setAttribute("FLAG", FLAG); String encoding = this.encoding; HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String resourcePath = req.getServletPath(); RequestContext requestContext = new RequestContext(config.getServletContext(), req, resourcePath); request.setAttribute("context", requestContext); for (Decorator decorator : decorators) { int returned = decorator.parseRequest(req, res, requestContext); switch (returned) { case Decorator.OK: // do nothing break; case Decorator.REDIRECT: res.sendRedirect(requestContext.getResourcePath()); return; case Decorator.MOVED_PERMANENTLY: res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); res.setHeader("Location", requestContext.getResourcePath()); return; default: // do nothing } } if (pattern.matcher(requestContext.getResourcePath()).matches()) { WebContent content = new WebContent(); if (requestContext.getResourcePath().startsWith("/WEB-INF/admin/")) { encoding = "UTF-8"; } ByteArrayResponseWrapper wrapper = new ByteArrayResponseWrapper(res); request.getRequestDispatcher(requestContext.getResourcePath()).include(req, wrapper); wrapper.finish(); content.setWholeContent(wrapper.getString(encoding)); response.setContentType(wrapper.getContentType()); content.finish(); for (Decorator decorator : decorators) { decorator.decorate(requestContext, content, content); content.finish(); } byte[] theContent = content.toString().getBytes(encoding); response.setContentLength(theContent.length); response.getOutputStream().write(theContent); return; } request.getRequestDispatcher(requestContext.getResourcePath()).forward(req, res); }