Search in sources :

Example 1 with ServletContext

use of jakarta.servlet.ServletContext 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 ServletContext

use of jakarta.servlet.ServletContext 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 ServletContext

use of jakarta.servlet.ServletContext 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 ServletContext

use of jakarta.servlet.ServletContext 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 ServletContext

use of jakarta.servlet.ServletContext 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

ServletContext (jakarta.servlet.ServletContext)148 Test (org.junit.jupiter.api.Test)63 ServletConfig (jakarta.servlet.ServletConfig)40 Enumeration (java.util.Enumeration)29 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)24 BeforeMethod (org.testng.annotations.BeforeMethod)22 IOException (java.io.IOException)20 ServletException (jakarta.servlet.ServletException)17 FilterRegistration (jakarta.servlet.FilterRegistration)16 DelegatingFilterProxy (org.springframework.web.filter.DelegatingFilterProxy)15 Filter (jakarta.servlet.Filter)13 Test (org.junit.Test)13 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)12 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)12 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)12 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)11 WebApplicationContext (org.springframework.web.context.WebApplicationContext)9 File (java.io.File)8 Context (org.apache.catalina.Context)7 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)7