Example usage for javax.servlet ServletContext getInitParameter

List of usage examples for javax.servlet ServletContext getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletContext getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

Usage

From source file:gr.forth.ics.isl.webservice.XPathsWebservice.java

/**
 * helper method to get the home path from web.xml
 *
 * @return/*from  w  w  w .j  ava 2s. c o  m*/
 */
private String getHomePath(String filename) {
    ServletContext context = request.getSession().getServletContext();
    String pathValue = context.getInitParameter("AppHome");
    if (filename.endsWith("xsd")) {
        pathValue = pathValue + FS + "xml_schema";
    } else {
        pathValue = pathValue + FS + "example_files";
    }
    return pathValue + FS;
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilter.java

protected void initInternal(final FilterConfig filterConfig) throws ServletException {
    logger.trace(this.getClass() + ".initInternal() BEGIN");

    if (!isIgnoreInitConfiguration()) {
        super.initInternal(filterConfig);

        // TODO ?    
        ServletContext context = filterConfig.getServletContext();
        String casServerName = context.getInitParameter(CAS_SERVER_NAME_CONTEXT_PARAMETER);
        CommonUtils.assertNotNull(casServerName, "casServerContextName cannot be null.");

        String casServerLoginPath = casServerName + "/login";

        String casServerAddress = getCasServerAddress();
        setCasServerLoginUrl(casServerAddress + "/" + casServerLoginPath);

        logger.trace("CasServerLoginUrl: " + this.casServerLoginUrl);

        setRenew(parseBoolean(getPropertyFromInitParams(filterConfig, "renew", "false")));
        logger.trace("Loaded renew parameter: " + this.renew);
        setGateway(parseBoolean(getPropertyFromInitParams(filterConfig, "gateway", "false")));
        logger.trace("Loaded gateway parameter: " + this.gateway);

        final String gatewayStorageClass = getPropertyFromInitParams(filterConfig, "gatewayStorageClass", null);

        if (gatewayStorageClass != null) {
            try {
                this.gatewayStorage = (GatewayResolver) Class.forName(gatewayStorageClass).newInstance();
            } catch (final Exception e) {
                logger.error(e, e);// w  w w  .  j ava 2  s .c  om
                throw new ServletException(e);
            }
        }
    }

    logger.trace(this.getClass() + ".initInternal() END");
}

From source file:org.kuali.rice.core.web.listener.KualiInitializeListener.java

/**
 * Translates context parameters from the web.xml into entries in a Properties file.
 *//*from   w  ww . j  a  v  a2s.c o  m*/
protected Properties getContextParameters(ServletContext context) {
    Properties properties = new Properties();
    @SuppressWarnings("unchecked")
    Enumeration<String> paramNames = context.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        properties.put(paramName, context.getInitParameter(paramName));
    }
    return properties;
}

From source file:org.pentaho.platform.web.http.context.SolutionContextListener.java

/**
 * Look for a parameter called "pentaho-system-cfg". If found, use its value to set the the value of the System
 * property "SYSTEM_CFG_PATH_KEY". This value is used by a LiberatedSystemSettings class to determine the location of
 * the system configuration file. This is typically pentaho.xml.
 *
 * @param context ServletContext/*www.  ja  v a  2s.  c  om*/
 */
private void setSystemCfgFile(final ServletContext context) {
    String jvmSpecifiedSysCfgPath = System.getProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY);
    if (StringUtils.isBlank(jvmSpecifiedSysCfgPath)) {
        String webSpecifiedSysCfgPath = context.getInitParameter("pentaho-system-cfg"); //$NON-NLS-1$
        if (StringUtils.isNotBlank(webSpecifiedSysCfgPath)) {
            System.setProperty(PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY, webSpecifiedSysCfgPath);
        }
    }
    // if it is blank, no big deal, we'll simply fall back on defaults
}

From source file:org.sakaiproject.login.springframework.SakaiHomeContextLoader.java

/**
 * Initialize the local ApplicationContext, link it to the shared context, and load shared definitions into the shared context.
 *
 * @param servletContext current servlet context
 * @return the new WebApplicationContext
 * @throws org.springframework.beans.BeansException
 *          if the context couldn't be initialized
 *///from   w  ww  . j  av  a2  s  .  c o m
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException {

    WebApplicationContext rv = super.initWebApplicationContext(servletContext);
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) rv;

    if (configurableApplicationContext != null) {
        String sakaiHomeLocation = servletContext.getInitParameter(SAKAI_HOME_LOCATION_PARAM);
        String servletContextName = rv.getServletContext().getServletContextName();
        if (sakaiHomeLocation == null || sakaiHomeLocation.length() == 0) {
            sakaiHomeLocation = servletContextName + SAKAI_HOME_CONTEXT_SUFFIX;
        }
        if (sakaiHomeLocation != null) {
            final String sakaiHomePath = ServerConfigurationService.getSakaiHomePath();

            String[] locations = StringUtils.tokenizeToStringArray(sakaiHomeLocation,
                    ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS);
            if (locations != null) {

                XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(
                        (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory());

                for (int i = 0; i < locations.length; i++) {
                    String resourcePath = sakaiHomePath + locations[i];
                    M_log.debug(
                            servletContextName + " is attempting to load Spring beans from: " + resourcePath);
                    if (new File(resourcePath).exists()) {
                        reader.loadBeanDefinitions(new FileSystemResource(resourcePath));
                    } else {
                        M_log.info(servletContext + " startup is skipping introspection of the resource: "
                                + resourcePath + " because it does not exist.");
                    }
                }
            }
        }
    }

    return rv;
}

From source file:com.curl.orb.context.Seasar2ApplicationContext.java

