use of org.springframework.web.context.WebApplicationContext in project redisson by redisson.
the class RedissonSessionManagerTest method testExpire.
@Test
public void testExpire() throws Exception {
Initializer.CONFIG_CLASS = ConfigTimeout.class;
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
WebApplicationContext wa = WebApplicationContextUtils.getRequiredWebApplicationContext(server.getServletContext());
SessionEventsListener listener = wa.getBean(SessionEventsListener.class);
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
Cookie cookie = cookieStore.getCookies().get(0);
Assert.assertEquals(1, listener.getSessionCreatedEvents());
Assert.assertEquals(0, listener.getSessionExpiredEvents());
Executor.closeIdleConnections();
Thread.sleep(6000);
Assert.assertEquals(1, listener.getSessionCreatedEvents());
Assert.assertEquals(1, listener.getSessionExpiredEvents());
executor = Executor.newInstance();
cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(executor, "test", "null");
Assert.assertEquals(2, listener.getSessionCreatedEvents());
write(executor, "test", "1234");
Thread.sleep(3000);
read(executor, "test", "1234");
Thread.sleep(3000);
Assert.assertEquals(1, listener.getSessionExpiredEvents());
Thread.sleep(1000);
Assert.assertEquals(1, listener.getSessionExpiredEvents());
Thread.sleep(3000);
Assert.assertEquals(2, listener.getSessionExpiredEvents());
Executor.closeIdleConnections();
server.stop();
}
use of org.springframework.web.context.WebApplicationContext in project redisson by redisson.
the class RedissonSessionManagerTest method testInvalidate.
@Test
public void testInvalidate() throws Exception {
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
WebApplicationContext wa = WebApplicationContextUtils.getRequiredWebApplicationContext(server.getServletContext());
SessionEventsListener listener = wa.getBean(SessionEventsListener.class);
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
Cookie cookie = cookieStore.getCookies().get(0);
Assert.assertEquals(1, listener.getSessionCreatedEvents());
Assert.assertEquals(0, listener.getSessionDeletedEvents());
invalidate(executor);
Assert.assertEquals(1, listener.getSessionCreatedEvents());
Assert.assertEquals(1, listener.getSessionDeletedEvents());
Executor.closeIdleConnections();
executor = Executor.newInstance();
cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(executor, "test", "null");
Executor.closeIdleConnections();
server.stop();
}
use of org.springframework.web.context.WebApplicationContext in project spring-boot by spring-projects.
the class SpringBootTestWebEnvironmentMockTests method validateWebApplicationContextIsSet.
@Test
public void validateWebApplicationContextIsSet() {
WebApplicationContext fromServletContext = WebApplicationContextUtils.getWebApplicationContext(this.servletContext);
assertThat(fromServletContext).isSameAs(this.context);
}
use of org.springframework.web.context.WebApplicationContext in project spring-boot by spring-projects.
the class SpringBootServletInitializer method createRootApplicationContext.
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
SpringApplicationBuilder builder = createSpringApplicationBuilder();
builder.main(getClass());
ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
if (parent != null) {
this.logger.info("Root context already created (using as parent).");
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
builder.initializers(new ParentContextApplicationContextInitializer(parent));
}
builder.initializers(new ServletContextApplicationContextInitializer(servletContext));
builder.listeners(new ServletContextApplicationListener(servletContext));
builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class);
builder = configure(builder);
SpringApplication application = builder.build();
if (application.getSources().isEmpty() && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
application.getSources().add(getClass());
}
Assert.state(!application.getSources().isEmpty(), "No SpringApplication sources have been defined. Either override the " + "configure method or add an @Configuration annotation");
// Ensure error pages are registered
if (this.registerErrorPageFilter) {
application.getSources().add(ErrorPageFilterConfiguration.class);
}
return run(application);
}
use of org.springframework.web.context.WebApplicationContext in project spring-boot by spring-projects.
the class SpringBootServletInitializer method onStartup.
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Logger initialization is deferred in case a ordered
// LogServletContextInitializer is being used
this.logger = LogFactory.getLog(getClass());
WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
if (rootAppContext != null) {
servletContext.addListener(new ContextLoaderListener(rootAppContext) {
@Override
public void contextInitialized(ServletContextEvent event) {
// no-op because the application context is already initialized
}
});
} else {
this.logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not " + "return an application context");
}
}
Aggregations