Example usage for org.apache.wicket.protocol.http WicketFilter WicketFilter

List of usage examples for org.apache.wicket.protocol.http WicketFilter WicketFilter

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WicketFilter WicketFilter.

Prototype

public WicketFilter() 

Source Link

Document

default constructor, usually invoked through the servlet container by the web.xml configuration

Usage

From source file:at.molindo.wicketutils.utils.MockUtils.java

License:Apache License

public static WicketFilter newMockFilter(final WebApplication application) {
    final MockServletContext context = new MockServletContext(application, "/");
    final WicketFilter filter = new WicketFilter() {
        @Override//  ww w .java  2 s  .c o  m
        protected IWebApplicationFactory getApplicationFactory() {
            return new IWebApplicationFactory() {
                @Override
                public WebApplication createApplication(WicketFilter filter) {
                    return application;
                }

                @Override
                public void destroy(WicketFilter filter) {
                    // noop
                };
            };
        }
    };

    try {
        filter.init(new FilterConfig() {

            @Override
            public ServletContext getServletContext() {
                return context;
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                return null;
            }

            @Override
            public String getInitParameter(String name) {
                return null;
            }

            @Override
            public String getFilterName() {
                return "WicketMockServlet";
            }
        });
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }

    return filter;
}

From source file:com.doculibre.constellio.wicket.servlet.ConstellioWicketServlet.java

License:Open Source License

@Override
protected WicketFilter newWicketFilter() {
    return new WicketFilter() {
        @Override//from ww w .  j ava  2  s  .c o m
        protected ClassLoader getClassLoader() {
            // PluginAwareClassLoader pluginAwareClassLoader = new
            // PluginAwareClassLoader();
            // return pluginAwareClassLoader;
            return super.getClassLoader();
        }
    };
}

From source file:com.evolveum.midpoint.web.boot.MidPointSpringApplication.java

License:Apache License

@Bean
public FilterRegistrationBean<WicketFilter> wicket() {
    FilterRegistrationBean<WicketFilter> registration = new FilterRegistrationBean<>();
    registration.setFilter(new WicketFilter());
    registration.setDispatcherTypes(DispatcherType.ERROR, DispatcherType.REQUEST, DispatcherType.FORWARD);
    registration.addUrlPatterns("/*");
    registration.addInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    registration.addInitParameter(Application.CONFIGURATION, "deployment"); // development
    registration.addInitParameter("applicationBean", "midpointApplication");
    registration.addInitParameter(WicketFilter.APP_FACT_PARAM,
            "org.apache.wicket.spring.SpringWebApplicationFactory");

    return registration;
}

From source file:com.francetelecom.clara.cloud.webapp.config.WicketWebInitializer.java

License:Apache License

@Bean
public FilterRegistrationBean wicketFilterRegistration() {

    FilterRegistrationBean registration = new FilterRegistrationBean();
    WicketFilter wicketFilter = new WicketFilter();
    registration.setFilter(wicketFilter);
    registration.setName("wicketFilter");
    registration.addInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
    registration.addInitParameter("configuration", configuration);
    registration.addInitParameter("testsMode", String.valueOf(testMode));
    registration.addInitParameter("mockMode", String.valueOf(mockMode));
    registration.addInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/portal/*");
    registration.addInitParameter(WicketFilter.IGNORE_PATHS_PARAM, "/favicon.ico");
    registration.addUrlPatterns("/portal/*");
    registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD);
    registration.setMatchAfter(true);/*from  w  w w  .  jav a 2s .c  om*/

    return registration;
}

From source file:com.okidokiteam.gouken.web.internal.Activator.java

License:Apache License

public void deploy(ExtHttpService httpService) {
    Dictionary dict = new Hashtable();
    ClassLoader parent = Thread.currentThread().getContextClassLoader();

    try {/*from w  w w. j  a  va  2s  .c  o m*/
        dict.put("applicationClassName", WicketApplication.class.getName());
        //   Thread.currentThread().setContextClassLoader( null );
        Filter filter = new WicketFilter() {
            @Override
            protected ClassLoader getClassLoader() {
                return Activator.class.getClassLoader();
            }

        };

        httpService.registerFilter(filter, "/*", dict, 0, httpService.createDefaultHttpContext());
        httpService.registerResources("/", "/web", httpService.createDefaultHttpContext());

    } catch (ServletException e) {
        throw new RuntimeException(e);
    } catch (NamespaceException e) {
        throw new RuntimeException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(parent);

    }

}

From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java

License:Open Source License

public WebClientsApplication fakeInit() {
    setWicketFilter(new WicketFilter() {
        private static final long serialVersionUID = 1L;

        /**/*from ww w.  j  av a  2s  .co m*/
         * @see wicket.protocol.http.WicketFilter#getFilterConfig()
         */
        @Override
        public FilterConfig getFilterConfig() {
            return new FilterConfig() {
                public String getFilterName() {
                    return "fakeservlet"; //$NON-NLS-1$
                }

                public String getInitParameter(String arg0) {
                    return Application.DEPLOYMENT;
                }

                public Enumeration<String> getInitParameterNames() {
                    return new Enumeration<String>() {
                        int i = 0;

                        /**
                         * @see java.util.Enumeration#hasMoreElements()
                         */
                        public boolean hasMoreElements() {
                            return i == 0;
                        }

                        /**
                         * @see java.util.Enumeration#nextElement()
                         */
                        public String nextElement() {
                            i++;
                            return Application.CONFIGURATION;
                        }
                    };
                }

                public ServletContext getServletContext() {
                    return new MockServletContext(WebClientsApplication.this, null);
                }
            };
        }
    });
    internalInit();
    return this;
}