/**
 * Create new Seasar2ApplicationContext.
 * /*from w w w.j  a v  a 2 s  . c  o  m*/
 * @param context ServletContext
 * @throws ApplicationContextException
 */
public Seasar2ApplicationContext(ServletContext context) throws ApplicationContextException {
    try {
        Class<?> cls = Class.forName("org.seasar.framework.container.servlet.SingletonS2ContainerInitializer");
        Object obj = cls.getConstructor(new Class[0]).newInstance(new Object[0]);
        if (context.getInitParameter("configPath") != null) {
            MethodUtils.invokeMethod(obj, "setConfigPath",
                    new Object[] { context.getInitParameter("configPath") });
        }
        MethodUtils.invokeMethod(obj, "setApplication", new Object[] { context });
        MethodUtils.invokeMethod(obj, "initialize", new Object[0]);
    } catch (IllegalArgumentException e) {
        throw new ApplicationContextException(e);
    } catch (SecurityException e) {
        throw new ApplicationContextException(e);
    } catch (InstantiationException e) {
        throw new ApplicationContextException(e);
    } catch (ClassNotFoundException e) {
        throw new ApplicationContextException(e);
    } catch (NoSuchMethodException e) {
        throw new ApplicationContextException(e);
    } catch (IllegalAccessException e) {
        throw new ApplicationContextException(e);
    } catch (InvocationTargetException e) {
        throw new ApplicationContextException(e);
    }
}

From source file:org.red5.server.war.RootContextLoaderServlet.java

protected void initRegistry(ServletContext ctx) {
    Registry r = null;//from w  w  w  .  j  a  v  a 2  s  .c  o m
    try {
        Object o = ctx.getInitParameter("rmiPort");
        if (o != null) {
            rmiPort = Integer.valueOf((String) o);
        }
        if (System.getSecurityManager() != null) {
            System.setSecurityManager(new RMISecurityManager());
        }
        // lookup the registry
        r = LocateRegistry.getRegistry(rmiPort);
        // ensure we are not already registered with the registry
        for (String regName : r.list()) {
            logger.debug("Registry entry: " + regName);
        }
    } catch (RemoteException re) {
        logger.info("RMI Registry server was not found on port " + rmiPort);
        // if we didnt find the registry and the user wants it created
        try {
            logger.info("Starting an internal RMI registry");
            // create registry for rmi
            r = LocateRegistry.createRegistry(rmiPort);
        } catch (RemoteException e) {
            logger.info("RMI Registry server was not started on port " + rmiPort);
        }

    }
}

From source file:org.ambraproject.configuration.WebAppListener.java

private FactoryConfig getFactoryConfig(ServletContext context) {
    // Allow JVM level property to override everything else
    String name = System.getProperty(ConfigurationStore.CONFIG_URL);

    if (name != null)
        return new FactoryConfig(name, "JVM System property " + ConfigurationStore.CONFIG_URL);

    // Now look for a config specified in web.xml
    name = context.getInitParameter(ConfigurationStore.CONFIG_URL);

    if (name != null)
        return new FactoryConfig(name,
                "Web-app context initialization parameter " + ConfigurationStore.CONFIG_URL);

    // Return a default
    return new FactoryConfig(ConfigurationStore.DEFAULT_CONFIG_URL, "default");
}

From source file:servlet.CinemaControl.java

protected void doListSeatsByIDs(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();
    ServletContext sc = getServletContext();
    String db_driver = sc.getInitParameter("db_driver"), db_url = sc.getInitParameter("db_url"),
            db_user = sc.getInitParameter("db_user"), db_password = sc.getInitParameter("db_password");
    String req_seatIDs = request.getParameter("seatID");

    String db_q_seat = "SELECT DISTINCT s.seatID, s.houseID, s.rowName, s.seatName, s.surcharge, s.state, ms.price"
            + " FROM Seat s, MovieSession ms" + " WHERE s.seatID IN" + " (" + req_seatIDs + ")"
            + " AND ms.houseID = s.houseID" + " AND ms.msID = ?";

    int msID = Integer.parseInt(request.getParameter("msID"));
    try {//ww w . j  a  va  2 s .co m
        JSONObject jso0 = new JSONObject();
        JSONArray jsa0 = new JSONArray();
        jso0.put("seats", jsa0);
        Class.forName(db_driver);
        Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
        // available seat
        PreparedStatement statmt1 = conn.prepareStatement(db_q_seat);
        statmt1.setInt(1, msID);
        if (statmt1.execute()) {
            ResultSet rs = statmt1.getResultSet();
            ResultSetMetaData rsmd = rs.getMetaData();
            int numOfColumns = rsmd.getColumnCount();
            while (rs.next()) {
                JSONObject jso1 = new JSONObject();
                jsa0.put(jso1);
                for (int i = 1; i <= numOfColumns; i++) {
                    jso1.put(rsmd.getColumnName(i), rs.getString(i));
                }
            }
        }

        conn.close();
        out.println(jso0.toString());

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(CinemaControl.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(CinemaControl.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(CinemaControl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.qualogy.qafe.webservice.servlet.GenericWebServiceServlet.java

protected Map<String, String> extractWebservices(ServletContext servletContext) {
    Map<String, String> webservices = new HashMap<String, String>();

    Enumeration<String> paramNames = (Enumeration<String>) servletContext.getInitParameterNames();

    while (paramNames.hasMoreElements()) {
        String parameterName = paramNames.nextElement();
        extractWebserviceParameter(webservices, parameterName, servletContext.getInitParameter(parameterName));
    }/* w ww  . ja  v  a2  s .  c o m*/
    return webservices;
}