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:net.orpiske.tcs.service.config.WebAppInitializer.java

private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

    rootContext.register(CoreConfig.class, SecurityConfig.class);
    rootContext.refresh();//from   www.  ja v  a 2s . c om

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

    return rootContext;
}

From source file:com.indeed.imhotep.web.config.WebApp.java

protected void initLog4j(ServletContext servletContext) {
    final String log4jConfigLocationParam = "log4jConfigLocation";
    final String log4jConfigLocation = servletContext.getInitParameter(log4jConfigLocationParam);
    if (Strings.isNullOrEmpty(log4jConfigLocation)) {
        servletContext.setInitParameter(log4jConfigLocationParam, getDefaultLog4jConfigLocation());
    }//  w  w w .  j  a  v a2 s  .  c o  m
    servletContext.setInitParameter("log4jExposeWebAppRoot", "false");

    servletContext.addListener(Log4jConfigListener.class);
}

From source file:de.dlopes.stocks.facilitator.config.JsfMvcConfig.java

/**
 * initialize the deployable war with a minumum set of configuration params
 *///w  ww.  j ava  2s .  co m
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    /*
     * set context param 'com.sun.faces.forceLoadConfiguration' in order to force JSF
     * implementation to neglect the need of a FacesServlet(-Mapping) and ConfigureListener
     * in a web.xml and to use annotation based configuration
     */
    servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
    super.onStartup(servletContext);
}

From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Create the root appcontext
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootConfig.class);
    rootContext.register(PersistenceConfig.class);

    // Manage the lifecycle of the root appcontext
    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");

    this.zkLoaderServlet(servletContext);

    // now the config for the Dispatcher servlet
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(WebMvcConfig.class);

    // Filters/*from   w  w w  .j  ava  2  s  . c o m*/
    // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/package-summary.html
    // Enables support for DELETE and PUT request methods with web browser
    // clients
    // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/HiddenHttpMethodFilter.html
    FilterRegistration.Dynamic fr = servletContext.addFilter("hiddenHttpMethodFilter",
            new HiddenHttpMethodFilter());
    fr.addMappingForUrlPatterns(null, true, "/*");

    fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter());
    fr.setInitParameter("encoding", "UTF-8");
    fr.setInitParameter("forceEncoding", "true");
    fr.addMappingForUrlPatterns(null, true, "/*");

    // The main Spring MVC servlet.
    ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet",
            new DispatcherServlet(mvcContext));
    appServlet.setLoadOnStartup(2);
    Set<String> mappingConflicts = appServlet.addMapping("/");

    if (!mappingConflicts.isEmpty()) {
        for (String s : mappingConflicts) {
            logger.error("Mapping conflict: " + s);
        }
        throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14");
    }

    HttpSessionListener zkCleanUp = new HttpSessionListener();
    servletContext.addListener(zkCleanUp);

    this.logbackServlet(servletContext);

    this.zkUpdateServlet(servletContext);
}

From source file:org.shaigor.rest.retro.config.WebAppInitializer.java

/**
 * Creates web application context //  w  ww.  jav a  2 s  . com
 * @param servletContext to be used during creation and registration
 * @return web application context for the application
 */
private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().setActiveProfiles("prod");
    Class<?>[] annotatedClasseses = configurations2Register();
    if (annotatedClasseses != null && annotatedClasseses.length > 0) {
        rootContext.register(annotatedClasseses);
    }
    rootContext.refresh();

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

    return rootContext;
}

From source file:io.gravitee.management.war.WebAppInitializer.java

@Override
public void onStartup(ServletContext context) throws ServletException {
    // initialize
    initialize();//  w w w .j  av  a 2s .  c  o  m
    Properties prop = propertiesLoader.load();

    // REST configuration
    ServletRegistration.Dynamic servletRegistration = context.addServlet("REST",
            ServletContainer.class.getName());
    servletRegistration.addMapping("/management/*");
    servletRegistration.setLoadOnStartup(1);
    servletRegistration.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName());

    // Spring configuration
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
            prop.getProperty("security.type", "basic-auth"));
    context.addListener(new ContextLoaderListener());
    context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.setInitParameter("contextConfigLocation", RestConfiguration.class.getName());

    // Spring Security filter
    context.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}

From source file:com.techtrip.dynbl.context.config.WebAppinitializer.java

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

    // Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component}
    // Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject}
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

    //context.setConfigLocation(APP_CONFIG_LOCATION);
    context.setConfigLocation(APP_CONFIG_LOCATION);

    /* //from  w  ww  .  j a  va2s. c o  m
    * Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered
    *  and configured with the specified context
    */
    /*              
    FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue()));
    securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied
    */
    // Add a Character Encoding Filter that specifies an encoding for mapped requests
    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString());
    characterEncodingFilter.setAsyncSupported(true);

    servletContext.addListener(new ContextLoaderListener(context));
    servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString());

    DispatcherServlet servlet = new DispatcherServlet();

    // no explicit configuration reference here: everything is configured in the root container for simplicity
    servlet.setContextConfigLocation("");

    /* TMT From JEE 6 API Docs:
    * Registers the given servlet instance with this ServletContext under the given servletName.
    * The registered servlet may be further configured via the returned ServletRegistration object. 
    */

    ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet);
    appServlet.setLoadOnStartup(1);
    appServlet.setAsyncSupported(true);

    Set<String> mappingConflicts = appServlet.addMapping("/");

    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException(String.format(
                "The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET));
    }

    // TMT
    servletContext.addListener(new Log4jConfigListener());

    System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion());

}

From source file:org.wso2.bps.humantask.sample.listener.HTAppServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    Properties properties = new Properties();
    // load configuration properties at context initialization
    try {/*  www. java  2s.c om*/
        properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
        //initialize the required parameters
        ServletContext sc = servletContextEvent.getServletContext();
        sc.setInitParameter(HumanTaskSampleConstants.BACKEND_SERVER_URL,
                properties.get(HumanTaskSampleConstants.BACKEND_SERVER_URL).toString());
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH));
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD));
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE));

    } catch (IOException e) {
        String errMsg = "Couldn't load properties from config file";
        log.error(errMsg, e);
    }
}