use of javax.servlet.ServletConfig in project opennms by OpenNMS.
the class PollerConfigServlet method reloadFiles.
/**
* <p>reloadFiles</p>
*
* @throws javax.servlet.ServletException if any.
*/
public void reloadFiles() throws ServletException {
ServletConfig config = this.getServletConfig();
try {
PollerConfigFactory.init();
pollerFactory = PollerConfigFactory.getInstance();
pollerConfig = pollerFactory.getConfiguration();
if (pollerConfig == null) {
throw new ServletException("Poller Configuration file is empty");
}
} catch (Throwable e) {
throw new ServletException(e.getMessage());
}
initPollerServices();
this.redirectSuccess = config.getInitParameter("redirect.success");
if (this.redirectSuccess == null) {
throw new ServletException("Missing required init parameter: redirect.success");
}
}
use of javax.servlet.ServletConfig in project opennms by OpenNMS.
the class ImportAssetsServlet method init.
/**
* Looks up the <code>redirect.success</code> parameter in the servlet's
* configuration. If not present, this servlet will throw an exception so it will
* be marked unavailable.
*
* @throws javax.servlet.ServletException if any.
*/
@Override
public void init() throws ServletException {
ServletConfig config = this.getServletConfig();
this.redirectSuccess = config.getInitParameter("redirect.success");
if (this.redirectSuccess == null) {
throw new UnavailableException("Require a redirect.success init parameter.");
}
this.model = new AssetModel();
}
use of javax.servlet.ServletConfig in project opennms by OpenNMS.
the class MailerServlet method init.
/**
* <p>init</p>
*
* @throws javax.servlet.ServletException if any.
*/
@Override
public void init() throws ServletException {
ServletConfig config = this.getServletConfig();
this.redirectSuccess = config.getInitParameter("redirect.success");
this.mailProgram = config.getInitParameter("mail.program");
if (this.redirectSuccess == null) {
throw new ServletException("Missing required init parameter: redirect.success");
}
if (this.mailProgram == null) {
throw new ServletException("Missing required init parameter: mail.program");
}
}
use of javax.servlet.ServletConfig 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.ServletConfig in project tomee by apache.
the class ServerServletTest method activated.
@Test
public void activated() {
final ServerServlet serverServlet = new ServerServlet();
serverServlet.init(new ServletConfig() {
@Override
public String getServletName() {
return null;
}
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public String getInitParameter(final String name) {
return "activated".equals(name) ? Boolean.toString(activated) : null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
assertEquals(activated == null || activated, Reflections.get(serverServlet, "activated"));
}
Aggregations