use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.
the class WebBrokerInitializerTest method contextInitialized_waitUntilStartedReturnsFalse_ExcThrown.
@Test(expected = BrokerLifecycleException.class)
public void contextInitialized_waitUntilStartedReturnsFalse_ExcThrown() throws Exception {
ServletContext sc = mock(ServletContext.class);
BrokerService broker = mock(BrokerService.class);
doReturn(false).when(broker).waitUntilStarted();
WebBrokerInitializer i = spy(WebBrokerInitializer.class);
doReturn(broker).when(i).createBroker(sc);
i.contextInitialized(new ServletContextEvent(sc));
}
use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.
the class ServletContextHolderInitializerTest method contextDestroyed.
@Test
public void contextDestroyed() {
ServletContextHolderInitializer i = new ServletContextHolderInitializer();
ServletContext sc = Mockito.mock(ServletContext.class);
ServletContextHolder.setServletContext(sc);
i.contextDestroyed(new ServletContextEvent(sc));
assertFalse(ServletContextHolder.isServletContextSet());
}
use of javax.servlet.ServletContextEvent in project tomee by apache.
the class HttpUtil method addServlet.
public static boolean addServlet(final String classname, final WebContext wc, final String mapping) {
final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
if (registry == null || mapping == null) {
return false;
}
final ServletListener listener;
try {
ServletContext servletContext = wc.getServletContext();
if (servletContext == null) {
servletContext = SystemInstance.get().getComponent(ServletContext.class);
}
if ("javax.faces.webapp.FacesServlet".equals(classname)) {
try {
// faking it to let the FacesServlet starting
// NOTE: needs myfaces-impl + tomcat-jasper (JspFactory)
// TODO: handle the whole lifecycle (cleanup mainly) + use myfaces SPI to make scanning really faster (take care should work in tomee were we already have it impl)
final Class<?> mfListenerClass = wc.getClassLoader().loadClass("org.apache.myfaces.webapp.StartupServletContextListener");
final ServletContextListener servletContextListener = ServletContextListener.class.cast(mfListenerClass.newInstance());
servletContext.setAttribute("javax.enterprise.inject.spi.BeanManager", new InjectableBeanManager(wc.getWebBeansContext().getBeanManagerImpl()));
final Thread thread = Thread.currentThread();
final ClassLoader old = setClassLoader(wc, thread);
try {
servletContextListener.contextInitialized(new ServletContextEvent(servletContext));
} finally {
thread.setContextClassLoader(old);
}
servletContext.removeAttribute("javax.enterprise.inject.spi.BeanManager");
} catch (final Exception e) {
// no-op
}
}
final Thread thread = Thread.currentThread();
final ClassLoader old = setClassLoader(wc, thread);
try {
listener = new ServletListener((Servlet) wc.newInstance(wc.getClassLoader().loadClass(classname)), wc.getContextRoot());
final ServletContext sc = servletContext;
listener.getDelegate().init(new ServletConfig() {
@Override
public String getServletName() {
return classname;
}
@Override
public ServletContext getServletContext() {
return sc;
}
@Override
public String getInitParameter(final String s) {
return sc.getInitParameter(s);
}
@Override
public Enumeration<String> getInitParameterNames() {
final Enumeration<String> parameterNames = sc.getInitParameterNames();
return parameterNames == null ? Collections.<String>emptyEnumeration() : parameterNames;
}
});
} finally {
thread.setContextClassLoader(old);
}
} catch (final Exception e) {
throw new OpenEJBRuntimeException(e);
}
registry.addHttpListener(listener, pattern(wc.getContextRoot(), "/".equals(mapping) ? "/*" : mapping));
return true;
}
use of javax.servlet.ServletContextEvent in project tomee by apache.
the class LiveReloadInstaller method install.
public static void install(String path, final int port, final String folder) {
final Server server = TomcatHelper.getServer();
if (server == null) {
throw new IllegalStateException("tomcat not yet starting");
}
// checking which one is localhost could be better but should be fine
final Service service = server.findServices()[0];
final Engine engine = Engine.class.cast(service.getContainer());
final Container host = engine.findChild(engine.getDefaultHost());
if (LifecycleState.STARTED != host.getState()) {
throw new IllegalStateException("host not started, call LiveReloadInstaller.install() later.");
}
// add connector
final Connector connector = new Connector();
connector.setPort(port);
connector.setAttribute("connectionTimeout", "30000");
service.addConnector(connector);
// and the endpoint and start the watcher
final Closeable watch = Instances.get().getWatcher().watch(folder);
final LiveReloadWebapp liveReloadWebapp = new LiveReloadWebapp(path);
liveReloadWebapp.addApplicationLifecycleListener(new ServletContextListener() {
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
servletContextEvent.getServletContext().log("Started livereload server on port " + port);
}
@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
try {
watch.close();
} catch (final IOException e) {
// no-op: not that important, we shutdown anyway
}
}
});
host.addChild(liveReloadWebapp);
}
use of javax.servlet.ServletContextEvent in project che by eclipse.
the class CheBootstrapTest method environment_variables_prefixed_with_che_underscore_convert_double_underscores_into_one_underscore_in_variable_name.
@Test
public void environment_variables_prefixed_with_che_underscore_convert_double_underscores_into_one_underscore_in_variable_name() throws Exception {
Properties cheProperties = new Properties();
cheProperties.put("che.some.other.name_with_underscores", "che_value");
cheProperties.put("che.some.name", "NULL");
writePropertiesFile(che, "che.properties", cheProperties);
Properties userProperties = new Properties();
userProperties.put("che.some.other.name_with_underscores", "user_value");
writePropertiesFile(userCongDir, "user.properties", userProperties);
systemPropertiesHelper.property("che.some.other.name_with_underscores", "che_dot_system_property_value");
ModuleScanner.modules.add(binder -> binder.bind(TestConfOverrideWithUnderscoresComponent.class));
cheBootstrap.contextInitialized(new ServletContextEvent(servletContext));
Injector injector = retrieveComponentFromServletContext(Injector.class);
TestConfOverrideWithUnderscoresComponent testComponent = injector.getInstance(TestConfOverrideWithUnderscoresComponent.class);
assertEquals(testComponent.otherString, System.getenv("CHE_SOME_OTHER_NAME__WITH__UNDERSCORES"));
}
Aggregations