Search in sources :

Example 1 with ServletConfig

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

the class AtmosphereFramework method servletConfig.

protected void servletConfig(final ServletConfig sc, boolean wrap) {
    if (wrap) {
        String value = sc.getServletContext().getInitParameter(USE_SERVLET_CONTEXT_PARAMETERS);
        final boolean useServletContextParameters = Boolean.parseBoolean(value);
        servletConfig = new ServletConfig() {

            AtomicBoolean done = new AtomicBoolean();

            public String getServletName() {
                return sc.getServletName();
            }

            public ServletContext getServletContext() {
                return sc.getServletContext();
            }

            public String getInitParameter(String name) {
                String param = initParams.get(name);
                if (param == null) {
                    param = sc.getInitParameter(name);
                    if (param == null && useServletContextParameters) {
                        param = sc.getServletContext().getInitParameter(name);
                    }
                }
                return param;
            }

            public Enumeration<String> getInitParameterNames() {
                if (!done.getAndSet(true)) {
                    Enumeration<String> en = sc.getInitParameterNames();
                    if (en != null) {
                        while (en.hasMoreElements()) {
                            String name = en.nextElement();
                            if (!initParams.containsKey(name)) {
                                initParams.put(name, sc.getInitParameter(name));
                            }
                        }
                    }
                }
                return Collections.enumeration(initParams.keySet());
            }
        };
    } else {
        servletConfig = sc;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Enumeration(java.util.Enumeration) VoidServletConfig(org.atmosphere.util.VoidServletConfig) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext)

Example 2 with ServletConfig

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

the class SSEAtmosphereInterceptorTest method setup.

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

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

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

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

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    config = framework.getAtmosphereConfig();
}
Also used : Enumeration(java.util.Enumeration) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) AsyncSupport(org.atmosphere.cpr.AsyncSupport) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with ServletConfig

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

the class WebSocketFactoryTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(mock(AsyncSupport.class));
    framework.addAnnotationPackage(WebSocketFactoryTest.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 4 with ServletConfig

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

the class WebSocketProcessorTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return action(req, res);
        }
    });
    framework.addInitParameter(RECYCLE_ATMOSPHERE_REQUEST_RESPONSE, "false");
    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 : ServletException(jakarta.servlet.ServletException) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ServletConfig

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

the class QueryStringTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new BlockingIOCometSupport(framework.getAtmosphereConfig()));
    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 : BlockingIOCometSupport(org.atmosphere.container.BlockingIOCometSupport) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

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