Search in sources :

Example 1 with RequestContextListener

use of org.springframework.web.context.request.RequestContextListener in project nutch by apache.

the class NutchUiServer method startServer.

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);
    server.start();
    server.join();
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) Context(org.mortbay.jetty.servlet.Context) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) RequestContextListener(org.springframework.web.context.request.RequestContextListener) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) WicketFilter(org.apache.wicket.protocol.http.WicketFilter) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener)

Example 2 with RequestContextListener

use of org.springframework.web.context.request.RequestContextListener in project molgenis by molgenis.

the class MolgenisWebAppInitializer method onStartup.

/**
 * A Molgenis common web application initializer
 */
protected void onStartup(ServletContext servletContext, Class<?> appConfig, int maxFileSize) {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(appConfig);
    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));
    // Register and map the dispatcher servlet
    DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext);
    dispatcherServlet.setDispatchOptionsRequest(true);
    // instead of throwing a 404 when a handler is not found allow for custom handling
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
    ServletRegistration.Dynamic dispatcherServletRegistration = servletContext.addServlet("dispatcher", dispatcherServlet);
    if (dispatcherServletRegistration == null) {
        LOG.warn("ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'");
    } else {
        final long maxSize = (long) maxFileSize * MB;
        dispatcherServletRegistration.addMapping("/");
        dispatcherServletRegistration.setMultipartConfig(new MultipartConfigElement(null, maxSize, maxSize, FILE_SIZE_THRESHOLD));
    }
    // add filters
    Dynamic browserDetectionFiler = servletContext.addFilter("browserDetectionFilter", BrowserDetectionFilter.class);
    browserDetectionFiler.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*");
    Dynamic etagFilter = servletContext.addFilter("etagFilter", ShallowEtagHeaderFilter.class);
    etagFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "dispatcher");
    Dynamic corsFilter = servletContext.addFilter("corsFilter", CorsFilter.class);
    corsFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/api/*");
    corsFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/fdp/*");
    // enable use of request scoped beans in FrontController
    servletContext.addListener(new RequestContextListener());
    servletContext.addListener(HttpSessionEventPublisher.class);
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) RequestContextListener(org.springframework.web.context.request.RequestContextListener) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 3 with RequestContextListener

use of org.springframework.web.context.request.RequestContextListener in project ocvn by devgateway.

the class WebInitializer method onStartup.

@Override
public void onStartup(final ServletContext sc) throws ServletException {
    sc.addFilter("Spring OpenEntityManagerInViewFilter", org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class).addMappingForUrlPatterns(null, false, "/*");
    FilterRegistration filter = sc.addFilter("wicket-filter", WicketFilter.class);
    filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
    filter.setInitParameter(PARAM_APP_BEAN, "formsWebApplication");
    // This line is the only surprise when comparing to the equivalent
    // web.xml. Without some initialization seems to be missing.
    filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    filter.addMappingForUrlPatterns(null, false, "/*");
    // // Request Listener
    sc.addListener(new RequestContextListener());
    sc.addListener(new HttpSessionEventPublisher());
}
Also used : SpringWebApplicationFactory(org.apache.wicket.spring.SpringWebApplicationFactory) RequestContextListener(org.springframework.web.context.request.RequestContextListener) HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) FilterRegistration(javax.servlet.FilterRegistration)

Example 4 with RequestContextListener

use of org.springframework.web.context.request.RequestContextListener in project oc-explorer by devgateway.

the class WebInitializer method onStartup.

@Override
public void onStartup(final ServletContext sc) throws ServletException {
    sc.addFilter("Spring OpenEntityManagerInViewFilter", org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class).addMappingForUrlPatterns(null, false, "/*");
    FilterRegistration filter = sc.addFilter("wicket-filter", WicketFilter.class);
    filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
    filter.setInitParameter(PARAM_APP_BEAN, "formsWebApplication");
    // This line is the only surprise when comparing to the equivalent
    // web.xml. Without some initialization seems to be missing.
    filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    filter.addMappingForUrlPatterns(null, false, "/*");
    // // Request Listener
    sc.addListener(new RequestContextListener());
    sc.addListener(new HttpSessionEventPublisher());
}
Also used : SpringWebApplicationFactory(org.apache.wicket.spring.SpringWebApplicationFactory) RequestContextListener(org.springframework.web.context.request.RequestContextListener) HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) FilterRegistration(javax.servlet.FilterRegistration)

Aggregations

RequestContextListener (org.springframework.web.context.request.RequestContextListener)4 FilterRegistration (javax.servlet.FilterRegistration)2 SpringWebApplicationFactory (org.apache.wicket.spring.SpringWebApplicationFactory)2 HttpSessionEventPublisher (org.springframework.security.web.session.HttpSessionEventPublisher)2 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 Dynamic (javax.servlet.FilterRegistration.Dynamic)1 WicketFilter (org.apache.wicket.protocol.http.WicketFilter)1 Server (org.mortbay.jetty.Server)1 Context (org.mortbay.jetty.servlet.Context)1 FilterHolder (org.mortbay.jetty.servlet.FilterHolder)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)1