Search in sources :

Example 71 with ServletConfig

use of javax.servlet.ServletConfig in project metrics by dropwizard.

the class HealthCheckServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNull.

@Test
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
    final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
    final ServletContext servletContext = mock(ServletContext.class);
    final ServletConfig servletConfig = mock(ServletConfig.class);
    when(servletConfig.getServletContext()).thenReturn(servletContext);
    when(servletContext.getAttribute(eq(HealthCheckServlet.HEALTH_CHECK_REGISTRY))).thenReturn(healthCheckRegistry);
    final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
    healthCheckServlet.init(servletConfig);
    verify(servletConfig, times(1)).getServletContext();
    verify(servletContext, times(1)).getAttribute(eq(HealthCheckServlet.HEALTH_CHECK_REGISTRY));
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 72 with ServletConfig

use of javax.servlet.ServletConfig in project metrics by dropwizard.

the class MetricsServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNull.

@Test
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() 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);
    when(servletContext.getAttribute(eq(MetricsServlet.METRICS_REGISTRY))).thenReturn(metricRegistry);
    final MetricsServlet metricsServlet = new MetricsServlet(null);
    metricsServlet.init(servletConfig);
    verify(servletConfig, times(1)).getServletContext();
    verify(servletContext, times(1)).getAttribute(eq(MetricsServlet.METRICS_REGISTRY));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 73 with ServletConfig

use of javax.servlet.ServletConfig in project cxf by apache.

the class JAXRSUtilsTest method testServletContextParameters.

@Test
public void testServletContextParameters() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("testServletParams", new Class[] { HttpServletRequest.class, HttpServletResponse.class, ServletContext.class, ServletConfig.class }), cri);
    ori.setHttpMethod("GET");
    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    HttpServletResponse response = new HttpServletResponseFilter(EasyMock.createMock(HttpServletResponse.class), null);
    ServletContext context = EasyMock.createMock(ServletContext.class);
    ServletConfig config = EasyMock.createMock(ServletConfig.class);
    EasyMock.replay(request);
    EasyMock.replay(context);
    EasyMock.replay(config);
    Message m = createMessage();
    m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
    m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
    m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
    m.put(AbstractHTTPDestination.HTTP_CONFIG, config);
    List<Object> params = JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
    assertEquals("4 parameters expected", 4, params.size());
    assertSame(request.getClass(), ((HttpServletRequestFilter) params.get(0)).getRequest().getClass());
    assertSame(response.getClass(), params.get(1).getClass());
    assertSame(context.getClass(), params.get(2).getClass());
    assertSame(config.getClass(), params.get(3).getClass());
}
Also used : Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ServletConfig(javax.servlet.ServletConfig) ThreadLocalServletConfig(org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletResponseFilter(org.apache.cxf.jaxrs.impl.HttpServletResponseFilter) ThreadLocalHttpServletRequest(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContext(javax.servlet.ServletContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) HttpServletRequestFilter(org.apache.cxf.jaxrs.impl.HttpServletRequestFilter) Test(org.junit.Test)

Example 74 with ServletConfig

use of javax.servlet.ServletConfig in project cxf by apache.

the class MessageContextImplTest method testServletConfig.

@Test
public void testServletConfig() {
    Message m = createMessage();
    MessageContext mc = new MessageContextImpl(m);
    ServletConfig request = EasyMock.createMock(ServletConfig.class);
    m.put(AbstractHTTPDestination.HTTP_CONFIG, request);
    assertSame(request.getClass(), mc.getServletConfig().getClass());
    assertSame(request.getClass(), mc.getContext(ServletConfig.class).getClass());
}
Also used : Message(org.apache.cxf.message.Message) ServletConfig(javax.servlet.ServletConfig) Test(org.junit.Test)

Example 75 with ServletConfig

use of javax.servlet.ServletConfig in project Lucee by lucee.

the class Admin method doGetInfo.

private void doGetInfo() throws PageException {
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    if (config instanceof ConfigWebImpl) {
        ConfigWebImpl cw = (ConfigWebImpl) config;
        sct.setEL(KeyConstants._id, cw.getIdentification().getId());
        sct.setEL(KeyConstants._label, cw.getLabel());
        sct.setEL(KeyConstants._hash, cw.getHash());
        sct.setEL(KeyConstants._root, cw.getRootDirectory().getAbsolutePath());
        sct.setEL("configServerDir", cw.getConfigServerDir().getAbsolutePath());
        sct.setEL("configWebDir", cw.getConfigDir().getAbsolutePath());
    } else {
        sct.setEL("configServerDir", config.getConfigDir().getAbsolutePath());
        sct.setEL("configWebDir", pageContext.getConfig().getConfigDir().getAbsolutePath());
    }
    sct.setEL(KeyConstants._config, config.getConfigFile().getAbsolutePath());
    // Servlets
    if (config instanceof ConfigServer) {
        ConfigServer cs = (ConfigServer) config;
        CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
        Struct srv = new StructImpl(), params;
        ServletConfig[] configs = engine.getServletConfigs();
        ServletConfig sc;
        Enumeration e;
        String name, value;
        for (int i = 0; i < configs.length; i++) {
            sc = configs[i];
            e = sc.getInitParameterNames();
            params = new StructImpl();
            while (e.hasMoreElements()) {
                name = (String) e.nextElement();
                value = sc.getInitParameter(name);
                params.set(name, value);
            }
            srv.set(sc.getServletName(), params);
        }
        sct.set("servlets", srv);
    }
    // sct.setEL("javaAgentSupported", Caster.toBoolean(InstrumentationUtil.isSupported()));
    sct.setEL("javaAgentSupported", Boolean.TRUE);
// sct.setEL("javaAgentPath", ClassUtil.getSourcePathForClass("lucee.runtime.instrumentation.Agent", ""));
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) StructImpl(lucee.runtime.type.StructImpl) Enumeration(java.util.Enumeration) ServletConfig(javax.servlet.ServletConfig) ConfigServer(lucee.runtime.config.ConfigServer) Struct(lucee.runtime.type.Struct)

Aggregations

ServletConfig (javax.servlet.ServletConfig)79 ServletContext (javax.servlet.ServletContext)54 Enumeration (java.util.Enumeration)38 ServletException (javax.servlet.ServletException)24 BeforeMethod (org.testng.annotations.BeforeMethod)21 Test (org.junit.Test)17 IOException (java.io.IOException)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)8 HttpServlet (javax.servlet.http.HttpServlet)7 MockServletContext (org.springframework.mock.web.test.MockServletContext)7 AtmosphereFramework (org.atmosphere.runtime.AtmosphereFramework)6 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)6 UnavailableException (javax.servlet.UnavailableException)5 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 File (java.io.File)3 PrintWriter (java.io.PrintWriter)3 AsynchronousProcessor (org.atmosphere.runtime.AsynchronousProcessor)3