Search in sources :

Example 36 with ServletContext

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

the class AtmosphereFilter method init.

/**
     * Initialize the {@link Filter}.
     *
     * @param filterConfig The {@link javax.servlet.FilterConfig}
     * @throws ServletException
     */
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(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext)

Example 37 with ServletContext

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

the class DefaultAnnotationProcessor method configure.

@Override
public void configure(final AtmosphereConfig config) {
    ServletContext sc = config.framework().getServletContext();
    Map<Class<? extends Annotation>, Set<Class<?>>> annotations = (Map<Class<? extends Annotation>, Set<Class<?>>>) sc.getAttribute(ANNOTATION_ATTRIBUTE);
    sc.removeAttribute(ANNOTATION_ATTRIBUTE);
    boolean useByteCodeProcessor = config.getInitParameter(ApplicationConfig.BYTECODE_PROCESSOR, false);
    boolean scanForAtmosphereAnnotation = false;
    if (useByteCodeProcessor || annotations == null || annotations.isEmpty()) {
        delegate = new BytecodeBasedAnnotationProcessor(handler);
        scanForAtmosphereAnnotation = true;
    } else {
        Map<Class<? extends Annotation>, Set<Class<?>>> clone = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
        clone.putAll(annotations);
        delegate = new ServletContainerInitializerAnnotationProcessor(handler, clone, config.framework());
    }
    logger.info("AnnotationProcessor {} being used", delegate.getClass());
    if (scanForAtmosphereAnnotation) {
        scanForAnnotation(config.framework());
    }
    delegate.configure(config.framework().getAtmosphereConfig());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ServletContext(javax.servlet.ServletContext) IOUtils.loadClass(org.atmosphere.util.IOUtils.loadClass) HashMap(java.util.HashMap) Map(java.util.Map) AtmosphereAnnotation(org.atmosphere.config.AtmosphereAnnotation) Annotation(java.lang.annotation.Annotation)

Example 38 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class AMModuleProperties method getModuleProperties.

/**
     * Return the list of authentication module property
     * @param fileName that has module properties
     * @return <code>List</code> of module property
     * @exception AuthLoginException if fails to get properties from the file.
     */
public static List getModuleProperties(String fileName) throws AuthLoginException {
    List list = (List) moduleProps.get(fileName);
    List pageAttr;
    if (list != null) {
        return list;
    }
    ServletContext servletContext = AuthD.getAuth().getServletContext();
    InputStream resStream = null;
    try {
        if (servletContext != null) {
            resStream = servletContext.getResourceAsStream(fileName);
        }
        ;
        if (resStream == null) {
            resStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName.substring(1));
        // remove leading '/' from fileName
        }
        // file might be empty for modules like Cert,Anonymous etc.
        if (resStream != null && resStream.read() == -1) {
            if (debug.messageEnabled()) {
                debug.message(fileName + " is empty");
            }
            list = new ArrayList();
            synchronized (moduleProps) {
                moduleProps.put(fileName, list);
            }
            return list;
        }
    } catch (Exception e) {
        debug.message("getModuleProperties: Error: ", e);
    } finally {
        try {
            resStream.close();
        } catch (Exception ee) {
            debug.message("Error closing input stream");
        }
    }
    AMModuleProperties prop = new AMModuleProperties(fileName, servletContext);
    list = prop.getCallbacks();
    if (list != null && !list.isEmpty()) {
        synchronized (moduleProps) {
            moduleProps.put(fileName, list);
        }
    }
    return list;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with ServletContext

use of javax.servlet.ServletContext in project Activiti by Activiti.

the class WebConfigurer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = null;
    if (context == null) {
        rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationConfiguration.class);
        rootContext.refresh();
    } else {
        rootContext = context;
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    initSpring(servletContext, rootContext);
    log.debug("Web application fully configured");
}
Also used : ServletContext(javax.servlet.ServletContext) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 40 with ServletContext

use of javax.servlet.ServletContext in project Activiti by Activiti.

the class WebConfigurer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = null;
    if (context == null) {
        rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationConfiguration.class);
        rootContext.refresh();
    } else {
        rootContext = context;
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    initSpring(servletContext, rootContext);
    initSpringSecurity(servletContext, disps);
    log.debug("Web application fully configured");
}
Also used : ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Aggregations

ServletContext (javax.servlet.ServletContext)1111 Test (org.junit.Test)259 HttpServletRequest (javax.servlet.http.HttpServletRequest)186 HttpServletResponse (javax.servlet.http.HttpServletResponse)143 IOException (java.io.IOException)136 ServletException (javax.servlet.ServletException)101 ServletConfig (javax.servlet.ServletConfig)79 File (java.io.File)78 FilterConfig (javax.servlet.FilterConfig)66 HashMap (java.util.HashMap)64 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)50 URL (java.net.URL)48 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)39 Locale (java.util.Locale)38 List (java.util.List)33 PrintWriter (java.io.PrintWriter)32 LinkedHashMap (java.util.LinkedHashMap)30