List of usage examples for javax.servlet ServletContext getInitParameter
public String getInitParameter(String name);
String
containing the value of the named context-wide initialization parameter, or null
if the parameter does not exist. From source file:org.openmrs.web.Listener.java
/** * Load the openmrs constants with values from web.xml init parameters * * @param servletContext startup context (web.xml) *//* w w w. j av a 2 s . com*/ private void loadConstants(ServletContext servletContext) { WebConstants.BUILD_TIMESTAMP = servletContext.getInitParameter("build.timestamp"); WebConstants.WEBAPP_NAME = getContextPath(servletContext); WebConstants.MODULE_REPOSITORY_URL = servletContext.getInitParameter("module.repository.url"); // note: the below value will be overridden after reading the runtime properties if the // "application_data_directory" runtime property is set String appDataDir = servletContext.getInitParameter("application.data.directory"); if (StringUtils.hasLength(appDataDir)) { OpenmrsUtil.setApplicationDataDirectory(appDataDir); } else if (!"openmrs".equalsIgnoreCase(WebConstants.WEBAPP_NAME)) { OpenmrsUtil.setApplicationDataDirectory( OpenmrsUtil.getApplicationDataDirectory() + File.separator + WebConstants.WEBAPP_NAME); } }
From source file:com.googlecode.psiprobe.Tomcat80ContainerAdaptor.java
public List getApplicationInitParams(Context context) { // We'll try to determine if a parameter value comes from a deployment descriptor or a context descriptor. // assumption: Context.findParameter() returns only values of parameters that are declared in a deployment descriptor. // If a parameter is declared in a context descriptor with override=false and redeclared in a deployment descriptor, // Context.findParameter() still returns its value, even though the value is taken from a context descriptor. // context.findApplicationParameters() returns all parameters that are declared in a context descriptor regardless // of whether they are overridden in a deployment descriptor or not or not. // creating a set of parameter names that are declared in a context descriptor // and can not be ovevridden in a deployment descriptor. Set nonOverridableParams = new HashSet(); ApplicationParameter[] appParams = context.findApplicationParameters(); for (int i = 0; i < appParams.length; i++) { if (appParams[i] != null && !appParams[i].getOverride()) { nonOverridableParams.add(appParams[i].getName()); }//from w ww . jav a 2 s . c o m } List initParams = new ArrayList(); ServletContext servletCtx = context.getServletContext(); for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements();) { String paramName = (String) e.nextElement(); ApplicationParam param = new ApplicationParam(); param.setName(paramName); param.setValue(servletCtx.getInitParameter(paramName)); // if the parameter is declared in a deployment descriptor // and it is not declared in a context descriptor with override=false, // the value comes from the deployment descriptor param.setFromDeplDescr( context.findParameter(paramName) != null && !nonOverridableParams.contains(paramName)); initParams.add(param); } return initParams; }
From source file:org.sindice.core.analytics.commons.webapps.SparqledContextListener.java
private XMLConfiguration createXMLConfiguration(final ServletContext context) { final XMLConfiguration config = new XMLConfiguration(); final ConfigurationInterpolator interpolator = config.getInterpolator(); final StrLookup defaultLookup = interpolator.getDefaultLookup(); interpolator.setDefaultLookup(new StrLookup() { @Override/* w w w . j a v a2 s.c o m*/ public String lookup(String key) { if (context.getAttribute(key) != null) { return context.getAttribute(key).toString(); } if (context.getInitParameter(key) != null) { return context.getInitParameter(key); } return defaultLookup.lookup(key); } }); return config; }
From source file:com.dhcc.framework.web.context.DhccContextLoader.java
/** * Template method with default implementation (which may be overridden by a * subclass), to load or obtain an ApplicationContext instance which will be * used as the parent context of the root WebApplicationContext. If the * return value from the method is null, no parent context is set. * <p>The main reason to load a parent context here is to allow multiple root * web application contexts to all be children of a shared EAR context, or * alternately to also share the same parent context that is visible to * EJBs. For pure web applications, there is usually no need to worry about * having a parent context to the root web application context. * <p>The default implementation uses * {@link org.springframework.context.access.ContextSingletonBeanFactoryLocator}, * configured via {@link #LOCATOR_FACTORY_SELECTOR_PARAM} and * {@link #LOCATOR_FACTORY_KEY_PARAM}, to load a parent context * which will be shared by all other users of ContextsingletonBeanFactoryLocator * which also use the same configuration parameters. * @param servletContext current servlet context * @return the parent application context, or {@code null} if none * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator *///w ww . j a va 2 s . com protected ApplicationContext loadParentContext(ServletContext servletContext) { ApplicationContext parentContext = null; String locatorFactorySelector = servletContext.getInitParameter(LOCATOR_FACTORY_SELECTOR_PARAM); String parentContextKey = servletContext.getInitParameter(LOCATOR_FACTORY_KEY_PARAM); if (parentContextKey != null) { // locatorFactorySelector may be null, indicating the default "classpath*:beanRefContext.xml" BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(locatorFactorySelector); Log logger = LogFactory.getLog(DhccContextLoader.class); if (logger.isDebugEnabled()) { logger.debug("Getting parent context definition: using parent context key of '" + parentContextKey + "' with BeanFactoryLocator"); } this.parentContextRef = locator.useBeanFactory(parentContextKey); parentContext = (ApplicationContext) this.parentContextRef.getFactory(); } return parentContext; }
From source file:org.wise.portal.spring.impl.CustomContextLoaderListener.java
/** * The behaviour of this method is the same as the superclass except for * setting of the config locations./*w w w .j a v a 2 s. c om*/ * * @throws ClassNotFoundException * * @see org.springframework.web.context.ContextLoader#createWebApplicationContext(javax.servlet.ServletContext, * org.springframework.context.ApplicationContext) */ @Override protected WebApplicationContext createWebApplicationContext(ServletContext servletContext) throws BeansException { Class<?> contextClass = determineContextClass(servletContext); if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Custom context class [" + contextClass.getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext webApplicationContext = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); webApplicationContext.setServletContext(servletContext); String configClass = servletContext.getInitParameter(CONFIG_CLASS_PARAM); if (configClass != null) { try { SpringConfiguration springConfig = (SpringConfiguration) BeanUtils .instantiateClass(Class.forName(configClass)); webApplicationContext.setConfigLocations(springConfig.getRootApplicationContextConfigLocations()); } catch (ClassNotFoundException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error(CONFIG_CLASS_PARAM + " <" + configClass + "> not found.", e); } throw new InvalidParameterException("ClassNotFoundException: " + configClass); } } else { throw new InvalidParameterException("No value defined for the required: " + CONFIG_CLASS_PARAM); } webApplicationContext.refresh(); return webApplicationContext; }
From source file:com.ephesoft.dcma.batch.service.EphesoftContext.java
/** * Creates host server registry entry in server_registry table. It first checks for the entry inside the database, if it is present * there it updates the entry by setting Active column to TRUE otherwise it make the respective entry in the database. * //from ww w . j a va 2 s. c om * It assumes correct port number inside the web.xml. */ private void createRegistry() { // Get port number from 'web.xml' if (applicationContext instanceof WebApplicationContext) { // Getting the instance of ServletContext. final ServletContext servletContext = ((WebApplicationContext) applicationContext).getServletContext(); final String portNumber = servletContext.getInitParameter(ICommonConstants.PORT_PARAM); if (portNumber != null) { try { port = Integer.valueOf(portNumber); } catch (NumberFormatException numberFormatException) { LOGGER.error("No port number is defined in web.xml. Assigning port number 0"); } } context = ((WebApplicationContext) applicationContext).getServletContext().getContextPath(); // Getting the protocol from web.xml. final String protocol = servletContext.getInitParameter(ICommonConstants.PROTOCOL_PARAM); // Set isSeure to true if request is from secure channel otherwise set it to false; if (ICommonConstants.HTTPS.equals(protocol)) { isSecure = true; // Registers a protocol with the given identifier. Protocol.registerProtocol(ICommonConstants.HTTPS, new Protocol(ICommonConstants.HTTPS, (ProtocolSocketFactory) new EphesoftSSLProtocolSocketFactory(), port)); } } List<ServerRegistry> activeServers = registryService.getActiveServers(); ServerRegistry registry = registryService.getServerRegistry(this.hostName, String.valueOf(this.port), this.context); if (activeServers.isEmpty()) { registry = new ServerRegistry(); registry.setIpAddress(this.hostName); registry.setPort(String.valueOf(this.port)); registry.setAppContext(this.context); registry.setActive(true); registry.setLicenseServer(false); // Setting it to false to mark this server as not a License server. when License // server // will be started on activating License server config file in // ApplicationContext.xml // then this property will be changed to true by LicenseServerManager setWorkflowProperties(registry); registry.setFolderMoniterServer(false); // Reading and Setting the Execution Capacity for a new server registryService.createServerRegistry(registry); } else { // Get host server registry entry from database. if (registry != null) { registry.setActive(true); setWorkflowProperties(registry); // Updating the Execution Capacity registry.setLicenseServer(false); // Same thing as above registryService.updateServerRegistry(registry); } } // add LICENSE_FAILOVER_MECHANISM property default value. createOrCheckClusterProperty(ClusterPropertyType.LICENSE_FAILOVER_MECHANISM); id = registry.getId(); }
From source file:org.yes.cart.cluster.node.impl.JGroupsNodeServiceImpl.java
void initNodeFromServletContext(final ServletContext servletContext) { final Enumeration parameters = servletContext.getInitParameterNames(); while (parameters.hasMoreElements()) { final String key = String.valueOf(parameters.nextElement()); final String value = servletContext.getInitParameter(key); configuration.put(key, value);/*from www . j a v a 2 s . c o m*/ } final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED); final String luceneDisabledValue = luceneDisabled != null ? Boolean.valueOf(luceneDisabled).toString() : Boolean.FALSE.toString(); configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue); node = new NodeImpl(true, configuration.get(NODE_ID), configuration.get(NODE_TYPE), configuration.get(NODE_CONFIG), configuration.get(CLUSTER_ID), Boolean.valueOf(luceneDisabledValue)); this.cluster.add(node); LOG = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId()); if (LOG.isInfoEnabled()) { final StringBuilder stats = new StringBuilder(); stats.append("\nLoading configuration for node..."); stats.append("\nNode: ").append(node.getId()); for (final Map.Entry<String, String> entry : configuration.entrySet()) { stats.append('\n').append(entry.getKey()).append(": ").append(entry.getValue()); } LOG.info(stats.toString()); } }
From source file:org.getobjects.servlets.WOServletAdaptor.java
@Override public void init(final ServletConfig _cfg) throws ServletException { // Jetty: org.mortbay.jetty.servlet.ServletHolder$Config@114024 super.init(_cfg); String an = this.valueFromServletConfig(_cfg, "WOAppName"); String ac = this.valueFromServletConfig(_cfg, "WOAppClass"); if (ac == null) ac = an;//from w ww . ja va2s . c o m if (an == null && ac != null) { /* if only the class is set, we use the shortname of the class */ int dotidx = ac.lastIndexOf('.'); an = dotidx < 1 ? ac : ac.substring(dotidx + 1); } if (an == null) { log.warn("no WOAppName specified in servlet context: " + _cfg); an = WOApplication.class.getName(); } /* Construct properties for the volatile "domain" from servlet init * parameters and context init parameters and attributes. * It's probably best to have a real UserDefaults concept, but for the * time being this is better than nothing. */ final Properties properties = new Properties(); Enumeration parameterNamesEnum = _cfg.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); final String value = _cfg.getInitParameter(name); if (name != null && value != null) properties.put(name, value); else if (value == null) log.error("Got no value for init parameter: " + name); } /* The ServletContext may override the previous init parameters. * ServletContext init parameters will be overridden by attributes. */ final ServletContext sctx = _cfg.getServletContext(); if (sctx != null) { parameterNamesEnum = sctx.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); properties.put(name, sctx.getInitParameter(name)); } final Enumeration attributeNamesEnum = sctx.getAttributeNames(); while (attributeNamesEnum.hasMoreElements()) { final String name = (String) attributeNamesEnum.nextElement(); properties.put(name, sctx.getAttribute(name)); } } this.initApplicationWithName(an, ac, properties); }
From source file:org.getobjects.servlets.WOServletAdaptor.java
protected String valueFromServletConfig(final ServletConfig _cfg, final String _key) { String an = _cfg.getInitParameter(_key); if (an != null) return an; final ServletContext sctx = _cfg.getServletContext(); if (sctx == null) return null; /*/*from w w w .j av a 2 s.co m*/ * This is specified in web.xml like: * <context-param> * <param-name>WOAppName</param-name> * <param-value>com.zideone.HelloWorld.HelloWorld</param-value> * </context-param> */ if ((an = sctx.getInitParameter(_key)) != null) return an; if ((an = (String) sctx.getAttribute(_key)) != null) return an; return an; }
From source file:org.springframework.web.context.ContextLoader.java
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam);/* w w w.j ava 2 s . c om*/ } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }