Java Code Examples for javax.servlet.ServletContext#setInitParameter()
The following examples show how to use
javax.servlet.ServletContext#setInitParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebXmlCommon.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void initialize(ServletContext servletContext, boolean dev) throws ServletException { FacesInitializer facesInitializer = new FacesInitializer(); servletContext.setInitParameter("primefaces.FONT_AWESOME", "true"); servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true"); if (dev) { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development"); } else { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production"); } servletContext.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE)); Set<Class<?>> clazz = new HashSet<>(); clazz.add(WebXmlSpringBoot.class); facesInitializer.onStartup(clazz, servletContext); }
Example 2
Source File: WebXmlCommon.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void initialize(ServletContext servletContext, boolean dev) throws ServletException { FacesInitializer facesInitializer = new FacesInitializer(); servletContext.setInitParameter("primefaces.FONT_AWESOME", "true"); servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true"); if (dev) { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development"); } else { servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production"); } servletContext.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE)); Set<Class<?>> clazz = new HashSet<>(); clazz.add(WebXmlSpringBoot.class); facesInitializer.onStartup(clazz, servletContext); }
Example 3
Source File: HTAppServletContextListener.java From product-ei with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { Properties properties = new Properties(); // load configuration properties at context initialization try { 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); } }
Example 4
Source File: ProfileUtil.java From logging-log4j-audit with Apache License 2.0 | 6 votes |
/** * Set the active profile if none has been specified. * @param servletContext */ public static void setActiveProfile(ServletContext servletContext) { String springProfile = System.getProperty(SPRING_PROFILE); if (springProfile == null) { springProfile = System.getenv(SPRING_PROFILE); } if (springProfile == null) { springProfile = servletContext.getInitParameter(SPRING_PROFILE); } if (springProfile == null) { Properties props = loadProperties(servletContext); String activeProfile = props.getProperty(SPRING_PROFILE); if (activeProfile == null) { servletContext.setInitParameter(SPRING_PROFILE, "eclipseLink"); } } }
Example 5
Source File: ServletContextListenerTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
private ServletContext setValidParametersTo(ServletContext context) { context.setInitParameter("apiml.config.location", "/service-config.yml"); context.setInitParameter("apiml.config.additional-location", "../config/local/helloworld-additional-config.yml"); context.setInitParameter("apiml.serviceIpAddress", "127.0.0.2"); context.setInitParameter("apiml.discoveryService.port", "10011"); context.setInitParameter("apiml.discoveryService.hostname", "localhost"); context.setInitParameter("apiml.ssl.verifySslCertificatesOfServices", "true"); context.setInitParameter("apiml.ssl.keyPassword", "password123"); context.setInitParameter("apiml.ssl.keyStorePassword", "password"); context.setInitParameter("apiml.ssl.trustStore", "../keystore/localhost/localhost.keystore.p12"); context.setInitParameter("apiml.ssl.trustStorePassword", "password"); return context; }
Example 6
Source File: MainWebAppInitializer.java From tutorials with MIT License | 5 votes |
/** * Register and configure all Servlet container components necessary to power the web application. */ @Override public void onStartup(final ServletContext sc) throws ServletException { LOGGER.info("MainWebAppInitializer.onStartup()"); sc.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true"); // Create the 'root' Spring application context final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); root.register(SpringCoreConfig.class); sc.addListener(new ContextLoaderListener(root)); }
Example 7
Source File: SpringWebinitializer.java From Spring-5.0-Cookbook with MIT License | 5 votes |
private void addRootContext(ServletContext container) { // Create the application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringContextConfig.class); // Register application context with ContextLoaderListener container.addListener(new ContextLoaderListener(rootContext)); container.setInitParameter("contextConfigLocation", "org.packt.web.reactor.security.config"); container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting }
Example 8
Source File: SpringWebinitializer.java From Spring-5.0-Cookbook with MIT License | 5 votes |
private void addRootContext(ServletContext container) { // Create the application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringContextConfig.class); // Register application context with ContextLoaderListener container.addListener(new ContextLoaderListener(rootContext)); container.addListener(new AppSessionListener()); container.setInitParameter("contextConfigLocation", "org.packt.secured.mvc.core"); container.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); // if URL, enable sessionManagement URL rewriting }
Example 9
Source File: WebLookupTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testLookup2() throws Exception { ContextAnchor.THREAD_CONTEXT.remove(); final ServletContext servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath("/"); servletContext.setAttribute("TestAttr", "AttrValue"); servletContext.setInitParameter("myapp.logdir", "target"); servletContext.setAttribute("Name1", "Ben"); servletContext.setInitParameter("Name2", "Jerry"); servletContext.setInitParameter("log4jConfiguration", "WEB-INF/classes/log4j-webvar.xml"); final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext); initializer.start(); initializer.setLoggerContext(); final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get(); assertNotNull("No LoggerContext", ctx); assertNotNull("No ServletContext", ctx.getExternalContext()); final Configuration config = ctx.getConfiguration(); assertNotNull("No Configuration", config); final Map<String, Appender> appenders = config.getAppenders(); for (final Map.Entry<String, Appender> entry : appenders.entrySet()) { if (entry.getKey().equals("file")) { final FileAppender fa = (FileAppender) entry.getValue(); assertEquals("target/myapp.log", fa.getFileName()); } } final StrSubstitutor substitutor = config.getStrSubstitutor(); String value = substitutor.replace("${web:contextPathName:-default}"); assertNotNull("No value for context name", value); assertEquals("Incorrect value for context name", "default", value); initializer.stop(); ContextAnchor.THREAD_CONTEXT.remove(); }
Example 10
Source File: SpringBootJsfApplication.java From JavaExercises with GNU General Public License v2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml"); servletContext.setInitParameter( "javax.faces.PARTIAL_STATE_SAVING_METHOD", "true"); servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Production"); servletContext.setInitParameter("facelets.DEVELOPMENT", "false"); servletContext.setInitParameter( "javax.faces.FACELETS_REFRESH_PERIOD", "-1"); }
Example 11
Source File: JsfConfig.java From JavaExercises with GNU General Public License v2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("primefaces.THEME", "bootstrap"); MyFacesContainerInitializer facesInitializer = new MyFacesContainerInitializer(); Set<Class<?>> clazz = new HashSet<Class<?>>(); clazz.add(JsfConfig.class); facesInitializer.onStartup(clazz, servletContext); servletContext.addListener(new StartupServletContextListener()); }
Example 12
Source File: RegistryAppInitializer.java From konker-platform with Apache License 2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.addListener(new RequestContextListener()); // verifying configs for features activation Set<String> profiles = new HashSet<String>(); if (isEmailFeaturesEnabled()) { profiles.add("email"); } if (isCdnFeaturesEnabled()) { profiles.add("cdn"); } if (isSslFeaturesEnabled()) { profiles.add("ssl"); } servletContext.setInitParameter("spring.profiles.active", StringUtils.arrayToCommaDelimitedString(profiles.toArray())); }
Example 13
Source File: ServletAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testAppender() throws Exception { ContextAnchor.THREAD_CONTEXT.remove(); final ServletContext servletContext = new MockServletContext(); servletContext.setAttribute("TestAttr", "AttrValue"); servletContext.setInitParameter("TestParam", "ParamValue"); servletContext.setAttribute("Name1", "Ben"); servletContext.setInitParameter("Name2", "Jerry"); servletContext.setInitParameter(Log4jWebSupport.LOG4J_CONFIG_LOCATION, CONFIG); final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext); try { initializer.start(); initializer.setLoggerContext(); final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get(); assertNotNull("No LoggerContext", ctx); assertNotNull("No ServletContext", ctx.getExternalContext()); final Configuration configuration = ctx.getConfiguration(); assertNotNull("No configuration", configuration); final Appender appender = configuration.getAppender("Servlet"); assertNotNull("No ServletAppender", appender); final Logger logger = LogManager.getLogger("Test"); logger.info("This is a test"); logger.error("This is a test 2", new IllegalStateException().fillInStackTrace()); } catch (final IllegalStateException e) { fail("Failed to initialize Log4j properly." + e.getMessage()); } finally { initializer.stop(); ContextAnchor.THREAD_CONTEXT.remove(); } }
Example 14
Source File: DispatcherServletInitializer.java From consensusj with Apache License 2.0 | 4 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize", "60000"); servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", "60000"); }
Example 15
Source File: DispatcherServletInitializer.java From consensusj with Apache License 2.0 | 4 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize", "60000"); servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", "60000"); }
Example 16
Source File: Initializer.java From JSF-on-Spring-Boot with GNU General Public License v3.0 | 4 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { System.err.println("------------------------------------"); servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true"); }
Example 17
Source File: WebLookupTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Test public void testLookup() throws Exception { ContextAnchor.THREAD_CONTEXT.remove(); final ServletContext servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath("/WebApp"); servletContext.setAttribute("TestAttr", "AttrValue"); servletContext.setInitParameter("TestParam", "ParamValue"); servletContext.setAttribute("Name1", "Ben"); servletContext.setInitParameter("Name2", "Jerry"); final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext); try { initializer.start(); initializer.setLoggerContext(); final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get(); assertNotNull("No LoggerContext", ctx); assertNotNull("No ServletContext", ctx.getExternalContext()); final Configuration config = ctx.getConfiguration(); assertNotNull("No Configuration", config); final StrSubstitutor substitutor = config.getStrSubstitutor(); assertNotNull("No Interpolator", substitutor); String value = substitutor.replace("${web:initParam.TestParam}"); assertNotNull("No value for TestParam", value); assertEquals("Incorrect value for TestParam: " + value, "ParamValue", value); value = substitutor.replace("${web:attr.TestAttr}"); assertNotNull("No value for TestAttr", value); assertEquals("Incorrect value for TestAttr: " + value, "AttrValue", value); value = substitutor.replace("${web:Name1}"); assertNotNull("No value for Name1", value); assertEquals("Incorrect value for Name1: " + value, "Ben", value); value = substitutor.replace("${web:Name2}"); assertNotNull("No value for Name2", value); assertEquals("Incorrect value for Name2: " + value, "Jerry", value); value = substitutor.replace("${web:contextPathName}"); assertNotNull("No value for context name", value); assertEquals("Incorrect value for context name", "WebApp", value); } catch (final IllegalStateException e) { fail("Failed to initialize Log4j properly." + e.getMessage()); } initializer.stop(); ContextAnchor.THREAD_CONTEXT.remove(); }
Example 18
Source File: MyWebInitializer.java From spring-embedded-database with MIT License | 4 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); servletContext.setInitParameter("spring.profiles.active", "hsql"); }
Example 19
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 4 votes |
private static void setInitParameter(final ServletContext context, final String key, final String value) { if (context.getInitParameter(key) == null) { context.setInitParameter(key, value); } }
Example 20
Source File: SpringBoot10WebApplicationBootstrap.java From thinking-in-spring-boot-samples with Apache License 2.0 | 4 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("message", "Hello,World"); }