List of usage examples for javax.servlet ServletConfig getInitParameterNames
public Enumeration<String> getInitParameterNames();
Enumeration
of String
objects, or an empty Enumeration
if the servlet has no initialization parameters. From source file:org.wrml.server.WrmlServletTest.java
@Test public void createAndInit() throws ServletException { ServletConfig servletConfig = mock(ServletConfig.class); Enumeration<String> eStrings = new TestEmptyEnum(); when(servletConfig.getInitParameterNames()).thenReturn(eStrings); String configLocation = "wrml.json"; when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_RESOURCE_PATH_INIT_PARAM_NAME)) .thenReturn(configLocation); _Servlet.init(servletConfig);//from w w w. j av a 2 s . c o m }
From source file:org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.java
private void writeObject(ObjectOutputStream stream) throws IOException { if (_log.isInfoEnabled()) { _log.info("serializing ActionServlet " + this); }/*from ww w.j ava 2 s .c om*/ if (_configParams != null) { stream.writeObject(_configParams); } else { ServletConfig servletConfig = getServletConfig(); assert servletConfig != null; HashMap params = new HashMap(); for (Enumeration e = servletConfig.getInitParameterNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); params.put(name, servletConfig.getInitParameter(name)); } stream.writeObject(params); } }
From source file:org.wings.session.Session.java
/** * Copy the init parameters.//w w w.ja va 2s.c o m */ protected void initProps(ServletConfig servletConfig) { Enumeration params = servletConfig.getInitParameterNames(); while (params.hasMoreElements()) { String name = (String) params.nextElement(); props.put(name, servletConfig.getInitParameter(name)); } }
From source file:net.wastl.webmail.server.WebMailServlet.java
public void init(ServletConfig config) throws ServletException { final ServletContext sc = config.getServletContext(); log.debug("Init"); final String depName = (String) sc.getAttribute("deployment.name"); final Properties rtProps = (Properties) sc.getAttribute("meta.properties"); log.debug("RT configs retrieved for application '" + depName + "'"); srvlt_config = config;/*from w w w . jav a2 s . com*/ this.config = new Properties(); final Enumeration enumVar = config.getInitParameterNames(); while (enumVar.hasMoreElements()) { final String s = (String) enumVar.nextElement(); this.config.put(s, config.getInitParameter(s)); log.debug(s + ": " + config.getInitParameter(s)); } /* * Issue a warning if webmail.basepath and/or webmail.imagebase are not * set. */ if (config.getInitParameter("webmail.basepath") == null) { log.warn("webmail.basepath initArg should be set to the WebMail " + "Servlet's base path"); basepath = ""; } else { basepath = config.getInitParameter("webmail.basepath"); } if (config.getInitParameter("webmail.imagebase") == null) { log.error("webmail.basepath initArg should be set to the WebMail " + "Servlet's base path"); imgbase = ""; } else { imgbase = config.getInitParameter("webmail.imagebase"); } /* * Try to get the pathnames from the URL's if no path was given in the * initargs. */ if (config.getInitParameter("webmail.data.path") == null) { this.config.put("webmail.data.path", sc.getRealPath("/data")); } if (config.getInitParameter("webmail.lib.path") == null) { this.config.put("webmail.lib.path", sc.getRealPath("/lib")); } if (config.getInitParameter("webmail.template.path") == null) { this.config.put("webmail.template.path", sc.getRealPath("/lib/templates")); } if (config.getInitParameter("webmail.xml.path") == null) { this.config.put("webmail.xml.path", sc.getRealPath("/lib/xml")); } if (config.getInitParameter("webmail.log.facility") == null) { this.config.put("webmail.log.facility", "net.wastl.webmail.logger.ServletLogger"); } // Override settings with webmail.* meta.properties final Enumeration rte = rtProps.propertyNames(); int overrides = 0; String k; while (rte.hasMoreElements()) { k = (String) rte.nextElement(); if (!k.startsWith("webmail.")) { continue; } overrides++; this.config.put(k, rtProps.getProperty(k)); } log.debug(Integer.toString(overrides) + " settings passed to WebMailServer, out of " + rtProps.size() + " RT properties"); /* * Call the WebMailServer's initialization method and forward all * Exceptions to the ServletServer */ try { doInit(); } catch (final Exception e) { log.error("Could not intialize", e); throw new ServletException("Could not intialize: " + e.getMessage(), e); } Helper.logThreads("Bottom of WebMailServlet.init()"); }
From source file:org.jahia.services.atmosphere.AtmosphereServlet.java
@Override public void init(final ServletConfig sc) throws ServletException { ServletConfig scFacade;//w w w .jav a 2 s .c om String asyncSupport = SettingsBean.getInstance().getAtmosphereAsyncSupport(); // override asyncSupport only if explicitly set via jahia.properties or not set at all if (StringUtils.isNotEmpty(asyncSupport) || sc.getInitParameter(PROPERTY_COMET_SUPPORT) == null) { final String implName = StringUtils.defaultIfBlank(asyncSupport, DEFAULT_ASYNC_SUPPORT); scFacade = new ServletConfig() { @Override public String getInitParameter(String name) { return PROPERTY_COMET_SUPPORT.equals(name) ? implName : sc.getInitParameter(name); } @Override public Enumeration<String> getInitParameterNames() { ArrayList<String> names = Lists.newArrayList(PROPERTY_COMET_SUPPORT); CollectionUtils.addAll(names, sc.getInitParameterNames()); return Collections.enumeration(names); } @Override public ServletContext getServletContext() { return sc.getServletContext(); } @Override public String getServletName() { return sc.getServletName(); } }; } else { scFacade = sc; } super.init(scFacade); }
From source file:org.wrml.server.WrmlServlet.java
@Override public void init(final ServletConfig servletConfig) throws ServletException { LOGGER.debug("Servlet Name {}", servletConfig.getServletName()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Parameters names passed ["); List<String> paramList = new ArrayList<>(); Enumeration<String> params = servletConfig.getInitParameterNames(); while (params.hasMoreElements()) { String paramName = params.nextElement(); paramList.add(String.format("%s=%s", paramName, servletConfig.getInitParameter(paramName))); }//from www . ja va 2 s .c o m LOGGER.debug("Parameters names passed={}", Arrays.toString(paramList.toArray())); } super.init(servletConfig); final String configFileLocation = PropertyUtil.getSystemProperty( EngineConfiguration.WRML_CONFIGURATION_FILE_PATH_PROPERTY_NAME, servletConfig.getInitParameter(WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME)); String configResourceLocation = null; if (configFileLocation == null) { configResourceLocation = servletConfig .getInitParameter(WRML_CONFIGURATION_RESOURCE_PATH_INIT_PARAM_NAME); } try { final EngineConfiguration engineConfig; if (configFileLocation != null) { LOGGER.info("Extracted configuration file location: {}", configFileLocation); engineConfig = EngineConfiguration.load(configFileLocation); } else if (configResourceLocation != null) { LOGGER.info("Extracted configuration resource location: {}", configResourceLocation); engineConfig = EngineConfiguration.load(getClass(), configResourceLocation); } else { throw new ServletException("The WRML engine configuration is null. Unable to initialize servlet."); } final Engine engine = new DefaultEngine(); engine.init(engineConfig); setEngine(engine); LOGGER.debug("Initialized WRML with: {}", engineConfig); } catch (IOException ex) { throw new ServletException("Unable to initialize servlet.", ex); } LOGGER.info("WRML SERVLET INITIALIZED --------------------------------------------------"); }
From source file:org.apache.tapestry.request.RequestContext.java
/** * Writes the state of the context to the writer, typically for inclusion * in a HTML page returned to the user. This is useful * when debugging. The Inspector uses this as well. * **///from w ww . jav a 2 s .com public void write(IMarkupWriter writer) { // Create a box around all of this stuff ... writer.begin("table"); writer.attribute("class", "request-context-border"); writer.begin("tr"); writer.begin("td"); // Get the session, if it exists, and display it. HttpSession session = getSession(); if (session != null) { object(writer, "Session"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "id", session.getId()); datePair(writer, "creationTime", session.getCreationTime()); datePair(writer, "lastAccessedTime", session.getLastAccessedTime()); pair(writer, "maxInactiveInterval", session.getMaxInactiveInterval()); pair(writer, "new", session.isNew()); List names = getSorted(session.getAttributeNames()); int count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, session.getAttribute(name)); } writer.end(); // Session } object(writer, "Request"); writer.begin("table"); writer.attribute("class", "request-context-object"); // Parameters ... List parameters = getSorted(_request.getParameterNames()); int count = parameters.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Parameters"); header(writer, "Name", "Value(s)"); } String name = (String) parameters.get(i); String[] values = _request.getParameterValues(name); writer.begin("tr"); writer.attribute("class", getRowClass()); writer.begin("th"); writer.print(name); writer.end(); writer.begin("td"); if (values.length > 1) writer.begin("ul"); for (int j = 0; j < values.length; j++) { if (values.length > 1) writer.beginEmpty("li"); writer.print(values[j]); } writer.end("tr"); } section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "authType", _request.getAuthType()); pair(writer, "characterEncoding", _request.getCharacterEncoding()); pair(writer, "contentLength", _request.getContentLength()); pair(writer, "contentType", _request.getContentType()); pair(writer, "method", _request.getMethod()); pair(writer, "pathInfo", _request.getPathInfo()); pair(writer, "pathTranslated", _request.getPathTranslated()); pair(writer, "protocol", _request.getProtocol()); pair(writer, "queryString", _request.getQueryString()); pair(writer, "remoteAddr", _request.getRemoteAddr()); pair(writer, "remoteHost", _request.getRemoteHost()); pair(writer, "remoteUser", _request.getRemoteUser()); pair(writer, "requestedSessionId", _request.getRequestedSessionId()); pair(writer, "requestedSessionIdFromCookie", _request.isRequestedSessionIdFromCookie()); pair(writer, "requestedSessionIdFromURL", _request.isRequestedSessionIdFromURL()); pair(writer, "requestedSessionIdValid", _request.isRequestedSessionIdValid()); pair(writer, "requestURI", _request.getRequestURI()); pair(writer, "scheme", _request.getScheme()); pair(writer, "serverName", _request.getServerName()); pair(writer, "serverPort", _request.getServerPort()); pair(writer, "contextPath", _request.getContextPath()); pair(writer, "servletPath", _request.getServletPath()); // Now deal with any headers List headers = getSorted(_request.getHeaderNames()); count = headers.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Headers"); header(writer, "Name", "Value"); } String name = (String) headers.get(i); String value = _request.getHeader(name); pair(writer, name, value); } // Attributes List attributes = getSorted(_request.getAttributeNames()); count = attributes.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) attributes.get(i); pair(writer, name, _request.getAttribute(name)); } // Cookies ... Cookie[] cookies = _request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (i == 0) { section(writer, "Cookies"); header(writer, "Name", "Value"); } Cookie cookie = cookies[i]; pair(writer, cookie.getName(), cookie.getValue()); } // Cookies loop } writer.end(); // Request object(writer, "Servlet"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "servlet", _servlet); pair(writer, "name", _servlet.getServletName()); pair(writer, "servletInfo", _servlet.getServletInfo()); ServletConfig config = _servlet.getServletConfig(); List names = getSorted(config.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Init Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); ; pair(writer, name, config.getInitParameter(name)); } writer.end(); // Servlet ServletContext context = config.getServletContext(); object(writer, "Servlet Context"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "majorVersion", context.getMajorVersion()); pair(writer, "minorVersion", context.getMinorVersion()); pair(writer, "serverInfo", context.getServerInfo()); names = getSorted(context.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Initial Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getInitParameter(name)); } names = getSorted(context.getAttributeNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getAttribute(name)); } writer.end(); // Servlet Context writeSystemProperties(writer); writer.end("table"); // The enclosing border }
From source file:org.tinygroup.jspengine.EmbeddedServletOptions.java
/** * Create an EmbeddedServletOptions object using data available from * ServletConfig and ServletContext. //from ww w . j av a 2s .com */ public EmbeddedServletOptions(ServletConfig config, ServletContext context) throws JasperException { // JVM version numbers try { if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) { compilerSourceVM = compilerTargetVM = "1.5"; } else { compilerSourceVM = compilerTargetVM = "1.4"; } } catch (NumberFormatException e) { // Ignore } Enumeration enumeration = config.getInitParameterNames(); while (enumeration.hasMoreElements()) { String k = (String) enumeration.nextElement(); String v = config.getInitParameter(k); setProperty(k, v); } /* SJSAS 6384538 // quick hack String validating=config.getInitParameter( "validating"); if( "false".equals( validating )) ParserUtils.validating=false; */ // START SJSAS 6384538 String validating = config.getInitParameter("validating"); if ("true".equals(validating)) { isValidationEnabled = true; } validating = config.getInitParameter("enableTldValidation"); if ("true".equals(validating)) { isValidationEnabled = true; } // END SJSAS 6384538 // keepgenerated default is false for JDK6 for later, true otherwise keepGenerated = getBoolean(config, !isJDK6(), "keepgenerated"); saveBytecode = getBoolean(config, saveBytecode, "saveBytecode"); trimSpaces = getBoolean(config, trimSpaces, "trimSpaces"); isPoolingEnabled = getBoolean(config, isPoolingEnabled, "enablePooling"); mappedFile = getBoolean(config, mappedFile, "mappedfile"); sendErrorToClient = getBoolean(config, sendErrorToClient, "sendErrToClient"); classDebugInfo = getBoolean(config, classDebugInfo, "classdebuginfo"); development = getBoolean(config, development, "development"); isSmapSuppressed = getBoolean(config, isSmapSuppressed, "suppressSmap"); isSmapDumped = getBoolean(config, isSmapDumped, "dumpSmap"); genStringAsCharArray = getBoolean(config, genStringAsCharArray, "genStrAsCharArray"); genStringAsByteArray = getBoolean(config, genStringAsByteArray, "genStrAsByteArray"); defaultBufferNone = getBoolean(config, defaultBufferNone, "defaultBufferNone"); errorOnUseBeanInvalidClassAttribute = getBoolean(config, errorOnUseBeanInvalidClassAttribute, "errorOnUseBeanInvalidClassAttribute"); fork = getBoolean(config, fork, "fork"); xpoweredBy = getBoolean(config, xpoweredBy, "xpoweredBy"); String checkIntervalStr = config.getInitParameter("checkInterval"); if (checkIntervalStr != null) { parseCheckInterval(checkIntervalStr); } String modificationTestIntervalStr = config.getInitParameter("modificationTestInterval"); if (modificationTestIntervalStr != null) { parseModificationTestInterval(modificationTestIntervalStr); } String ieClassId = config.getInitParameter("ieClassId"); if (ieClassId != null) this.ieClassId = ieClassId; String classpath = config.getInitParameter("classpath"); if (classpath != null) this.classpath = classpath; // START PWC 1.2 6311155 String sysClassPath = config.getInitParameter("com.sun.appserv.jsp.classpath"); this.sysClassPath = sysClassPath != null ? sysClassPath : System.getProperty("java.class.path"); // END PWC 1.2 6311155 if ("false".equals(config.getInitParameter("delegate"))) { delegate = false; } /* * scratchdir */ String dir = config.getInitParameter("scratchdir"); if (dir != null) { scratchDir = new File(dir); } else { // First try the Servlet 2.2 javax.servlet.context.tempdir property scratchDir = (File) context.getAttribute(Constants.TMP_DIR); if (scratchDir == null) { // Not running in a Servlet 2.2 container. // Try to get the JDK 1.2 java.io.tmpdir property dir = System.getProperty("java.io.tmpdir"); if (dir != null) scratchDir = new File(dir); } } if (this.scratchDir == null) { log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir")); return; } if (!(scratchDir.exists() && scratchDir.canRead() && scratchDir.canWrite() && scratchDir.isDirectory())) log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", scratchDir.getAbsolutePath())); this.compiler = config.getInitParameter("compiler"); String compilerTargetVM = config.getInitParameter("compilerTargetVM"); if (compilerTargetVM != null) { this.compilerTargetVM = compilerTargetVM; } String compilerSourceVM = config.getInitParameter("compilerSourceVM"); if (compilerSourceVM != null) { this.compilerSourceVM = compilerSourceVM; } String javaEncoding = config.getInitParameter("javaEncoding"); if (javaEncoding != null) { this.javaEncoding = javaEncoding; } String reloadIntervalString = config.getInitParameter("reload-interval"); if (reloadIntervalString != null) { int reloadInterval = 0; try { reloadInterval = Integer.parseInt(reloadIntervalString); } catch (NumberFormatException e) { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.reloadInterval")); } } if (reloadInterval == -1) { // Never check JSPs for modifications, and disable // recompilation this.development = false; this.checkInterval = 0; } else { // Check JSPs for modifications at specified interval in // both (development and non-development) modes parseCheckInterval(reloadIntervalString); parseModificationTestInterval(reloadIntervalString); } } // BEGIN S1AS 6181923 String usePrecompiled = config.getInitParameter("usePrecompiled"); if (usePrecompiled == null) { usePrecompiled = config.getInitParameter("use-precompiled"); } if (usePrecompiled != null) { if (usePrecompiled.equalsIgnoreCase("true")) { this.usePrecompiled = true; } else if (usePrecompiled.equalsIgnoreCase("false")) { this.usePrecompiled = false; } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.usePrecompiled")); } } } // END S1AS 6181923 // START SJSWS String capacity = config.getInitParameter("initialCapacity"); if (capacity == null) { capacity = config.getInitParameter("initial-capacity"); } if (capacity != null) { try { initialCapacity = Integer.parseInt(capacity); // Find a value that is power of 2 and >= the specified // initial capacity, in order to make Hashtable indexing // more efficient. int value = Constants.DEFAULT_INITIAL_CAPACITY; while (value < initialCapacity) { value *= 2; } initialCapacity = value; } catch (NumberFormatException nfe) { if (log.isWarnEnabled()) { String msg = Localizer.getMessage("jsp.warning.initialcapacity"); msg = MessageFormat.format(msg, capacity, Integer.valueOf(Constants.DEFAULT_INITIAL_CAPACITY)); log.warn(msg); } } } String jspCompilerPlugin = config.getInitParameter("javaCompilerPlugin"); if (jspCompilerPlugin != null) { if ("org.apache.jasper.compiler.JikesJavaCompiler".equals(jspCompilerPlugin)) { this.compiler = "jikes"; } else if ("org.apache.jasper.compiler.SunJava14Compiler".equals(jspCompilerPlugin)) { // use default, do nothing } else { // use default, issue warning if (log.isWarnEnabled()) { String msg = Localizer.getMessage("jsp.warning.unsupportedJavaCompiler"); msg = MessageFormat.format(msg, jspCompilerPlugin); log.warn(msg); } } } // END SJSWS // Setup the global Tag Libraries location cache for this // web-application. /* SJSAS 6384538 tldLocationsCache = new TldLocationsCache(context); */ // START SJSAS 6384538 tldLocationsCache = new TldLocationsCache(context, this); // END SJSAS 6384538 // Setup the jsp config info for this web app. /* SJSAS 6384538 jspConfig = new JspConfig(context); */ // START SJSAS 6384538 jspConfig = new JspConfig(context, this); // END SJSAS 6384538 // Create a Tag plugin instance tagPluginManager = new TagPluginManager(context); }
From source file:org.kuali.rice.ksb.messaging.servlet.KSBDispatcherServlet.java
/** * This is a workaround after upgrading to CXF 2.7.0 whereby we could no longer just call "setHideServiceList" on * the ServletController. Instead, it is now reading this information from the ServletConfig, so wrapping the base * ServletContext to return true or false for hide service list depending on whether or not we are in dev mode. *//*from w w w . ja va 2 s . com*/ protected ServletConfig getCXFServletConfig(final ServletConfig baseServletConfig) { // disable handling of URLs ending in /services which display CXF generated service lists if we are not in dev mode final String shouldHide = Boolean .toString(!ConfigContext.getCurrentContextConfig().getDevMode().booleanValue()); return new ServletConfig() { private static final String HIDE_SERVICE_LIST_PAGE_PARAM = "hide-service-list-page"; @Override public String getServletName() { return baseServletConfig.getServletName(); } @Override public ServletContext getServletContext() { return baseServletConfig.getServletContext(); } @Override public String getInitParameter(String parameter) { if (HIDE_SERVICE_LIST_PAGE_PARAM.equals(parameter)) { return shouldHide; } return baseServletConfig.getInitParameter(parameter); } @Override public Enumeration<String> getInitParameterNames() { List<String> initParameterNames = EnumerationUtils .toList(baseServletConfig.getInitParameterNames()); initParameterNames.add(HIDE_SERVICE_LIST_PAGE_PARAM); return new Vector<String>(initParameterNames).elements(); } }; }