1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tuckey.web.filters.urlrewrite.Conf;
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.io.InputStream;
import java.net.URL;
/**
* Subclass of {@link org.tuckey.web.filters.urlrewrite.UrlRewriteFilter}
* that overrides the configuration file loading mechanism.
*/
public class UrlRewriteFilter extends org.tuckey.web.filters.urlrewrite.UrlRewriteFilter {
private final Logger log = LoggerFactory.getLogger(UrlRewriteFilter.class);
@Override
protected void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
ServletContext context = filterConfig.getServletContext();
String confPath = filterConfig.getInitParameter("confPath");
boolean modRewriteStyleConf = getModRewriteStyleConf(filterConfig.getInitParameter("modRewriteConf"));
try {
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(confPath);
final URL confUrl = getClass().getClassLoader().getResource(confPath);
if (inputStream == null) {
log.error("unable to find urlrewrite conf file at " + confPath);
// set the writer back to null
if (isLoaded()) {
log.error("unloading existing conf");
destroyUrlRewriter();
}
} else {
Conf conf = new Conf(context, inputStream, confPath, confUrl.toString(), modRewriteStyleConf);
checkConf(conf);
}
} catch (Throwable e) {
log.error("unloading urlrewrite conf file at " + confPath, e);
throw new ServletException(e);
}
}
private boolean getModRewriteStyleConf(String modRewriteConf) {
boolean modRewriteStyleConf = false;
if (!StringUtils.isBlank(modRewriteConf)) {
modRewriteStyleConf = "true".equals(StringUtils.trim(modRewriteConf).toLowerCase());
}
return modRewriteStyleConf;
}
}
|
댓글 없음:
댓글 쓰기
참고: 블로그의 회원만 댓글을 작성할 수 있습니다.