Example usage for javax.servlet ServletContext setInitParameter

List of usage examples for javax.servlet ServletContext setInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletContext setInitParameter.

Prototype

public boolean setInitParameter(String name, String value);

Source Link

Document

Sets the context initialization parameter with the given name and value on this ServletContext.

Usage

From source file:com.chortitzer.web.Initializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    try {/*from  w  w w. ja va2  s. c o m*/
        System.err.println("------------------------------------");
        servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
        servletContext.setInitParameter("primefaces.THEME", "bootstrap");
        servletContext.setInitParameter("javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE",
                "true");
        servletContext.setInitParameter("facelets.SKIP_COMMENTS", "true");
    } catch (Exception ex) {
        LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex);
    }
}

From source file:com.iflytek.edu.cloud.frame.web.RestServiceWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.setInitParameter("contextConfigLocation", "classpath*:META-INF/spring/*-context.xml");
    servletContext.setInitParameter("contextInitializerClasses",
            ProfileApplicationContextInitializer.class.getName());
    servletContext.addListener(new LogBackLoadConfigureListener());
    servletContext.addListener(new ContextLoaderListener());

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter",
            new CharacterEncodingFilter());
    EnumSet<DispatcherType> characterEncodingFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD);//ww  w. j av  a  2 s. c o m
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(characterEncodingFilterDispatcherTypes, true, "/*");

    FilterRegistration.Dynamic openServiceFilter = servletContext.addFilter("openServiceFilter",
            new DelegatingFilterProxy());
    EnumSet<DispatcherType> openServiceFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD);
    openServiceFilter.addMappingForUrlPatterns(openServiceFilterDispatcherTypes, true, "/api");

    if (EnvUtil.jdbcEnabled()) {
        FilterRegistration.Dynamic serviceMetricsFilter = servletContext.addFilter("serviceMetricsFilter",
                new DelegatingFilterProxy());
        EnumSet<DispatcherType> serviceMetricsFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST,
                DispatcherType.FORWARD);
        serviceMetricsFilter.addMappingForUrlPatterns(serviceMetricsFilterDispatcherTypes, true, "/api");
    }

    FilterRegistration.Dynamic CORSFilter = servletContext.addFilter("CORSFilter", new DelegatingFilterProxy());
    EnumSet<DispatcherType> CORSFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD);
    CORSFilter.addMappingForUrlPatterns(CORSFilterDispatcherTypes, true, "/api");

    if (EnvUtil.oauthEnabled()) {
        FilterRegistration.Dynamic springSecurityFilterChain = servletContext
                .addFilter("springSecurityFilterChain", new DelegatingFilterProxyExt());
        EnumSet<DispatcherType> springSecurityFilterChainDispatcherTypes = EnumSet.of(DispatcherType.REQUEST,
                DispatcherType.FORWARD);
        springSecurityFilterChain.addMappingForUrlPatterns(springSecurityFilterChainDispatcherTypes, true,
                "/api");
    } else {
        logger.info(
                "?oauth2???META-INF/res/profile.propertiesoauth2 profile");
    }

    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("rest", new DispatcherServlet());
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    dispatcherServlet.setInitParameter("contextConfigLocation", "org.spring.rest");
    dispatcherServlet.setMultipartConfig(getMultiPartConfig());
    dispatcherServlet.addMapping("/api");

    ServletRegistration.Dynamic printProjectVersionServlet = servletContext
            .addServlet("printProjectVersionServlet", new PrintProjectVersionServlet());
    printProjectVersionServlet.setLoadOnStartup(Integer.MAX_VALUE);
}

From source file:io.gumga.security.WebConfigForTest.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

    servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages");
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);
    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);//from  w w w.j  a va2  s .c om
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    rootContext.setServletContext(servletContext);
    rootContext.register(WebConfigForTest.class);
    rootContext.refresh();

}

From source file:org.glassfish.jersey.server.spring.SpringWebApplicationInitializer.java

@Override
public void onStartup(ServletContext sc) throws ServletException {
    if (sc.getInitParameter(PAR_NAME_CTX_CONFIG_LOCATION) == null) {
        LOGGER.config(LocalizationMessages.REGISTERING_CTX_LOADER_LISTENER());
        sc.setInitParameter(PAR_NAME_CTX_CONFIG_LOCATION, "classpath:applicationContext.xml");
        sc.addListener("org.springframework.web.context.ContextLoaderListener");
        sc.addListener("org.springframework.web.context.request.RequestContextListener");
    } else {//from  ww  w  . j a v a2  s  .c  om
        LOGGER.config(LocalizationMessages.SKIPPING_CTX_LODAER_LISTENER_REGISTRATION());
    }
}

From source file:br.com.semanticwot.cd.conf.ServletSpringMVC.java

