Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebFilter(urlPatterns = "/*")
- public static class Filter implements IWebApplicationFactory, javax.servlet.Filter {
- private final Map<String, WicketFilter> filters = new HashMap<String, WicketFilter>();
- private final ThreadLocal<String> hosts = new ThreadLocal<String>();
- private FilterConfig config;
- public Filter() {
- System.setProperty("wicket.configuration", DEPLOYMENT);
- }
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- this.config = filterConfig;
- }
- @Override
- public void destroy() {
- for (WicketFilter w : filters.values()) {
- w.destroy();
- }
- filters.clear();
- }
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- hosts.set(request.getServerName());
- try {
- getFilterForHost().doFilter(request, response, chain);
- } finally {
- hosts.remove();
- }
- }
- private WicketFilter getFilterForHost() throws ServletException {
- String host = hosts.get();
- if (!filters.containsKey(host)) {
- WicketFilter w = new WicketFilter() {
- @Override
- protected IWebApplicationFactory getApplicationFactory() {
- return Filter.this;
- }
- };
- w.init(config);
- filters.put(host, w);
- }
- return filters.get(host);
- }
- @Override
- public WebApplication createApplication(WicketFilter wf) {
- return new WicketApp(hosts.get());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement