liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
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
package com.cloud.attendance.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.tuckey.web.filters.urlrewrite.Conf;
import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;
 
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import java.io.IOException;
 
@Configuration
public class UrlRewriteFilterConfig extends UrlRewriteFilter {
 
    private static final String URL_REWRITE = "classpath:/urlrewrite.xml";
 
    // Inject the Resource from the given location
    @Value(URL_REWRITE)
    private Resource resource;
 
    // Override the loadUrlRewriter method, and write your own implementation
    protected void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
        try {
            // Create a UrlRewrite Conf object with the injected resource
            Conf conf = new Conf(filterConfig.getServletContext(), resource.getInputStream(), resource.getFilename(),
                    "@@wp@@");  /*traceability*/
            checkConf(conf);
        } catch (IOException ex) {
            throw new ServletException("不能 URL rewrite configuration file from " + URL_REWRITE, ex);
        }
    }
}