@Override
public void onStartup(ServletContext servletContext) // Define qual  o contexto ativo no momento
        throws ServletException {
    super.onStartup(servletContext);
    servletContext.addListener(RequestContextListener.class);
    servletContext.setInitParameter(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, "dev");

}

From source file:de.lbe.sandbox.springboot.jersey2.JerseyAutoConfiguration.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // We need to switch *off* the Jersey WebApplicationInitializer because it
    // will try and register a ContextLoaderListener which we don't need
    servletContext.setInitParameter("contextConfigLocation", "<NONE>");
}

From source file:com.devnexus.ting.web.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages");

    //UrlRewriteFilter
    final FilterRegistration.Dynamic urlRewriteFilterRegistration = servletContext.addFilter("UrlRewriteFilter",
            new UrlRewriteFilter());
    urlRewriteFilterRegistration.setAsyncSupported(true);
    urlRewriteFilterRegistration.addMappingForUrlPatterns(null, true, "/proxy/*");

    // UTF-8 Encoding
    FilterRegistration.Dynamic encodingFilterRegistration = servletContext.addFilter("encodingFilter",
            new CharacterEncodingFilter());
    encodingFilterRegistration.setInitParameter("encoding", "UTF-8");
    encodingFilterRegistration.setInitParameter("forceEncoding", "true");
    encodingFilterRegistration.addMappingForUrlPatterns(null, true, "/s/*");

    FilterRegistration.Dynamic gzipFilterRegistration = servletContext.addFilter("gzipFilter",
            CompressingFilter.class);
    gzipFilterRegistration.addMappingForUrlPatterns(null, true, "/s/*", "*.html", "/api/*");

    // jsonPRequestFilter
    FilterRegistration.Dynamic jsonPRequestFilterRegistration = servletContext.addFilter("JSONPRequestFilter",
            JSONPRequestFilter.class);
    jsonPRequestFilterRegistration.addMappingForUrlPatterns(null, true, "*.json");

    // lazyLoadingFilter
    FilterRegistration.Dynamic lazyLoadingFilterRegistration = servletContext.addFilter("lazyLoadingFilter",
            OpenEntityManagerInViewFilter.class);
    lazyLoadingFilterRegistration.addMappingForUrlPatterns(null, true, "*.html", "/s/*");

    // springSecurityFilterChain
    FilterRegistration.Dynamic springSecurityFilterChainRegistration = servletContext
            .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
    springSecurityFilterChainRegistration.addMappingForUrlPatterns(null, true, "/*");

    // loggingFilter4Logback
    FilterRegistration.Dynamic loggingFilter4LogbackRegistration = servletContext
            .addFilter("loggingFilter4Logback", LoggingFilter4Logback.class);
    loggingFilter4LogbackRegistration.addMappingForUrlPatterns(null, true, "/s/*", "/api/*");

    // etagFilter
    FilterRegistration.Dynamic etagFilterRegistration = servletContext.addFilter("etagFilter",
            ShallowEtagHeaderFilter.class);
    etagFilterRegistration.addMappingForUrlPatterns(null, true, "/s/*");

    // sitemeshFilter
    FilterRegistration.Dynamic sitemeshRegistration = servletContext.addFilter("sitemesh",
            ConfigurableSiteMeshFilter.class);
    sitemeshRegistration.addMappingForUrlPatterns(null, true, "/s/*", "/index.jsp");

    // responseAddHttpHeadersFilter
    FilterRegistration.Dynamic responseAddHttpHeadersFilterRegistration = servletContext
            .addFilter("responseAddHttpHeadersFilter", ResponseAddHttpHeadersFilter.class);
    responseAddHttpHeadersFilterRegistration.setInitParameter("secondsToCache", "2592000");
    responseAddHttpHeadersFilterRegistration.addMappingForUrlPatterns(null, true, "*.css", "*.gif", "*.ico",
            "*.jpg", "*.png", "*.js");

    setupContext(servletContext);/*  w  ww. j a v  a2  s  .  co m*/
    super.onStartup(servletContext);
}

From source file:com.folion.config.CommunityWebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    super.onStartup(servletContext);

    String activeProfile = System.getProperty("your.profile.property");
    if (activeProfile == null) {
        activeProfile = "dev"; // or whatever you want the default to be
    }/*  w ww .j av a 2 s . c o m*/

    servletContext.setInitParameter("spring.profiles.active", activeProfile);
}

From source file:br.eti.danielcamargo.backend.common.config.WebAppInitializer.java

private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CoreConfig.class, SecurityConfig.class);
    rootContext.refresh();//from   w w w.j  av a2  s.  c  om
    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");
    return rootContext;
}

From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java

private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CoreConfig.class);
    rootContext.refresh();/*from   ww w  .j ava2s . co  m*/

    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");

    return rootContext;
}