use of org.apache.openejb.server.httpd.HttpListenerRegistry 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 org.apache.openejb.server.httpd.HttpListenerRegistry in project tomee by apache.
the class HttpUtil method removeFilter.
public static void removeFilter(final String mapping, final WebContext wc) {
final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
if (registry == null || mapping == null) {
return;
}
final Collection<HttpListener> filters = registry.removeHttpFilter(pattern(wc.getContextRoot(), mapping));
for (HttpListener listener : filters) {
final Filter filter = ((FilterListener) listener).getDelegate();
filter.destroy();
wc.destroy(filter);
}
filters.clear();
}
use of org.apache.openejb.server.httpd.HttpListenerRegistry in project tomee by apache.
the class HttpUtil method addFilter.
public static boolean addFilter(final String classname, final WebContext wc, final String mapping, final FilterConfig config) {
final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
if (registry == null || mapping == null) {
return false;
}
final FilterListener listener;
try {
listener = new FilterListener((Filter) wc.newInstance(wc.getClassLoader().loadClass(classname)), wc.getContextRoot());
listener.getDelegate().init(config);
} catch (Exception e) {
throw new OpenEJBRuntimeException(e);
}
registry.addHttpFilter(listener, pattern(wc.getContextRoot(), mapping));
return true;
}
use of org.apache.openejb.server.httpd.HttpListenerRegistry in project tomee by apache.
the class HttpUtil method removeServlet.
public static void removeServlet(final String mapping, final WebContext wc) {
final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
if (registry == null || mapping == null) {
return;
}
final Servlet servlet = ((ServletListener) registry.removeHttpListener(pattern(wc.getContextRoot(), mapping))).getDelegate();
servlet.destroy();
wc.destroy(servlet);
if (servlet.getClass().equals("org.apache.jasper.servlet.JspServlet")) {
SystemInstance.get().getComponent(ServletContext.class).removeAttribute("org.apache.tomcat.InstanceManager");
}
}
Aggregations