@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); // rootContext.register(WebConfig.class); rootContext.scan("org.saiku.admin.config"); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); // FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter", new // CharacterEncodingFilter()); // fr.setInitParameter("encoding", "UTF-8"); // fr.setInitParameter("forceEncoding", "true"); // fr.addMappingForUrlPatterns(null, true, "/*"); // FilterRegistration.Dynamic fr = servletContext.addFilter("authFilter", new // AuthFilter()); // fr.addMappingForUrlPatterns(null, true, "/*"); // // fr = servletContext.addFilter("requestsLoggerServletFilter", new // RequestsLoggerServletFilter()); // fr.addMappingForUrlPatterns(null, true, "/*"); // // fr = servletContext.addFilter("TeeFilter", new // ch.qos.logback.access.servlet.TeeFilter()); // fr.addMappingForUrlPatterns(null, true, "/*"); }
@Override public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.register(SecurityConfig.class); container.addListener(new ContextLoaderListener(ctx)); container .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class) .addMappingForUrlPatterns(null, false, "/*"); Map<String, String> initParams = new HashMap<String, String>(); initParams.put("encoding", "UTF-8"); initParams.put("forceEncoding", "true"); FilterRegistration.Dynamic ceFilter = container.addFilter("encodingFilter", CharacterEncodingFilter.class); ceFilter.setInitParameters(initParams); ceFilter.addMappingForUrlPatterns(null, false, "/*"); ctx.setServletContext(container); ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.setLoadOnStartup(1); servlet.addMapping("/"); }
public static WebApplicationContext createJavaConfiguration(ServletContext context) { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.setServletContext(context); appContext.register(ZenContactConfiguration.class); appContext.refresh(); return appContext; }
/** * Set up default filters for character encoding and cors * * @param servletContext */ public static void defaultSetup(ServletContext servletContext, Class<?> appConfig) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(appConfig); // rootContext.register(ConfigApp.class); defaultSetup(servletContext, rootContext); }
/** * A Molgenis common web application initializer * * @param servletContext * @param appConfig * @param isDasUsed is the molgenis-omx-das module used? * @throws ServletException */ protected void onStartup(ServletContext servletContext, Class<?> appConfig, boolean isDasUsed) throws ServletException { // 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 ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); if (dispatcherServlet == null) { logger.warn( "ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'"); } else { final int maxSize = 32 * 1024 * 1024; int loadOnStartup = (isDasUsed ? 2 : 1); dispatcherServlet.setLoadOnStartup(loadOnStartup); dispatcherServlet.addMapping("/"); dispatcherServlet.setMultipartConfig( new MultipartConfigElement(null, maxSize, maxSize, maxSize)); dispatcherServlet.setInitParameter("dispatchOptionsRequest", "true"); } // add filters javax.servlet.FilterRegistration.Dynamic etagFilter = servletContext.addFilter("etagFilter", new ShallowEtagHeaderFilter()); etagFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "dispatcher"); // enable use of request scoped beans in FrontController servletContext.addListener(new RequestContextListener()); }
/** * Register and configure all Servlet container components necessary to power the web application. */ @Override public void onStartup(final ServletContext sc) throws ServletException { System.out.println("MyWebAppInitializer.onStartup()"); // Create the 'root' Spring application context final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); root.scan("org.baeldung.config.parent"); // root.getEnvironment().setDefaultProfiles("embedded"); // Manages the lifecycle of the root application context sc.addListener(new ContextLoaderListener(root)); // Handles requests into the application final AnnotationConfigWebApplicationContext childWebApplicationContext = new AnnotationConfigWebApplicationContext(); childWebApplicationContext.scan("org.baeldung.config.child"); final ServletRegistration.Dynamic appServlet = sc.addServlet("api", new DispatcherServlet(childWebApplicationContext)); appServlet.setLoadOnStartup(1); final Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException( "'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278"); } // spring security filter final DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain"); final Dynamic addedFilter = sc.addFilter("springSecurityFilterChain", springSecurityFilterChain); addedFilter.addMappingForUrlPatterns(null, false, "/*"); }
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try { // Force the timezone of application to UTC (required for Hibernate/JDBC) TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final String logLocation = (String) initialContext.lookup("java:comp/env/osp/osgpAdapterDomainPublicLighting/log-config"); LogbackConfigurer.initLogging(logLocation); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); servletContext.addListener(new ContextLoaderListener(rootContext)); } catch (final NamingException e) { throw new ServletException("naming exception", e); } catch (final FileNotFoundException e) { throw new ServletException("Logging file not found", e); } catch (final JoranException e) { throw new ServletException("Logback exception", e); } }
@Test public void testWithAuthServerAndGlobalMethodSecurity() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(ResourceServerAndAuthorizationServerContextAndGlobalMethodSecurity.class); context.refresh(); context.close(); }
@Override public void contextDestroyed(ServletContextEvent sce) { log.info("Destroying Web application"); WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; gwac.close(); log.debug("Web application destroyed"); }
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.setServletContext(servletContext); Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(WebConfig.class); servletContext.addListener(new ContextLoaderListener(ctx)); ServletRegistration.Dynamic servlet = servletContext.addServlet(DISPATCHER, new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppWebConfig.class); ctx.setServletContext(servletContext); Dynamic dynamic = servletContext.addServlet("web-dispatcher", new DispatcherServlet(ctx)); dynamic.addMapping("/"); dynamic.setLoadOnStartup(1); dynamic.setAsyncSupported(true); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(AppConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher", new DispatcherServlet(appContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(ToyboxConfiguration.class); ctx.setServletContext(container); ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.setLoadOnStartup(1); servlet.addMapping("/"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); webApplicationContext.register(ApplicationConfig.class, WebMvcConfig.class); Dynamic dynamc = servletContext.addServlet( "dispatcherServlet", new DispatcherServlet(webApplicationContext)); dynamc.addMapping("/api/v1/*"); dynamc.setLoadOnStartup(1); }
@Override public void onStartup(ServletContext ctx) throws ServletException { // Register the ContextLoaderListener AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(DistanceConfiguration.class); ctx.addListener(new ContextLoaderListener(appContext)); // Register the Servlet ServletRegistration.Dynamic registration = ctx.addServlet("distance", new DistanceServlet()); registration.setLoadOnStartup(1); registration.addMapping("/distance"); }
@Override public void onStartup(ServletContext container) { // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(AppConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
public DispatcherServletChannelInitializer() throws ServletException { MockServletContext servletContext = new MockServletContext(); MockServletConfig servletConfig = new MockServletConfig(servletContext); AnnotationConfigWebApplicationContext wac = new AnnotationConfigWebApplicationContext(); wac.setServletContext(servletContext); wac.setServletConfig(servletConfig); wac.register(WebConfig.class); wac.refresh(); this.dispatcherServlet = new DispatcherServlet(wac); this.dispatcherServlet.init(servletConfig); }
public void createSpringApp(String name) { JdbcConfig jdbc = buildJdbcProperties(rootContext, name); DataSource dataSource = null; if (rootContext.containsBean(name + "dataSource")) dataSource = (DataSource) rootContext.getBean(name + "dataSource"); SessionFactory sessionFactory = buildSession(name, config, dataSource, jdbc); beanFactory.registerSingleton(name + "SessionFactory", sessionFactory); beanFactory.registerSingleton( name + "HibernateTransactionManager", buildTransactionManager(name, config, dataSource, jdbc)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(WebAppConfig.class); ctx.register(SecurityConfig.class); servletContext.addListener(new ContextLoaderListener(ctx)); ctx.setServletContext(servletContext); Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
@Override public void onStartup(ServletContext container) throws ServletException { container.getServletRegistration("default").addMapping("/resources/*"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootContextConfiguration.class); container.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext servletContext = new AnnotationConfigWebApplicationContext(); servletContext.register(ServletContextConfiguration.class); ServletRegistration.Dynamic dispatcher = container.addServlet("springDispatcher", new DispatcherServlet(servletContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.getEnvironment().setActiveProfiles("dev"); ctx.register(WebAppConfig.class); servletContext.addListener(new ContextLoaderListener(ctx)); ctx.setServletContext(servletContext); registerHiddenHttpMethodFilter(servletContext); Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
private JdbcConfig buildJdbcProperties( AnnotationConfigWebApplicationContext rootContext, String name) { return JdbcConfig.builder() .properties((Properties) rootContext.getBean("propertyFactory")) .name(name) .build(); }
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(SpringWebAppConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("springDispatcher", new DispatcherServlet(appContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); // UtF8 Character Filter. FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); fr.addMappingForUrlPatterns(null, true, "/*"); }
public void onStartup(ServletContext container) throws javax.servlet.ServletException { AnnotationConfigWebApplicationContext applContext = new AnnotationConfigWebApplicationContext(); applContext.register(Config.class); container.addListener(new ContextLoaderListener(applContext)); FilterRegistration.Dynamic characterEncodingFilter = container.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns( EnumSet.allOf(DispatcherType.class), true, "/*"); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(applContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
public static void createAndStartServer() { server = new Server(HTTP_SERVER_PORT); HashSessionIdManager idmanager = new HashSessionIdManager(); server.setSessionIdManager(idmanager); AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); applicationContext.register(JPAApplicationConfiguration.class); applicationContext.refresh(); appContext = applicationContext; try { server.setHandler(getServletContextHandler(applicationContext)); server.start(); } catch (Exception e) { log.error("Error starting server", e); } }
@Override public void onStartup(ServletContext cs) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringRootConfig.class); // Manage the lifecycle of the root application context cs.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(MvcConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = cs.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(MvcConfiguration.class); servletContext.addListener(new ContextLoaderListener(context)); servletContext.addListener( new HttpSessionListener() { @Override public void sessionCreated(HttpSessionEvent httpSessionEvent) {} @Override public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { System.out.println("Session destroyed."); // TODO: Add this back in before deployment LoginInfo loginInfo = (LoginInfo) httpSessionEvent.getSession().getAttribute("loginInfo"); if (loginInfo != null) { RestTemplate restTemplate = new RestTemplate(); String url = "https://canvas.instructure.com/login/oauth2/token"; HttpHeaders headers = new HttpHeaders(); if (loginInfo.getAccessToken() != null) { headers.set("Authorization", "Bearer " + loginInfo.getAccessToken()); HttpEntity requestEntity = new HttpEntity(headers); restTemplate.exchange( url, HttpMethod.DELETE, requestEntity, Object.class, new HashMap<String, String>()); } } } }); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); dispatcher.addMapping("/"); dispatcher.setLoadOnStartup(1); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); // Déclaration du la classe de configuration du context (dataSource, repositories, // spring-security ...) rootContext.register(ContextConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); // Création du distapcher de servlet AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(WebMvcConfig.class); // Déclaration du distapcher de servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }