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.pentaho.telemetry.web.TelemetryServlet.java
/** * Initializes the servlet.//from w w w . j a va 2s. co m */ public void init(ServletConfig config) throws ServletException { super.init(config); Enumeration initParameterNames = config.getInitParameterNames(); Map<String, String> params = new HashMap<String, String>(); while (initParameterNames.hasMoreElements()) { String name = (String) initParameterNames.nextElement(); String value = config.getInitParameter(name); params.put(name, value); } serializer.setup(params); }
From source file:edu.ucsd.xmlrpc.xmlrpc.webserver.XmlRpcServlet.java
private void handleInitParameters(ServletConfig pConfig) throws ServletException { for (Enumeration en = pConfig.getInitParameterNames(); en.hasMoreElements();) { String name = (String) en.nextElement(); String value = pConfig.getInitParameter(name); try {//from w w w . j av a 2s .co m if (!ReflectionUtil.setProperty(this, name, value) && !ReflectionUtil.setProperty(server, name, value) && !ReflectionUtil.setProperty(server.getConfig(), name, value)) { throw new ServletException("Unknown init parameter " + name); } } catch (IllegalAccessException e) { throw new ServletException("Illegal access to instance of " + server.getClass().getName() + " while setting property " + name + ": " + e.getMessage(), e); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); throw new ServletException("Failed to invoke setter for property " + name + " on instance of " + server.getClass().getName() + ": " + t.getMessage(), t); } } }
From source file:org.apache.openaz.xacml.rest.XACMLRest.java
/** * 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: -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 *///www . j ava2s . co m 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 // if (logger.isDebugEnabled()) { logger.debug("Using Servlet Config Property for XACML_PROPERTIES_NAME:" + propFile); } System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, propFile); } else { if (logger.isDebugEnabled()) { 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); } } }
From source file:org.springframework.faces.mvc.servlet.FacesHandlerAdapterTests.java
public void testDelegatingServletConfig() throws Exception { Properties initParameters = new Properties(); initParameters.setProperty("testkey", "testvalue"); ServletContext servletContext = (ServletContext) EasyMock.createMock(ServletContext.class); adapter.setInitParameters(initParameters); adapter.setServletContext(servletContext); adapter.setOverrideInitParameters(false); adapter.setFacesServletClass(MockServlet.class); adapter.afterPropertiesSet();//from w w w.j a v a 2 s . c o m MockServlet servlet = (MockServlet) adapter.getFacesServlet(); ServletConfig config = servlet.getServletConfig(); assertTrue(EnumerationUtils.toList(config.getInitParameterNames()).contains("testkey")); assertEquals("testvalue", config.getInitParameter("testkey")); assertEquals("testAdapterBean", config.getServletName()); assertSame(servletContext, config.getServletContext()); }
From source file:org.webguitoolkit.ui.http.PageServlet.java
/** * // init page-mappings (i102455/20080220) * requires mapping in web-xml/* ww w . jav a 2 s . c om*/ * * Example: <init-param> <description> page mapping to prevent long page * names </description> <param-name>page-mapping@NameOfPageClass</param-name> * <param-value> abbriviation;index;test;index.htm;whatever * </param-value> </init-param> * * Description: param-name: page-mapping@ followed by the PageClassName. * Packages must be defined by the import init-param of this servlet * param-value: add short names for the PageClassName */ private void initPageMappings(ServletConfig sc) throws ServletException { // get all initParamsNames Enumeration initParamNames = sc.getInitParameterNames(); if (initParamNames != null) { // loop through initParamsNames and check for start page-mapping@ while (initParamNames.hasMoreElements()) { String initParamName = (String) initParamNames.nextElement(); if (initParamName != null && initParamName.startsWith(PAGE_MAPPING) && initParamName.indexOf("@") < initParamName.length()) { // get parameter String mapping = sc.getInitParameter(initParamName); if (StringUtils.isNotEmpty(mapping)) { String[] mapArray = StringUtils.split(mapping, ';'); if (mapArray != null) { for (int i = 0; i < mapArray.length; i++) { if (pageMapppingMap == null) pageMapppingMap = new Hashtable(); // add mapping -> page entry to table try { if (pageMapppingMap.get(StringUtils.trimToEmpty(mapArray[i])) == null) { pageMapppingMap.put(StringUtils.trimToEmpty(mapArray[i]), StringUtils.substringAfter(initParamName, "@")); } else { throw new Exception("Duplicate page mapping for '" + StringUtils.trimToEmpty(mapArray[i]) + "', check web.xml"); } } catch (Exception e) { e.printStackTrace(); } } } } } } } }
From source file:org.mobicents.servlet.sip.restcomm.callmanager.gateway.SipGatewayManager.java
@Override public void init(ServletConfig config) throws ServletException { logger.info("initializing ServletConfig:" + config + " ServletName:" + config.getServletName() + " InitParameterNames:" + config.getInitParameterNames()); this.config = config; final ServletContext context = config.getServletContext(); final ServiceLocator services = ServiceLocator.getInstance(); // daos = services.get(DaoManager.class); // logger.info("getGatewaysDao:"+daos.getGatewaysDao()); // gateways = daos.getGatewaysDao().getGateways(); clock = (TimerService) config.getServletContext().getAttribute(TIMER_SERVICE); sipFactory = (SipFactory) context.getAttribute(SIP_FACTORY); final TimerManager timers = services.get(TimerManager.class); try {/*from w w w . j a v a 2 s. com*/ final SipGatewayManagerTimerListener listener = new SipGatewayManagerTimerListener(); if (!timers.isRegistered("REGISTER")) { timers.register("REGISTER", listener); } } catch (final TooManyListenersException ignored) { } }
From source file:org.apache.geronimo.daytrader.javaee6.web.TradeAppServlet.java
/** * Servlet initialization method./*w w w . ja v a2s . c o m*/ */ public void init(ServletConfig config) throws ServletException { super.init(config); java.util.Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { String parm = (String) en.nextElement(); String value = config.getInitParameter(parm); TradeConfig.setConfigParam(parm, value); } try { if (TradeConfig.runTimeMode == TradeConfig.JDBC) { TradeJDBCDirect.init(); } else if (TradeConfig.runTimeMode == TradeConfig.JPA) { TradeJPADirect.init(); } else { TradeJEEDirect.init(); } } catch (Exception e) { Log.error(e, "TradeAppServlet:init -- Error initializing TradeDirect"); } }
From source file:org.hyperic.lather.server.LatherServlet.java
private ConnManager getConnManager(ServletConfig cfg) throws ServletException { @SuppressWarnings("unchecked") final Enumeration<String> paramNames = cfg.getInitParameterNames(); final Map<String, Semaphore> maxConnMap = new HashMap<String, Semaphore>(); while (paramNames.hasMoreElements()) { final String name = paramNames.nextElement(); if (!name.startsWith(PROP_PREFIX) || name.contains(PROP_EXECTIMEOUT)) { continue; }/*ww w. j ava 2 s . c o m*/ final String param = cfg.getInitParameter(name); try { final int value = Integer.parseInt(param); maxConnMap.put(name.replace(PROP_PREFIX, ""), new Semaphore(value)); } catch (NumberFormatException e) { log.error("could not initialize max conn setting for " + name + " value=" + param); } } if (!maxConnMap.containsKey(PROP_MAXCONNS)) { throw new ServletException("init-params do not contain key=" + PROP_MAXCONNS + ")"); } return new ConnManager(maxConnMap); }
From source file:com.cyclopsgroup.waterview.servlet.WaterviewServlet.java
/** * Override method init in super class of MainServlet * * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) *///from www.j av a2 s .c om public void init(ServletConfig config) throws ServletException { applicationBase = config.getInitParameter("application.base"); servletConfig = config; String basedir = config.getServletContext().getRealPath(""); Properties initProperties = new Properties(); initProperties.setProperty("basedir", basedir); initProperties.setProperty("plexus.home", basedir); Enumeration i = config.getInitParameterNames(); while (i.hasMoreElements()) { String key = (String) i.nextElement(); String value = config.getInitParameter(key); initProperties.setProperty(key, value); } try { container = new WaterviewPlexusContainer(); serviceManager = new ServiceManagerAdapter(container); for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) { String initPropertyName = (String) j.next(); container.addContextValue(initPropertyName, initProperties.get(initPropertyName)); } container.addContextValue(Waterview.INIT_PROPERTIES, initProperties); container.initialize(); container.start(); } catch (Exception e) { container.getLogger().fatalError("Can not start container", e); } }
From source file:org.sakaiproject.util.Web.java
public static String snoop(PrintWriter out, boolean html, ServletConfig config, HttpServletRequest req) { // if no out, send to system out ByteArrayOutputStream ostream = null; if (out == null) { ostream = new ByteArrayOutputStream(); out = new PrintWriter(ostream); html = false;/* w w w . j a v a 2 s .c o m*/ } String h1 = ""; String h1x = ""; String pre = ""; String prex = ""; String b = ""; String bx = ""; String p = ""; if (html) { h1 = "<h1>"; h1x = "</h1>"; pre = "<pre>"; prex = "</pre>"; b = "<b>"; bx = "</b>"; p = "<p>"; } Enumeration<?> e = null; out.println(h1 + "Snoop for request" + h1x); out.println(req.toString()); if (config != null) { e = config.getInitParameterNames(); if (e != null) { boolean first = true; while (e.hasMoreElements()) { if (first) { out.println(h1 + "Init Parameters" + h1x); out.println(pre); first = false; } String param = (String) e.nextElement(); out.println(" " + param + ": " + config.getInitParameter(param)); } out.println(prex); } } out.println(h1 + "Request information:" + h1x); out.println(pre); print(out, "Request method", req.getMethod()); String requestUri = req.getRequestURI(); print(out, "Request URI", requestUri); displayStringChars(out, requestUri); print(out, "Request protocol", req.getProtocol()); String servletPath = req.getServletPath(); print(out, "Servlet path", servletPath); displayStringChars(out, servletPath); String contextPath = req.getContextPath(); print(out, "Context path", contextPath); displayStringChars(out, contextPath); String pathInfo = req.getPathInfo(); print(out, "Path info", pathInfo); displayStringChars(out, pathInfo); print(out, "Path translated", req.getPathTranslated()); print(out, "Query string", req.getQueryString()); print(out, "Content length", req.getContentLength()); print(out, "Content type", req.getContentType()); print(out, "Server name", req.getServerName()); print(out, "Server port", req.getServerPort()); print(out, "Remote user", req.getRemoteUser()); print(out, "Remote address", req.getRemoteAddr()); // print(out, "Remote host", req.getRemoteHost()); print(out, "Authorization scheme", req.getAuthType()); out.println(prex); e = req.getHeaderNames(); if (e.hasMoreElements()) { out.println(h1 + "Request headers:" + h1x); out.println(pre); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(" " + name + ": " + req.getHeader(name)); } out.println(prex); } e = req.getParameterNames(); if (e.hasMoreElements()) { out.println(h1 + "Servlet parameters (Single Value style):" + h1x); out.println(pre); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(" " + name + " = " + req.getParameter(name)); } out.println(prex); } e = req.getParameterNames(); if (e.hasMoreElements()) { out.println(h1 + "Servlet parameters (Multiple Value style):" + h1x); out.println(pre); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String vals[] = (String[]) req.getParameterValues(name); if (vals != null) { out.print(b + " " + name + " = " + bx); out.println(vals[0]); for (int i = 1; i < vals.length; i++) out.println(" " + vals[i]); } out.println(p); } out.println(prex); } e = req.getAttributeNames(); if (e.hasMoreElements()) { out.println(h1 + "Request attributes:" + h1x); out.println(pre); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(" " + name + ": " + req.getAttribute(name)); } out.println(prex); } if (ostream != null) { out.flush(); return ostream.toString(); } return ""; }