Search in sources :

Example 51 with ServletContext

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

the class AtmosphereResourceTest 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 52 with ServletContext

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

the class JPAWebConfigurer 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(JPAApplicationConfiguration.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)

Example 53 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)

Example 54 with ServletContext

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

the class WebComponent method createResourceConfig.

/**
     * Create a {@link ResourceConfig} instance from given {@link WebConfig}.
     *
     * @param config web config to create resource config from.
     * @return resource config instance.
     * @throws ServletException if an error has occurred.
     */
private static ResourceConfig createResourceConfig(final WebConfig config) throws ServletException {
    final ServletContext servletContext = config.getServletContext();
    // check if ResourceConfig has already been created, if so use it
    ResourceConfig resourceConfig = Utils.retrieve(config.getServletContext(), config.getName());
    if (resourceConfig != null) {
        return resourceConfig;
    }
    final Map<String, Object> initParams = getInitParams(config);
    final Map<String, Object> contextParams = Utils.getContextParams(servletContext);
    // check if the JAX-RS application config class property is present
    final String jaxrsApplicationClassName = config.getInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS);
    if (jaxrsApplicationClassName == null) {
        // If no resource config class property is present, create default config
        resourceConfig = new ResourceConfig().addProperties(initParams).addProperties(contextParams);
        final String webApp = config.getInitParameter(ServletProperties.PROVIDER_WEB_APP);
        if (webApp != null && !"false".equals(webApp)) {
            resourceConfig.registerFinder(new WebAppResourcesScanner(servletContext));
        }
        return resourceConfig;
    }
    try {
        final Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass = AccessController.doPrivileged(ReflectionHelper.<javax.ws.rs.core.Application>classForNameWithExceptionPEA(jaxrsApplicationClassName));
        if (javax.ws.rs.core.Application.class.isAssignableFrom(jaxrsApplicationClass)) {
            return ResourceConfig.forApplicationClass(jaxrsApplicationClass).addProperties(initParams).addProperties(contextParams);
        } else {
            throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_PARENT_CLASS_INVALID(jaxrsApplicationClassName, javax.ws.rs.core.Application.class));
        }
    } catch (final PrivilegedActionException e) {
        throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_LOAD(jaxrsApplicationClassName), e.getCause());
    } catch (final ClassNotFoundException e) {
        throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_LOAD(jaxrsApplicationClassName), e);
    }
}
Also used : Providers(org.glassfish.jersey.internal.inject.Providers) Collectors(java.util.stream.Collectors) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 55 with ServletContext

use of javax.servlet.ServletContext in project lucene-solr by apache.

the class HadoopAuthPlugin method getInitFilterConfig.

@SuppressWarnings("unchecked")
protected FilterConfig getInitFilterConfig(Map<String, Object> pluginConfig) {
    Map<String, String> params = new HashMap<>();
    String type = (String) Objects.requireNonNull(pluginConfig.get(HADOOP_AUTH_TYPE));
    params.put(HADOOP_AUTH_TYPE, type);
    String sysPropPrefix = (String) pluginConfig.getOrDefault(SYSPROP_PREFIX_PROPERTY, "solr.");
    Collection<String> authConfigNames = (Collection<String>) pluginConfig.getOrDefault(AUTH_CONFIG_NAMES_PROPERTY, Collections.emptyList());
    Map<String, String> authConfigDefaults = (Map<String, String>) pluginConfig.getOrDefault(DEFAULT_AUTH_CONFIGS_PROPERTY, Collections.emptyMap());
    Map<String, String> proxyUserConfigs = (Map<String, String>) pluginConfig.getOrDefault(PROXY_USER_CONFIGS, Collections.emptyMap());
    for (String configName : authConfigNames) {
        String systemProperty = sysPropPrefix + configName;
        String defaultConfigVal = authConfigDefaults.get(configName);
        String configVal = System.getProperty(systemProperty, defaultConfigVal);
        if (configVal != null) {
            params.put(configName, configVal);
        }
    }
    // Configure proxy user settings.
    params.putAll(proxyUserConfigs);
    final ServletContext servletContext = new AttributeOnlyServletContext();
    log.info("Params: " + params);
    ZkController controller = coreContainer.getZkController();
    if (controller != null) {
        servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient());
    }
    FilterConfig conf = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String param) {
            return params.get(param);
        }

        @Override
        public String getFilterName() {
            return "HadoopAuthFilter";
        }
    };
    return conf;
}
Also used : HashMap(java.util.HashMap) IteratorEnumeration(org.apache.commons.collections.iterators.IteratorEnumeration) ZkController(org.apache.solr.cloud.ZkController) Collection(java.util.Collection) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ServletContext (javax.servlet.ServletContext)1059 Test (org.junit.Test)231 HttpServletRequest (javax.servlet.http.HttpServletRequest)171 IOException (java.io.IOException)138 HttpServletResponse (javax.servlet.http.HttpServletResponse)127 ServletException (javax.servlet.ServletException)95 File (java.io.File)75 ServletConfig (javax.servlet.ServletConfig)68 FilterConfig (javax.servlet.FilterConfig)65 HashMap (java.util.HashMap)63 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)49 URL (java.net.URL)47 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)38 PrintWriter (java.io.PrintWriter)32 List (java.util.List)32 RequestDispatcher (javax.servlet.RequestDispatcher)30 WebApplicationContext (org.springframework.web.context.WebApplicationContext)28