Java Code Examples for javax.servlet.ServletConfig#getInitParameterNames()
The following examples show how to use
javax.servlet.ServletConfig#getInitParameterNames() .
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: HttpServletBean.java From java-technology-stack with MIT License | 6 votes |
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 2
Source File: HttpServletBean.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Create new ServletConfigPropertyValues. * @param config ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<String>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 3
Source File: HttpServletBean.java From spring-analysis-note with MIT License | 6 votes |
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 4
Source File: PrintParams.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { List<String> params = new ArrayList<String>(); ServletConfig config = getServletConfig(); Enumeration<String> paramsEnum = config.getInitParameterNames(); while (paramsEnum.hasMoreElements()) { params.add(paramsEnum.nextElement()); } Collections.sort(params); res.setContentType("text/plain"); for (String param : params) { res.getWriter().println(param + ": " + config.getInitParameter(param)); } }
Example 5
Source File: TransformationServlet.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void init(final ServletConfig config) throws ServletException { super.init(config); cookies = new CookieHandler(config, this); if (config != null) { if (config.getInitParameter(TRANSFORMATIONS) == null) { throw new MissingInitParameterException(TRANSFORMATIONS); } final Enumeration<?> names = config.getInitParameterNames(); while (names.hasMoreElements()) { final String name = (String) names.nextElement(); if (name.startsWith("default-")) { defaults.put(name.substring("default-".length()), config.getInitParameter(name)); } } } }
Example 6
Source File: ProxyRepositoryServlet.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @SuppressWarnings("unchecked") public void init(ServletConfig config) throws ServletException { super.init(config); lastModified = System.currentTimeMillis(); if (config.getInitParameter(DEFAULT_PATH_PARAM) == null) { throw new MissingInitParameterException(DEFAULT_PATH_PARAM); } Enumeration<String> names = config.getInitParameterNames(); while (names.hasMoreElements()) { String path = names.nextElement(); if (path.startsWith("/")) { try { servlets.put(path, createServlet(path)); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new ServletException(e); } } } }
Example 7
Source File: TradeAppServlet.java From sample.daytrader7 with Apache License 2.0 | 6 votes |
/** * Servlet initialization method. */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); java.util.Enumeration<String> en = config.getInitParameterNames(); while (en.hasMoreElements()) { String parm = en.nextElement(); String value = config.getInitParameter(parm); TradeConfig.setConfigParam(parm, value); } try { // TODO: Uncomment this once split-tier issue is resolved // TradeDirect.init(); } catch (Exception e) { Log.error(e, "TradeAppServlet:init -- Error initializing TradeDirect"); } }
Example 8
Source File: LoaderServlet.java From tomee with Apache License 2.0 | 6 votes |
/** * Retrieves all intialization parameters for this servlet and stores them in a java.util.Properties object. * * @param config javax.servlet.ServletConfig * @return java.util.Properties */ protected Properties initParamsToProperties(final ServletConfig config) { final Properties properties = new Properties(); //@Tomcat // Set some defaults properties.setProperty("openejb.loader", "tomcat"); // Load in each init-param as a property final Enumeration<?> enumeration = config.getInitParameterNames(); System.out.println("OpenEJB Loader init-params:"); if (!enumeration.hasMoreElements()) { System.out.println("\tThere are no initialization parameters."); } while (enumeration.hasMoreElements()) { final String name = (String) enumeration.nextElement(); final String value = config.getInitParameter(name); properties.put(name, value); System.out.println("\tparam-name: " + name + ", param-value: " + value); } return properties; }
Example 9
Source File: HttpServletBean.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Create new ServletConfigPropertyValues. * @param config ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ? new HashSet<String>(requiredProperties) : null; Enumeration<String> en = config.getInitParameterNames(); while (en.hasMoreElements()) { String property = en.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (missingProps != null && missingProps.size() > 0) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 10
Source File: ShiroKaptchaServlet.java From phone with Apache License 2.0 | 6 votes |
@Override public void init(ServletConfig conf) throws ServletException { super.init(conf); // Switch off disk based caching. ImageIO.setUseCache(false); Enumeration<?> initParams = conf.getInitParameterNames(); while (initParams.hasMoreElements()) { String key = (String) initParams.nextElement(); String value = conf.getInitParameter(key); this.props.put(key, value); } Config config = new Config(this.props); this.kaptchaProducer = config.getProducerImpl(); this.sessionKeyValue = config.getSessionKey(); this.sessionKeyDateValue = config.getSessionDate(); }
Example 11
Source File: KualiActionServlet.java From rice with Educational Community License v2.0 | 5 votes |
public KualiActionServletConfig(ServletConfig wrapped) { this.wrapped = wrapped; // copy out all the init parameters so they can be augmented @SuppressWarnings("unchecked") final Enumeration<String> initParameterNames = wrapped.getInitParameterNames(); while ( initParameterNames.hasMoreElements() ) { String paramName = initParameterNames.nextElement(); initParameters.put( paramName, wrapped.getInitParameter(paramName) ); } // loop over the installed modules, adding their struts configuration to the servlet // if they have a web interface final Collection<ModuleConfigurer> riceModules = ModuleConfigurer.getCurrentContextConfigurers(); if ( LOG.isInfoEnabled() ) { LOG.info( "Configuring init parameters of the KualiActionServlet from riceModules: " + riceModules ); } for ( ModuleConfigurer module : riceModules ) { // only install the web configuration if the module has web content // and it is running in a "local" mode // in "embedded" or "remote" modes, the UIs are hosted on a central server if ( module.shouldRenderWebInterface() ) { WebModuleConfiguration webModuleConfiguration = module.getWebModuleConfiguration(); if (webModuleConfiguration == null) { throw new ConfigurationException("Attempting to load WebModuleConfiguration for module '" + module.getModuleName() + "' but no configuration was provided!"); } if ( LOG.isInfoEnabled() ) { LOG.info( "Configuring Web Content for Module: " + webModuleConfiguration.getModuleName() + " / " + webModuleConfiguration.getWebModuleStrutsConfigName() + " / " + webModuleConfiguration.getWebModuleStrutsConfigurationFiles() + " / Base URL: " + webModuleConfiguration.getWebModuleBaseUrl() ); } if ( !initParameters.containsKey( webModuleConfiguration.getWebModuleStrutsConfigName() ) ) { initParameters.put( webModuleConfiguration.getWebModuleStrutsConfigName(), webModuleConfiguration.getWebModuleStrutsConfigurationFiles() ); } } } }
Example 12
Source File: TradeScenarioServlet.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
/** * Servlet initialization method. */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); java.util.Enumeration<String> en = config.getInitParameterNames(); while (en.hasMoreElements()) { String parm = en.nextElement(); String value = config.getInitParameter(parm); TradeConfig.setConfigParam(parm, value); } }
Example 13
Source File: OneConfig.java From hasor with Apache License 2.0 | 5 votes |
public void putConfig(ServletConfig config, boolean overwrite) { Enumeration<?> names = config.getInitParameterNames(); if (names != null) { while (names.hasMoreElements()) { String name = names.nextElement().toString(); this.computeIfAbsent(name, s -> overwrite ? config.getInitParameter(name) : s); } } }
Example 14
Source File: NtlmServlet.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void init ( ServletConfig config ) throws ServletException { super.init(config); Properties p = new Properties(); p.putAll(System.getProperties()); /* * Set jcifs properties we know we want; soTimeout and cachePolicy to 10min. */ p.setProperty("jcifs.smb.client.soTimeout", "300000"); p.setProperty("jcifs.netbios.cachePolicy", "600"); Enumeration<String> e = config.getInitParameterNames(); String name; while ( e.hasMoreElements() ) { name = e.nextElement(); if ( name.startsWith("jcifs.") ) { p.setProperty(name, config.getInitParameter(name)); } } try { this.defaultDomain = p.getProperty("jcifs.smb.client.domain"); this.domainController = p.getProperty("jcifs.http.domainController"); if ( this.domainController == null ) { this.domainController = this.defaultDomain; this.loadBalance = Config.getBoolean(p, "jcifs.http.loadBalance", true); } this.enableBasic = Boolean.valueOf(p.getProperty("jcifs.http.enableBasic")).booleanValue(); this.insecureBasic = Boolean.valueOf(p.getProperty("jcifs.http.insecureBasic")).booleanValue(); this.realm = p.getProperty("jcifs.http.basicRealm"); if ( this.realm == null ) this.realm = "jCIFS"; this.transportContext = new BaseContext(new PropertyConfiguration(p));; } catch ( CIFSException ex ) { throw new ServletException("Failed to initialize config", ex); } }
Example 15
Source File: NtlmServlet.java From jcifs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void init ( ServletConfig config ) throws ServletException { super.init(config); Properties p = new Properties(); p.putAll(System.getProperties()); /* * Set jcifs properties we know we want; soTimeout and cachePolicy to 10min. */ p.setProperty("jcifs.smb.client.soTimeout", "300000"); p.setProperty("jcifs.netbios.cachePolicy", "600"); Enumeration<String> e = config.getInitParameterNames(); String name; while ( e.hasMoreElements() ) { name = e.nextElement(); if ( name.startsWith("jcifs.") ) { p.setProperty(name, config.getInitParameter(name)); } } try { this.defaultDomain = p.getProperty("jcifs.smb.client.domain"); this.domainController = p.getProperty("jcifs.http.domainController"); if ( this.domainController == null ) { this.domainController = this.defaultDomain; this.loadBalance = Config.getBoolean(p, "jcifs.http.loadBalance", true); } this.enableBasic = Boolean.valueOf(p.getProperty("jcifs.http.enableBasic")).booleanValue(); this.insecureBasic = Boolean.valueOf(p.getProperty("jcifs.http.insecureBasic")).booleanValue(); this.realm = p.getProperty("jcifs.http.basicRealm"); if ( this.realm == null ) this.realm = "jCIFS"; this.transportContext = new BaseContext(new PropertyConfiguration(p));; } catch ( CIFSException ex ) { throw new ServletException("Failed to initialize config", ex); } }
Example 16
Source File: BasicServletConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("unchecked") public BasicServletConfig(String name, ServletConfig config) { this(name, config.getServletContext()); Enumeration<String> e = config.getInitParameterNames(); while (e.hasMoreElements()) { String param = e.nextElement(); params.put(param, config.getInitParameter(param)); } }
Example 17
Source File: XACMLRest.java From XACML with MIT License | 5 votes |
/** * This must be called during servlet initialization. It sets up the xacml.{?}.properties * file as a system property. If the System property is already set, then it does not * do anything. This allows the developer to specify their own xacml.properties file to be * used. They can 1) modify the default properties that comes with the project, or 2) change * the WebInitParam annotation, or 3) specify an alternative path in the web.xml, or 4) set * the Java System property to point to their xacml.properties file. * * The recommended way of overriding the default xacml.properties file is using a Java System * property: * * For PDP REST: * -Dxacml.properties=/opt/app/xacml/etc/xacml.pdp.properties * * For PAP REST: * -Dxacml.properties=/opt/app/xacml/etc/xacml.pap.properties * * For PAP ADMIN: * -Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties * * This way one does not change any actual code or files in the project and can leave the * defaults alone. * * @param config - The servlet config file passed from the javax servlet init() function */ public static void xacmlInit(ServletConfig config) { // // Get the XACML Properties File parameter first // String propFile = config.getInitParameter("XACML_PROPERTIES_NAME"); if (propFile != null) { // // Look for system override // String xacmlPropertiesName = System.getProperty(XACMLProperties.XACML_PROPERTIES_NAME); if (xacmlPropertiesName == null) { // // Set it to our servlet default // logger.debug("Using Servlet Config Property for XACML_PROPERTIES_NAME {}", propFile); System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, propFile); } else { logger.debug("Using System Property for XACML_PROPERTIES_NAME {}", xacmlPropertiesName); } } // // Setup the remaining properties // Enumeration<String> params = config.getInitParameterNames(); while (params.hasMoreElements()) { String param = params.nextElement(); if (! param.equals("XACML_PROPERTIES_NAME")) { String value = config.getInitParameter(param); logger.info("{}={}", param, config.getInitParameter(param)); restProperties.setProperty(param, value); } } }
Example 18
Source File: FakeServletConfig.java From validator-web with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Map<String, String> getInitParametersInServletConfig(ServletConfig servletConfig) { Map<String , String> initParameters = new HashMap<String, String>(); Enumeration<String> params = servletConfig.getInitParameterNames(); while (params.hasMoreElements()) { String name = params.nextElement(); String value = servletConfig.getInitParameter(name); initParameters.put(name, value); } return Collections.unmodifiableMap(initParameters); }
Example 19
Source File: Servlet.java From rockscript with Apache License 2.0 | 5 votes |
protected Map<String, String> readConfigurationProperties(ServletConfig servletConfig) { Map<String,String> initParameters = new LinkedHashMap<>(); Enumeration<String> initParameterNames = servletConfig.getInitParameterNames(); while (initParameterNames.hasMoreElements()) { String initParameterName = initParameterNames.nextElement(); String initParameterValue = servletConfig.getInitParameter(initParameterName); initParameters.put(initParameterName, initParameterValue); } return initParameters; }
Example 20
Source File: ServletDefinitionTest.java From dagger-servlet with Apache License 2.0 | 4 votes |
@Test public final void testServletInitAndConfig() throws ServletException { ObjectGraph objectGraph = createMock(ObjectGraph.class); final HttpServlet mockServlet = new HttpServlet() { }; expect(objectGraph.get(HttpServlet.class)) .andReturn(mockServlet) .anyTimes(); replay(objectGraph); //some init params //noinspection SSBasedInspection final Map<String, String> initParams = new HashMap<String, String>() { { put("ahsd", "asdas24dok"); put("ahssd", "asdasd124ok"); put("ahfsasd", "asda124sdok"); put("ahsasgd", "a124sdasdok"); put("ahsd124124", "as124124124dasdok"); } }; String pattern = "/*"; final ServletDefinition servletDefinition = new ServletDefinition(pattern, HttpServlet.class, UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null); ServletContext servletContext = createMock(ServletContext.class); final String contextName = "thing__!@@44__SRV" + getClass(); expect(servletContext.getServletContextName()) .andReturn(contextName); replay(servletContext); servletDefinition.init(servletContext, objectGraph, Sets.newSetFromMap(Maps.<HttpServlet, Boolean>newIdentityHashMap())); assertNotNull(mockServlet.getServletContext()); assertEquals(contextName, mockServlet.getServletContext().getServletContextName()); assertEquals(HttpServlet.class.getName(), mockServlet.getServletName()); final ServletConfig servletConfig = mockServlet.getServletConfig(); final Enumeration names = servletConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); assertTrue(initParams.containsKey(name)); assertEquals(initParams.get(name), servletConfig.getInitParameter(name)); } verify(objectGraph, servletContext); }