Search in sources :

Example 31 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereFrameworkTest method testAtmosphereServlet.

@Test
public void testAtmosphereServlet() throws ServletException {
    AtmosphereServlet s = new MyAtmosphereServlet();
    s.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            if (ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356.equals(name)) {
                return "true";
            }
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    assertNotNull(s);
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) Test(org.testng.annotations.Test)

Example 32 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereResponseImplTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(mock(AsyncSupport.class));
    framework.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class EncoderDecoderTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
    framework.addAnnotationPackage(ManagedMessage.class);
    framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return suspended(req, res);
        }

        public void action(AtmosphereResourceImpl r) {
            try {
                resumed(r.getRequest(), r.getResponse());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }).init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    latch.set(new CountDownLatch(1));
}
Also used : AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletContext(jakarta.servlet.ServletContext) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 34 with ServletConfig

use of jakarta.servlet.ServletConfig in project atmosphere by Atmosphere.

the class AtmosphereFilter method init.

/**
 * Initialize the {@link Filter}.
 *
 * @param filterConfig The {@link jakarta.servlet.FilterConfig}
 */
public void init(final FilterConfig filterConfig) throws ServletException {
    logger.info("AtmosphereServlet running as a Filter");
    as.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return filterConfig.getFilterName();
        }

        @Override
        public ServletContext getServletContext() {
            return filterConfig.getServletContext();
        }

        @Override
        public String getInitParameter(String name) {
            return filterConfig.getInitParameter(name);
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return filterConfig.getInitParameterNames();
        }
    });
    String s = filterConfig.getInitParameter(ApplicationConfig.ATMOSPHERE_EXCLUDED_FILE);
    if (s != null) {
        excluded = s;
    }
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext)

Example 35 with ServletConfig

use of jakarta.servlet.ServletConfig in project spring-framework by spring-projects.

the class DispatcherServletTests method detectHandlerMappingFromParent.

@Test
public void detectHandlerMappingFromParent() throws ServletException, IOException {
    // create a parent context that includes a mapping
    StaticWebApplicationContext parent = new StaticWebApplicationContext();
    parent.setServletContext(getServletContext());
    parent.registerSingleton("parentHandler", ControllerFromParent.class, new MutablePropertyValues());
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue(new PropertyValue("mappings", URL_KNOWN_ONLY_PARENT + "=parentHandler"));
    parent.registerSingleton("parentMapping", SimpleUrlHandlerMapping.class, pvs);
    parent.refresh();
    DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
    // will have parent
    complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");
    ServletConfig config = new MockServletConfig(getServletContext(), "complex");
    config.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, parent);
    complexDispatcherServlet.init(config);
    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", URL_KNOWN_ONLY_PARENT);
    MockHttpServletResponse response = new MockHttpServletResponse();
    complexDispatcherServlet.service(request, response);
    assertThat(response.getStatus() == HttpServletResponse.SC_NOT_FOUND).as("Matched through parent controller/handler pair: not response=" + response.getStatus()).isFalse();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) ServletConfig(jakarta.servlet.ServletConfig) PropertyValue(org.springframework.beans.PropertyValue) MockServletConfig(org.springframework.web.testfixture.servlet.MockServletConfig) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ServletConfig (jakarta.servlet.ServletConfig)42 ServletContext (jakarta.servlet.ServletContext)40 Enumeration (java.util.Enumeration)28 BeforeMethod (org.testng.annotations.BeforeMethod)22 ServletException (jakarta.servlet.ServletException)10 IOException (java.io.IOException)10 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)9 Test (org.junit.jupiter.api.Test)7 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)7 AtmosphereFramework (org.atmosphere.cpr.AtmosphereFramework)6 Test (org.junit.Test)6 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)6 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)6 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 AsynchronousProcessor (org.atmosphere.cpr.AsynchronousProcessor)4 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)4 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)4 AtmosphereResponse (org.atmosphere.cpr.AtmosphereResponse)4 Test (org.testng.annotations.Test)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2