From source file:name.martingeisse.admin.WebServerLauncher.java

License:Open Source License

/**
 * Launches the web server./*from w ww  .j  av a2s  .c om*/
 * @throws Exception on errors
 */
public static void launch() throws Exception {
    logger.debug("WebServerLauncher.launch(): begin");

    final EnumSet<DispatcherType> allDispatcherTypes = EnumSet.allOf(DispatcherType.class);

    // create and configure a servlet context
    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.getSessionHandler().getSessionManager().setMaxInactiveInterval(30 * 60);
    context.getSessionHandler().getSessionManager().setSessionIdPathParameterName("none");

    // add the global servlet listener
    context.addEventListener(new GlobalServletContext());
    context.addFilter(SideEffectsOriginRestrictionFilter.class, "/*", allDispatcherTypes);
    context.addFilter(AntiJsessionidUrlFilter.class, "/*", allDispatcherTypes);

    // the GZIP filter seems to cause problems on Jetty. The HTTP response either has
    // an incorrect or duplicate Content-Length header (my tools won't tell me...)
    //context.addFilter(GzipFilter.class, "/*", allDispatcherTypes);

    // JDBC connection-closing filter
    context.addFilter(EntityConnectionServletFilter.class, "/*", allDispatcherTypes);

    // add the Wicket filter
    final Filter wicketFilter = new WicketFilter();
    final FilterHolder wicketFilterHolder = new FilterHolder(wicketFilter);
    wicketFilterHolder.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    wicketFilterHolder.setInitParameter("applicationClassName",
            AdminWicketApplication.class.getCanonicalName());
    context.addFilter(wicketFilterHolder, "/*", allDispatcherTypes);

    // a default servlet is needed, otherwise the filters cannot catch the request
    context.addServlet(DefaultServlet.class, "/*");

    // configure SSL / HTTPS
    //      SslContextFactory sslContextFactory = new SslContextFactory("/Users/martin/.keystore");
    //      sslContextFactory.setKeyStorePassword("changeit");
    //      SslSocketConnector sslSocketConnector = new SslSocketConnector(sslContextFactory);
    //      sslSocketConnector.setPort(8443);

    final Server server = new Server(8888);
    //      server.addConnector(sslSocketConnector);
    server.setHandler(context);
    server.start();
    server.join();

    logger.debug("WebServerLauncher.launch(): end");
}

From source file:name.martingeisse.webeco.Main.java

License:Open Source License

/**
 * The main method./*from w w w . java 2 s. c om*/
 * @param args command-line arguments (ignored)
 * @throws Exception on errors
 */
public static void main(String[] args) throws Exception {

    // This seems to be needed to prevent a deadlock when creating a BufferedImage
    // while the server is running. I guess the reason is that this forces AWT to start.
    new BufferedImage(8, 16, BufferedImage.TYPE_BYTE_INDEXED);

    final EnumSet<DispatcherType> allDispatcherTypes = EnumSet.allOf(DispatcherType.class);

    final Filter wicketFilter = new WicketFilter();
    FilterHolder wicketFilterHolder = new FilterHolder(wicketFilter);
    wicketFilterHolder.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    wicketFilterHolder.setInitParameter("applicationClassName", WebecoApplication.class.getCanonicalName());

    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.getSessionHandler().getSessionManager().setMaxInactiveInterval(30 * 60);
    //      context.setInitParameter("useFakeFacebookLikeCount", "true");
    //      context.setInitParameter("username", "postgres");
    //      context.setInitParameter("password", "postgres");
    context.addEventListener(new GlobalServletContext());
    context.addFilter(AntiJsessionidUrlFilter.class, "/*", allDispatcherTypes);
    context.addFilter(CharacterGeneratorServletFilter.class, "/*", allDispatcherTypes);
    //      // context.addFilter(DomainEnforcementFilter.class, "/*", allDispatcherTypes);

    //      // the GZIP filter seems to cause problems on Jetty. The HTTP response either has
    //      // an incorrect or duplicate Content-Length header (my tools won't tell me...)
    ////      context.addFilter(GzipFilter.class, "/*", allDispatcherTypes);

    //      context.addFilter(JpaSessionServletFilter.class, "/*", allDispatcherTypes);
    context.addFilter(wicketFilterHolder, "/*", allDispatcherTypes);

    // a default servlet is needed, otherwise the filters cannot catch the request
    context.addServlet(DefaultServlet.class, "/*");

    //      ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
    //      context.setErrorHandler(errorHandler);
    //      errorHandler.addErrorPage(404, "/404");

    //      SslContextFactory sslContextFactory = new SslContextFactory("/Users/martin/.keystore");
    //      sslContextFactory.setKeyStorePassword("changeit");

    //      SslSocketConnector sslSocketConnector = new SslSocketConnector(sslContextFactory);
    //      sslSocketConnector.setPort(8443);

    final Server server = new Server(8080);
    //      server.addConnector(sslSocketConnector);
    server.setHandler(context);
    server.start();
    server.join();

}

From source file:org.apache.nutch.webui.NutchUiServer.java

License:Apache License

private static void startServer() throws Exception, InterruptedException {
    Server server = new Server(port);
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(DefaultServlet.class, "/*");

    context.addEventListener(new ContextLoaderListener(getContext()));
    context.addEventListener(new RequestContextListener());

    WicketFilter filter = new WicketFilter();
    filter.setFilterPath("/");
    FilterHolder holder = new FilterHolder(filter);
    holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
    context.addFilter(holder, "/*", Handler.DEFAULT);

    server.setHandler(context);/*  w ww .j a  v a 2s  .  c  o  m*/
    server.start();
    server.join();
}