|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry; |
|
16 |
| |
|
17 |
| import java.io.IOException; |
|
18 |
| |
|
19 |
| import javax.servlet.Filter; |
|
20 |
| import javax.servlet.FilterChain; |
|
21 |
| import javax.servlet.FilterConfig; |
|
22 |
| import javax.servlet.ServletException; |
|
23 |
| import javax.servlet.ServletRequest; |
|
24 |
| import javax.servlet.ServletResponse; |
|
25 |
| import javax.servlet.http.HttpServletRequest; |
|
26 |
| import javax.servlet.http.HttpServletResponse; |
|
27 |
| |
|
28 |
| import org.apache.commons.logging.Log; |
|
29 |
| import org.apache.commons.logging.LogFactory; |
|
30 |
| import org.apache.hivemind.HiveMind; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| public class RedirectFilter implements Filter |
|
49 |
| { |
|
50 |
| private static final Log LOG = LogFactory.getLog(RedirectFilter.class); |
|
51 |
| |
|
52 |
| public static final String REDIRECT_PATH_PARAM = "redirect-path"; |
|
53 |
| |
|
54 |
| private String _redirectPath; |
|
55 |
| |
|
56 |
0
| public void init(FilterConfig config) throws ServletException
|
|
57 |
| { |
|
58 |
0
| _redirectPath = config.getInitParameter(REDIRECT_PATH_PARAM);
|
|
59 |
| |
|
60 |
0
| if (HiveMind.isBlank(_redirectPath))
|
|
61 |
0
| _redirectPath = "/app";
|
|
62 |
| |
|
63 |
0
| if (LOG.isDebugEnabled())
|
|
64 |
0
| LOG.debug(Tapestry.format("RedirectServlet.redirect-path", _redirectPath));
|
|
65 |
| } |
|
66 |
| |
|
67 |
0
| public void destroy()
|
|
68 |
| { |
|
69 |
| |
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
0
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
79 |
| throws IOException, ServletException |
|
80 |
| { |
|
81 |
0
| HttpServletRequest hrequest = (HttpServletRequest) request;
|
|
82 |
0
| HttpServletResponse hresponse = (HttpServletResponse) response;
|
|
83 |
| |
|
84 |
0
| String servletPath = hrequest.getServletPath();
|
|
85 |
0
| String pathInfo = hrequest.getPathInfo();
|
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
0
| if ((HiveMind.isBlank(servletPath) || servletPath.equals("/"))
|
|
92 |
| && (HiveMind.isBlank(pathInfo) || pathInfo.equals("/"))) |
|
93 |
| { |
|
94 |
0
| String path = hrequest.getContextPath() + _redirectPath;
|
|
95 |
| |
|
96 |
0
| if (LOG.isDebugEnabled())
|
|
97 |
0
| LOG.debug(Tapestry.format("RedirectServlet.redirecting", path));
|
|
98 |
| |
|
99 |
0
| hresponse.sendRedirect(path);
|
|
100 |
0
| return;
|
|
101 |
| } |
|
102 |
| |
|
103 |
0
| chain.doFilter(request, response);
|
|
104 |
| } |
|
105 |
| |
|
106 |
| } |