use of javax.servlet.ServletContextEvent in project che by eclipse.
the class CheBootstrapTest method propertiesFromUserSpecifiedLocationOverrideCheProperties.
@Test
public void propertiesFromUserSpecifiedLocationOverrideCheProperties() throws Exception {
systemPropertiesHelper.property(CHE_LOCAL_CONF_DIR, userCongDir.getAbsolutePath());
Properties cheProperties = new Properties();
cheProperties.put("che.some.name", "che_value");
writePropertiesFile(che, "che.properties", cheProperties);
Properties userProperties = new Properties();
userProperties.put("che.some.name", "user_value");
writePropertiesFile(userCongDir, "user.properties", userProperties);
ModuleScanner.modules.add(binder -> binder.bind(TestConfOverrideComponent.class));
cheBootstrap.contextInitialized(new ServletContextEvent(servletContext));
Injector injector = retrieveComponentFromServletContext(Injector.class);
TestConfOverrideComponent testComponent = injector.getInstance(TestConfOverrideComponent.class);
assertEquals(testComponent.string, "user_value");
}
use of javax.servlet.ServletContextEvent in project metrics by dropwizard.
the class InstrumentedFilterContextListenerTest method injectsTheMetricRegistryIntoTheServletContext.
@Test
public void injectsTheMetricRegistryIntoTheServletContext() throws Exception {
final ServletContext context = mock(ServletContext.class);
final ServletContextEvent event = mock(ServletContextEvent.class);
when(event.getServletContext()).thenReturn(context);
listener.contextInitialized(event);
verify(context).setAttribute("com.codahale.metrics.servlet.InstrumentedFilter.registry", registry);
}
use of javax.servlet.ServletContextEvent in project jetty.project by eclipse.
the class ContextHandler method stopContext.
/* ------------------------------------------------------------ */
protected void stopContext() throws Exception {
//stop all the handler hierarchy
super.doStop();
//Call the context listeners
ServletContextEvent event = new ServletContextEvent(_scontext);
Collections.reverse(_destroySerletContextListeners);
MultiException ex = new MultiException();
for (ServletContextListener listener : _destroySerletContextListeners) {
try {
callContextDestroyed(listener, event);
} catch (Exception x) {
ex.add(x);
}
}
ex.ifExceptionThrow();
}
use of javax.servlet.ServletContextEvent in project jetty.project by eclipse.
the class TestJNDI method testThreadContextClassloaderAndCurrentContext.
@Test
public void testThreadContextClassloaderAndCurrentContext() throws Exception {
//create a jetty context, and start it so that its classloader it created
//and it is the current context
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
ContextHandler ch = new ContextHandler();
URLClassLoader chLoader = new URLClassLoader(new URL[0], currentLoader);
ch.setClassLoader(chLoader);
Server server = new Server();
HandlerList hl = new HandlerList();
server.setHandler(hl);
hl.addHandler(ch);
//Create another one
ContextHandler ch2 = new ContextHandler();
URLClassLoader ch2Loader = new URLClassLoader(new URL[0], currentLoader);
ch2.setClassLoader(ch2Loader);
hl.addHandler(ch2);
try {
ch.setContextPath("/ch");
ch.addEventListener(new ServletContextListener() {
private Context comp;
private Object testObj = new Object();
public void contextInitialized(ServletContextEvent sce) {
try {
InitialContext initCtx = new InitialContext();
Context java = (Context) initCtx.lookup("java:");
assertNotNull(java);
comp = (Context) initCtx.lookup("java:comp");
assertNotNull(comp);
Context env = ((Context) comp).createSubcontext("env");
assertNotNull(env);
env.bind("ch", testObj);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public void contextDestroyed(ServletContextEvent sce) {
try {
assertNotNull(comp);
assertEquals(testObj, comp.lookup("env/ch"));
comp.destroySubcontext("env");
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
});
//Starting the context makes it current and creates a classloader for it
ch.start();
ch2.setContextPath("/ch2");
ch2.addEventListener(new ServletContextListener() {
private Context comp;
private Object testObj = new Object();
public void contextInitialized(ServletContextEvent sce) {
try {
InitialContext initCtx = new InitialContext();
comp = (Context) initCtx.lookup("java:comp");
assertNotNull(comp);
//another context's bindings should not be visible
Context env = ((Context) comp).createSubcontext("env");
try {
env.lookup("ch");
fail("java:comp/env visible from another context!");
} catch (NameNotFoundException e) {
//expected
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public void contextDestroyed(ServletContextEvent sce) {
try {
assertNotNull(comp);
comp.destroySubcontext("env");
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
});
//make the new context the current one
ch2.start();
} finally {
ch.stop();
ch2.stop();
Thread.currentThread().setContextClassLoader(currentLoader);
}
}
use of javax.servlet.ServletContextEvent in project JessMA by ldcsaa.
the class SpringInjectFilter method init.
@Override
public void init() {
servletContext = HttpHelper.getServletContext();
springMap = new HashMap<CoupleKey<Class<?>, Method>, SpringAttr[]>();
context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
if (context == null) {
listener = new ContextLoaderListener();
listener.contextInitialized(new ServletContextEvent(servletContext));
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
}
Aggregations