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.wso2.carbon.identity.application.authenticator.iwa.ntlm.servlet.IWAServlet.java
@Override public void init(ServletConfig config) throws ServletException { Map<String, String> implParameters = new HashMap<String, String>(); String authProvider = null;// w ww . j a v a 2 s . c o m String[] providerNames = null; if (config != null) { Enumeration parameterNames = config.getInitParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); String parameterValue = config .getInitParameter(parameterName); if (parameterName.equals(IWAConstants.PRINCIPAL_FORMAT)) { IWAServiceDataHolder.getInstance().setPrincipalFormat(PrincipalFormat.valueOf(parameterValue)); } else if (parameterName.equals(IWAConstants.ROLE_FORMAT)) { IWAServiceDataHolder.getInstance().setRoleFormat(PrincipalFormat.valueOf(parameterValue)); } else if (parameterName.equals(IWAConstants.ALLOW_GUEST_LOGIN)) { IWAServiceDataHolder.getInstance().setAllowGuestLogin(Boolean.parseBoolean(parameterValue)); } else if (parameterName.equals(IWAConstants.IMPERSONATE)) { IWAServiceDataHolder.getInstance().setImpersonate(Boolean.parseBoolean(parameterValue)); } else if (parameterName.equals(IWAConstants.SECURITY_FILTER_PROVIDERS)) { providerNames = parameterValue.split("\\s+"); } else if (parameterName.equals(IWAConstants.AUTH_PROVIDER)) { authProvider = parameterValue; } else { implParameters.put(parameterName, parameterValue); } } } if (authProvider != null) { try { IWAServiceDataHolder.getInstance() .setAuth((IWindowsAuthProvider) Class.forName(authProvider).getConstructor().newInstance()); } catch (Exception e) { throw new ServletException("Error loading '" + authProvider, e); } } if (IWAServiceDataHolder.getInstance().getAuth() == null) { IWAServiceDataHolder.getInstance().setAuth(new WindowsAuthProviderImpl()); } if (providerNames != null) { IWAServiceDataHolder.getInstance().setProviders(new SecurityFilterProviderCollection(providerNames, IWAServiceDataHolder.getInstance().getAuth())); } // create default providers if none specified if (IWAServiceDataHolder.getInstance().getProviders() == null) { if (log.isDebugEnabled()) { log.debug("initializing default security filter providers"); } IWAServiceDataHolder.getInstance().setProviders( new SecurityFilterProviderCollection(IWAServiceDataHolder.getInstance().getAuth())); } // apply provider implementation parameters for (Map.Entry<String, String> implParameter : implParameters.entrySet()) { String[] classAndParameter = implParameter.getKey().split("/", 2); if (classAndParameter.length == 2) { try { if (log.isDebugEnabled()) { log.debug("Setting " + classAndParameter[0] + ", " + classAndParameter[1] + "=" + implParameter.getValue()); } SecurityFilterProvider provider = IWAServiceDataHolder.getInstance().getProviders() .getByClassName(classAndParameter[0]); provider.initParameter(classAndParameter[1], implParameter.getValue()); } catch (ClassNotFoundException e) { throw new ServletException( "Invalid class: " + classAndParameter[0] + " in " + implParameter.getKey(), e); } } else { throw new ServletException("Invalid parameter: " + implParameter.getKey()); } } }
From source file:fedora.localservices.saxon.SaxonServlet.java
/** * Initialize the servlet by setting up the stylesheet cache, the http * connection manager, and configuring credentials for the http client. *///from ww w . j av a2 s .c om @Override public void init(ServletConfig config) throws ServletException { m_cache = new HashMap<String, Templates>(); m_creds = new HashMap<String, UsernamePasswordCredentials>(); m_cManager = new MultiThreadedHttpConnectionManager(); m_cManager.getParams().setConnectionTimeout(TIMEOUT_SECONDS * 1000); Enumeration<?> enm = config.getInitParameterNames(); while (enm.hasMoreElements()) { String name = (String) enm.nextElement(); if (name.startsWith(CRED_PARAM_START)) { String value = config.getInitParameter(name); if (value.indexOf(":") == -1) { throw new ServletException( "Malformed credentials for " + name + " -- expected ':' user/pass delimiter"); } String[] parts = value.split(":"); String user = parts[0]; StringBuffer pass = new StringBuffer(); for (int i = 1; i < parts.length; i++) { if (i > 1) { pass.append(':'); } pass.append(parts[i]); } m_creds.put(name.substring(CRED_PARAM_START.length()), new UsernamePasswordCredentials(user, pass.toString())); } } }
From source file:org.wings.session.WingServlet.java
/** * The following init parameters are known by wings. * <p/>/* w ww . j av a2 s. c o m*/ * <dl compact> * <dt>externalizer.timeout</dt><dd> - The time, externalized objects * are kept, before they are removed</dd> * <p/> * <dt>content.maxlength</dt><dd> - Maximum content lengt for form posts. * Remember to increase this, if you make use of the SFileChooser * component</dd> * <p/> * <dt>filechooser.uploaddir</dt><dd> - The directory, where uploaded * files ar stored temporarily</dd> * </dl> * <p/> * <dt>wings.servlet.lookupname</dt><dd> - The name the wings sessions of * this servlet instance are stored in the servlet session hashtable</dd> * </dl> * * @throws ServletException */ public void init(ServletConfig config) throws ServletException { super.init(config); servletConfig = config; if (log.isInfoEnabled()) { log.info("Initializing wingS global servlet with configuration:"); for (Enumeration en = config.getInitParameterNames(); en.hasMoreElements();) { String param = (String) en.nextElement(); log.info(" " + param + " = " + config.getInitParameter(param)); } } initLookupName(config); }
From source file:org.iff.infra.util.servlet.ProxyServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); {//add by tylerchen Enumeration<String> names = servletConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = servletConfig.getInitParameter(name); initParameterMap.put(name, StringHelper.replaceBlock(value, MapHelper.toMap("CPATH", servletConfig.getServletContext().getContextPath()), null)); }/*from w ww . j a v a 2 s.c o m*/ } String doLogStr = servletConfig.getInitParameter(P_LOG); if (doLogStr != null) { this.doLog = Boolean.parseBoolean(doLogStr); } String doForwardIPString = servletConfig.getInitParameter(P_FORWARDEDFOR); if (doForwardIPString != null) { this.doForwardIP = Boolean.parseBoolean(doForwardIPString); } try {// get target url String paramName = initParameterMap.get("paramName"); if (paramName != null) { String targetUri = null;//TODO ResourceKit.getValue(paramName); if (targetUri == null || targetUri.length() < 1) { targetUri = servletConfig.getInitParameter(P_TARGET_URI); } targetUriObj = new URI(targetUri); } } catch (Exception e) { throw new RuntimeException("Trying to process targetUri init parameter: " + e, e); } targetUri = targetUriObj.toString(); HttpParams hcParams = new BasicHttpParams(); readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class); proxyClient = createHttpClient(hcParams); }
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
/** * Looks up an instance of a service and creates one if necessary. * * @param session the current session (for storing * instances). * @param serviceClassName the fully qualified name of the class * to instantiate. * @param name the name to use for the instance. * @param requiredType The type the service must have. May be * null. //from w w w. ja v a2s. com */ public synchronized Service getServiceInstance(HttpSession session, String serviceClassName, Object name, Class requiredType) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { if (requiredType == null) { requiredType = Service.class; } String lookFor = serviceClassName; if (name != null) { lookFor += "/" + name; } Service inst = (Service) session.getAttribute(lookFor); if (inst == null) { Class clazz = Class.forName(serviceClassName); if (!requiredType.isAssignableFrom(clazz)) { throw new ClassCastException("The requested service class " + clazz.getName() + " is not from the required type " + requiredType.getName() + ""); } inst = (Service) clazz.newInstance(); Class[] paramTypes = new Class[1]; Object[] params = new Object[1]; paramTypes[0] = Environment.class; Method method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentEnvironment", paramTypes); if (method == null) { method = MethodUtils.getMatchingAccessibleMethod(clazz, "setQooxdooEnvironment", paramTypes); } if (method != null) { params[0] = new Environment(); method.invoke(inst, params); } if (name != null) { paramTypes[0] = String.class; method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentName", paramTypes); if (method != null) { params[0] = name; method.invoke(inst, params); } } session.setAttribute(lookFor, inst); // initialize the service properties ServletConfig servletConfig = getServletConfig(); Enumeration initParamNames = servletConfig.getInitParameterNames(); String initParamName; String initParamValue; int pos; String packageName; String propertyName; HashMap candidates = new HashMap(); while (initParamNames.hasMoreElements()) { initParamName = (String) initParamNames.nextElement(); pos = initParamName.lastIndexOf('.'); if (pos == -1) { packageName = ""; propertyName = initParamName; } else { packageName = initParamName.substring(0, pos); propertyName = initParamName.substring(pos + 1); } String candidateName; if (serviceClassName.startsWith(packageName)) { candidateName = (String) candidates.get(propertyName); if (candidateName == null) { candidates.put(propertyName, initParamName); } else if (candidateName.length() < initParamName.length()) { candidates.put(propertyName, initParamName); } } } Iterator candidatesIterator = candidates.keySet().iterator(); Class propertyType; while (candidatesIterator.hasNext()) { propertyName = (String) candidatesIterator.next(); initParamName = (String) candidates.get(propertyName); initParamValue = servletConfig.getInitParameter(initParamName); propertyType = PropertyUtils.getPropertyType(inst, propertyName); if (propertyType != null) { if (propertyType.getComponentType() == String.class) { PropertyUtils.setSimpleProperty(inst, propertyName, StringUtils.tokenize(initParamValue, ';')); } else { try { PropertyUtils.setSimpleProperty(inst, propertyName, ConvertUtils.convert(initParamValue, propertyType)); } catch (Exception e) { // try to instatiate a class of the supplied parameter //System.out.println("***** setting '" + propertyName + "' to an instance of '" + initParamValue + "'"); PropertyUtils.setSimpleProperty(inst, propertyName, getServiceInstance(session, initParamValue, null, null)); } } } else { //System.out.println("***** property '" + propertyName + "' not matched"); } } // tell the instance that we're done paramTypes = new Class[0]; method = MethodUtils.getMatchingAccessibleMethod(clazz, "webcomponentInit", paramTypes); if (method != null) { params = new Object[0]; method.invoke(inst, params); } } return inst; }
From source file:org.wings.session.PortletWingServlet.java
/** * The following init parameters are known by wings. * <p/>// w ww . j ava 2s .c o m * <dl compact> * <dt>externalizer.timeout</dt><dd> - The time, externalized objects * are kept, before they are removed</dd> * <p/> * <dt>content.maxlength</dt><dd> - Maximum content lengt for form posts. * Remember to increase this, if you make use of the SFileChooser * component</dd> * <p/> * <dt>filechooser.uploaddir</dt><dd> - The directory, where uploaded * files ar stored temporarily</dd> * </dl> * <p/> * <dt>wings.servlet.lookupname</dt><dd> - The name the wings sessions of * this servlet instance are stored in the servlet session hashtable</dd> * </dl> * * @throws ServletException */ public final void init(ServletConfig config) throws ServletException { super.init(config); servletConfig = config; if (log.isInfoEnabled()) { log.info("Initializing wingS global servlet with configuration:"); for (Enumeration en = config.getInitParameterNames(); en.hasMoreElements();) { String param = (String) en.nextElement(); log.info(" " + param + " = " + config.getInitParameter(param)); } } // initLookupName(config); }
From source file:org.wrml.server.WrmlServletTest.java
@Test(expected = ServletException.class) public void createAndInitTwoParam() throws ServletException { ServletConfig servletConfig = mock(ServletConfig.class); Enumeration<String> eStrings = new TestTwoEnum(); when(servletConfig.getInitParameterNames()).thenReturn(eStrings); _Servlet.init(servletConfig);//from w ww . j a v a 2 s . com }
From source file:org.wrml.server.WrmlServletTest.java
@Test(expected = ServletException.class) public void createAndInitNoParam() throws ServletException { ServletConfig servletConfig = mock(ServletConfig.class); Enumeration<String> eStrings = new TestEmptyEnum(); when(servletConfig.getInitParameterNames()).thenReturn(eStrings); _Servlet.init(servletConfig);/*from w ww . j a va 2s . c o m*/ }
From source file:org.wrml.server.WrmlServletTest.java
@Test(expected = ServletException.class) public void createAndInitBadLocation() throws ServletException { ServletConfig servletConfig = mock(ServletConfig.class); Enumeration<String> eStrings = new TestEmptyEnum(); when(servletConfig.getInitParameterNames()).thenReturn(eStrings); String configLocation = "abcdefg"; when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME)) .thenReturn(configLocation); _Servlet.init(servletConfig);//from w ww . java 2 s . c o m }
From source file:org.wrml.server.WrmlServletTest.java
@Test(expected = ServletException.class) public void createAndInitMalformedFile() throws ServletException { ServletConfig servletConfig = mock(ServletConfig.class); Enumeration<String> eStrings = new TestEmptyEnum(); when(servletConfig.getInitParameterNames()).thenReturn(eStrings); String configLocation = "wrmlbad.json"; when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME)) .thenReturn(configLocation); _Servlet.init(servletConfig);/*from w w w. java2 s . co m*/ }