use of javax.servlet.ServletConfig in project metrics by dropwizard.
the class MetricsServletTest method constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig.
@Test
public void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
final MetricRegistry metricRegistry = mock(MetricRegistry.class);
final ServletContext servletContext = mock(ServletContext.class);
final ServletConfig servletConfig = mock(ServletConfig.class);
when(servletConfig.getServletContext()).thenReturn(servletContext);
final MetricsServlet metricsServlet = new MetricsServlet(metricRegistry);
metricsServlet.init(servletConfig);
verify(servletConfig, times(1)).getServletContext();
verify(servletContext, never()).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
}
use of javax.servlet.ServletConfig in project Lucee by lucee.
the class PageContextUtil method getPageContext.
public static PageContext getPageContext(Config config, ServletConfig servletConfig, File contextRoot, String host, String scriptName, String queryString, Cookie[] cookies, Map<String, Object> headers, Map<String, String> parameters, Map<String, Object> attributes, OutputStream os, boolean register, long timeout, boolean ignoreScopes) throws ServletException {
boolean callOnStart = ThreadLocalPageContext.callOnStart.get();
try {
ThreadLocalPageContext.callOnStart.set(false);
if (contextRoot == null)
contextRoot = new File(".");
// Engine
CFMLEngine engine = null;
try {
engine = CFMLEngineFactory.getInstance();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
if (engine == null)
throw new ServletException("there is no ServletContext");
if (headers == null)
headers = new HashMap<String, Object>();
if (parameters == null)
parameters = new HashMap<String, String>();
if (attributes == null)
attributes = new HashMap<String, Object>();
// Request
HttpServletRequest req = CreationImpl.getInstance(engine).createHttpServletRequest(contextRoot, host, scriptName, queryString, cookies, headers, parameters, attributes, null);
// Response
HttpServletResponse rsp = CreationImpl.getInstance(engine).createHttpServletResponse(os);
if (config == null)
config = ThreadLocalPageContext.getConfig();
CFMLFactory factory = null;
HttpServlet servlet;
if (config instanceof ConfigWeb) {
ConfigWeb cw = (ConfigWeb) config;
factory = cw.getFactory();
servlet = factory.getServlet();
} else {
if (servletConfig == null) {
ServletConfig[] configs = engine.getServletConfigs();
String rootDir = contextRoot.getAbsolutePath();
for (ServletConfig conf : configs) {
if (lucee.commons.io.SystemUtil.arePathsSame(rootDir, conf.getServletContext().getRealPath("/"))) {
servletConfig = conf;
break;
}
}
if (servletConfig == null)
servletConfig = configs[0];
}
factory = engine.getCFMLFactory(servletConfig, req);
servlet = new HTTPServletImpl(servletConfig, servletConfig.getServletContext(), servletConfig.getServletName());
}
return factory.getLuceePageContext(servlet, req, rsp, null, false, -1, false, register, timeout, false, ignoreScopes);
} finally {
ThreadLocalPageContext.callOnStart.set(callOnStart);
}
}
use of javax.servlet.ServletConfig in project cxf by apache.
the class AtmosphereWebSocketJettyDestination method activate.
protected void activate() {
super.activate();
if (handler.getServletContext().getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") == null) {
try {
Class<?> dcc = ClassUtils.forName("org.eclipse.jetty.util.DecoratedObjectFactory", getClass().getClassLoader());
handler.getServletContext().setAttribute("org.eclipse.jetty.util.DecoratedObjectFactory", dcc.newInstance());
} catch (ClassNotFoundException | LinkageError | InstantiationException | IllegalAccessException e) {
// ignore, old version of Jetty
}
}
ServletConfig config = new VoidServletConfig(initParams) {
@Override
public ServletContext getServletContext() {
return handler.getServletContext();
}
};
try {
framework.init(config);
} catch (ServletException e) {
throw new Fault(new Message("Could not initialize WebSocket Framework", LOG, e.getMessage()), e);
}
}
use of javax.servlet.ServletConfig in project tomee by apache.
the class ArquillianFilterRunner method init.
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
try {
delegate = HttpServlet.class.cast(Thread.currentThread().getContextClassLoader().loadClass(ARQUILLIAN_SERVLET_RUNNER).newInstance());
delegate.init(new ServletConfig() {
@Override
public String getServletName() {
return ArquillianFilterRunner.class.getName();
}
@Override
public ServletContext getServletContext() {
return filterConfig.getServletContext();
}
@Override
public String getInitParameter(final String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return emptyEnumeration();
}
});
} catch (final Exception e) {
// no-op: can happen if the servlet is not present, that's a normal case
}
}
use of javax.servlet.ServletConfig in project openremote by openremote.
the class JSAPIServlet method scanResources.
@SuppressWarnings("unchecked")
public void scanResources() throws Exception {
ServletConfig config = getServletConfig();
ServletContext servletContext = config.getServletContext();
Map<String, ResteasyDeployment> deployments = (Map<String, ResteasyDeployment>) servletContext.getAttribute(ResteasyContextParameters.RESTEASY_DEPLOYMENTS);
if (deployments == null)
return;
synchronized (this) {
services = new HashMap<String, ServiceRegistry>();
for (Map.Entry<String, ResteasyDeployment> entry : deployments.entrySet()) {
ResourceMethodRegistry registry = (ResourceMethodRegistry) entry.getValue().getRegistry();
ResteasyProviderFactory providerFactory = entry.getValue().getProviderFactory();
ServiceRegistry service = new ServiceRegistry(null, registry, providerFactory, null);
services.put(entry.getKey(), service);
}
}
}
Aggregations