Search in sources :

Example 56 with ServletConfig

use of javax.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 = value != null && Boolean.valueOf(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 en = sc.getInitParameterNames();
                    if (en != null) {
                        while (en.hasMoreElements()) {
                            String name = (String) 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(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext)

Example 57 with ServletConfig

use of javax.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(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 58 with ServletConfig

use of javax.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(javax.servlet.ServletException) Enumeration(java.util.Enumeration) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 59 with ServletConfig

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

the class CookieTest 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(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 60 with ServletConfig

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

the class WebSocketStreamingHandlerTest method create.

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

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