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(); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.addListener(new RequestContextListener()); // verifying configs for features activation Set<String> profiles = new HashSet<String>(); if (isEmailFeaturesEnabled()) { profiles.add("email"); } if (isCdnFeaturesEnabled()) { profiles.add("cdn"); } if (isSslFeaturesEnabled()) { profiles.add("ssl"); } servletContext.setInitParameter("spring.profiles.active", StringUtils.arrayToCommaDelimitedString(profiles.toArray())); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { //create a new Spring webapp context and add core listeners for requests and lifecycle events AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext(); servletContext.addListener(RequestContextListener.class); servletContext.addListener(new ContextLoaderListener(webAppContext)); //tell Spring where to find @Configuration classes for further Spring config webAppContext.setConfigLocation(SPRING_CONFIG_PACKAGE); //create Spring's Dispatcher servlet and tell the servletContext it is present DispatcherServlet dispatcherServlet = new DispatcherServlet(webAppContext); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", dispatcherServlet); //perform additional dispatcher servlet config dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
/** * Test of getPage method, of class fr.paris.lutece.portal.web.search.SearchApp. * * @throws SiteMessageException */ public void testGetPage( ) throws SiteMessageException { System.out.println( "getPage" ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.addParameter( "query", "lutece" ); request.addParameter( "items_per_page", "5" ); RequestContextListener listener = new RequestContextListener( ); ServletContext context = new MockServletContext( ); listener.requestInitialized( new ServletRequestEvent( context, request ) ); int nMode = 0; Plugin plugin = null; SearchApp instance = SpringContextService.getBean( "core.xpage.search" ); XPage result = instance.getPage( request, nMode, plugin ); listener.requestDestroyed( new ServletRequestEvent( context, request ) ); }
public static void startServer(int port) throws Exception { final DeploymentInfo deployment = Servlets.deployment().setClassLoader(WebServer.class.getClassLoader()); deployment.setContextPath(""); deployment.setDeploymentName("membrane"); deployment.addInitParameter("contextConfigLocation", "classpath:context/application-context.xml"); deployment.setResourceManager(new FileResourceManager(new File("."), 0)); deployment.addListener(Servlets.listener(ContextLoaderListener.class)); deployment.addListener(Servlets.listener(RequestContextListener.class)); deployment.addServlet(Servlets.servlet("dispatcher", DispatcherServlet.class).addMapping("/*") .addInitParam("contextConfigLocation", "classpath:context/dispatcher-servlet.xml")); deployment.addFilter(Servlets.filter(CharacterEncodingFilter.class).addInitParam("forceEncoding", "true") .addInitParam("encoding", "UTF-8")); final DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment); manager.deploy(); final Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0").setHandler(manager.start()).build(); server.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // graceful shutdown of everything server.stop(); try { manager.stop(); } catch (ServletException e) { } manager.undeploy(); } }); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { System.out.println("****** Application Context Initialization ******"); initSecurityFilter(servletContext); servletContext.addListener(new RequestContextListener()); servletContext.getSessionCookieConfig().setName(SecurityConstants.SESSION_COOKIE_NAME); super.onStartup(servletContext); }
@Override public void onStartup(ServletContext servletContext) // Define qual é o contexto ativo no momento throws ServletException { super.onStartup(servletContext); servletContext.addListener(RequestContextListener.class); servletContext.setInitParameter( AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, "dev"); }
/** * 自定义,并注册 listener 演示 * 直接用 Bean ,也可以用 ServletListenerRegistrationBean * * @return */ // 向系统注册一个 RequestContextListener Bean ,这样在其他组件中就可以使用了 // CustomUserDetailsService 用到,用于截获 HttpServletRequest // @Autowired // private HttpServletRequest request; @Bean public RequestContextListener requestContextListener() { return new RequestContextListener(); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); registerProxyFilter(servletContext, "springSecurityFilterChain"); registerProxyFilter(servletContext, "oauth2ClientContextFilter"); registerProxyFilter(servletContext, "customOauth2ClientContextFilter"); servletContext.addListener(RequestContextListener.class); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { System.out.println("Version: " + VersionUtils.getCurrentVersion()); properties = loadProperties(); LogUtils.initLogging(getConfigDir(false), (TypedProperties) properties); AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); applicationContext.scan("org.jumpmind.metl"); MutablePropertySources sources = applicationContext.getEnvironment().getPropertySources(); sources.addLast(new PropertiesPropertySource("passed in properties", properties)); servletContext.addListener(new ContextLoaderListener(applicationContext)); servletContext.addListener(this); servletContext.addListener(new RequestContextListener()); AnnotationConfigWebApplicationContext dispatchContext = new AnnotationConfigWebApplicationContext(); dispatchContext.setParent(applicationContext); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatchContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/api/*"); applicationContextRef.set(dispatchContext); ServletRegistration.Dynamic apidocs = servletContext.addServlet("docs", DefaultServlet.class); apidocs.addMapping("/api.html", "/ws-api.html", "/doc/*", "/ace/*"); ServletRegistration.Dynamic vaadin = servletContext.addServlet("vaadin", AppServlet.class); vaadin.setAsyncSupported(true); vaadin.setInitParameter("org.atmosphere.cpr.asyncSupport", JSR356AsyncSupport.class.getName()); vaadin.setInitParameter("beanName", "appUI"); vaadin.addMapping("/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); Dynamic faces = servletContext.addServlet("Faces Servlet", "javax.faces.webapp.FacesServlet"); faces.addMapping("*.html"); //ConfigureListener listener = new ConfigureListener(); //servletContext.addListener(listener); servletContext.addListener(new RequestContextListener()); Dynamic elResolverInitializer = servletContext.addServlet( "elResolverInit", new ELResolverInitializerServlet()); elResolverInitializer.setLoadOnStartup(2); }
protected void createWebApplicationContext(ServletContext servletContext, Class clazz) { log.info("Creating Web Application Context started"); List<Class> configClasses = new ArrayList<>(); configClasses.add(clazz); // let's determine if this is a cloud based server Cloud cloud = getCloud(); String activeProfiles = System.getProperty(SPRING_PROFILES_ACTIVE); if (StringUtils.isEmpty(activeProfiles)) { if (cloud == null) { // if no active profiles are specified, we default to these profiles activeProfiles = String.format("%s,%s,%s,%s,%s", MONGODB_LOCAL,REDIS_LOCAL,RABBIT_LOCAL,ELASTICSEARCH_LOCAL,LOCAL); } else { activeProfiles = String.format("%s,%s,%s,%s,%s", MONGODB_CLOUD,REDIS_CLOUD,RABBIT_CLOUD,ELASTICSEARCH_CLOUD,CLOUD); } } log.info("Active spring profiles: " + activeProfiles); // load local or cloud based configs if (cloud != null) { // list available service - fail servlet initializing if we are missing one that we require below printAvailableCloudServices(cloud.getServiceInfos()); } AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(configClasses.toArray(new Class[configClasses.size()])); servletContext.addListener(new ContextLoaderListener(appContext)); servletContext.addListener(new RequestContextListener()); // log.info("Creating Web Application Context completed"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { /* Setting the configuration classes */ AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("qa.qcri.aidr.data.config"); /*Configuring error handler filter for errors out isde the controllers FilterRegistration.Dynamic errorHandlerFilter = servletContext.addFilter("errorHandlerFilter", new ErrorHandlerFilter()); errorHandlerFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); */ FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", new org.springframework.web.filter.CharacterEncodingFilter()); encodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); encodingFilter.setInitParameter("encoding", "UTF-8"); encodingFilter.setInitParameter("forceEncoding", "true"); /* Adding context listener */ servletContext.addListener(new ContextLoaderListener(context)); /* Adding request listener */ servletContext.addListener(new RequestContextListener()); /* Configuring dispatcher servlet for spring mvc */ /*CustomDispatcherServlet servlet = new CustomDispatcherServlet(context); */ ServletRegistration.Dynamic appServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); appServlet.setLoadOnStartup(1); appServlet.addMapping("/*"); }
@Bean @ConditionalOnMissingBean(RequestContextListener.class) public RequestContextListener requestContextListener() { return new RequestContextListener(); }
@Bean public RequestContextListener requestContextListener() { return new RequestContextListener(); }
@Bean @ConditionalOnMissingBean({ RequestContextListener.class, RequestContextFilter.class }) public static RequestContextFilter requestContextFilter() { return new OrderedRequestContextFilter(); }
protected void addSpringRequestContextListener(ServletContext ctx, AnnotationConfigWebApplicationContext applicationContext) { ctx.addListener(RequestContextListener.class); }
@Bean @ConditionalOnMissingBean({ RequestContextListener.class, RequestContextFilter.class }) public RequestContextFilter requestContextFilter() { return new OrderedRequestContextFilter(); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { InitializationUtils.registerListener(servletContext, RequestContextListener.class); InitializationUtils.registerFilter(servletContext, "springSecurityFilterChain", DelegatingFilterProxy.class, "/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.addListener(RequestContextListener.class); servletContext.setInitParameter("spring.profiles.active", "dev"); }
public TestMetadata() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestDimensions() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestData() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestDataAllDomains() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestSearch() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestDocuments() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestGroupsAndDomains() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestSchema() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestBulkDownloads() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestCodes() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestCodesAllDomains() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
public TestDefinitions() { super(new WebAppDescriptor.Builder("org.fao.faostat.api.web.rest").contextPath("testing") .contextParam("contextConfigLocation", "classpath:testApplicationContext.xml") .contextListenerClass(ContextLoaderListener.class).servletClass(SpringServlet.class) .requestListenerClass(RequestContextListener.class).build()); }
@Override public void onStartup(javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException { super.onStartup(servletContext); servletContext.addListener(RequestContextListener.class); }