private String getBaseUrl() { String root = ConfigUtils.getPropOrEnv(WEB_HOME_ENV); if (root == null) { throw new RuntimeException(WEB_HOME_ENV + " is not specified."); } return root + "/webapp"; }
public void setResourceBase(String resourceBase) { m_resourceBase = ConfigUtils.getInitialPropertyExpanded(resourceBase); }
/** * Returns all context files at the given path, across multiple data stores: files, svn/dav, etc. * * @param path * the directory path to look for context files. * @return all files ending in .xml at the given path. */ public static List<String> getContexts(String path) { try { ConfigDataSource cds = ConfigUtils.getConfigDataSource(path); List<String> names = new ArrayList<String>(cds.getStreamLocations()); for (int i = names.size() - 1; i >= 0; i--) if (!names.get(i).toUpperCase().endsWith(".XML")) names.remove(i); return names; } catch (Throwable t) { throw CommonUtils.runtimeException(t); } }
public static void setProperties(Object theTarget, Properties theProperties) throws ConfigException { Class<?> clazz = theTarget.getClass(); Method[] methods = clazz.getMethods(); for (Object key : theProperties.keySet()) { if (!(key instanceof String)) continue; String property = (String) key; String setter = "set" + (property.startsWith("is") ? property.substring(2) : property); for (int i = 0; i < methods.length; i++) { Class<?>[] formals = methods[i].getParameterTypes(); if (formals.length == 1 && setter.equalsIgnoreCase(methods[i].getName())) { Object value = getValueForType(formals[0], theProperties.getProperty(property)); try { // Pretty dumb now - doesn't handle overloads or many type conversions methods[i].invoke(theTarget, new Object[] { value }); i = methods.length; setter = null; } catch (Throwable t) { throw new ConfigException("Cannot set property " + property + " to value " + value, t); } } // if a matching setter } // for methods if (setter != null) LOGGER.warn( "No such property found: " + key + " in " + theTarget); } // for property keys }
/** * Calculates the list of default Spring context files. This list consists first of classpath context files, then * files from the configuration folder. The classpath context files are class resource files ending in .xml, named the * same as the "className" class in the ApplicationInformation, then its super class, etc, and then all implemented * interfaces. The classpath lookup mechanism is disabled if the class is null or cannot be loaded. The configuration * folder is specified by the com.ebay.jetstream.config system property if it exists, and if it does not exist, then the * "JetstreamConf" folder under the location contained in the JETSTREAM_HOME system property or environment variable * (checked in that order). * * @return the array of default context files. */ public static String[] getDefaultContexts(ApplicationInformation ai) { List<String> contexts = new ArrayList<String>(); Class<?> contextClass = ConfigUtils.getClassForName(ai.get("className")); if (contextClass != null) contexts.addAll(getClasspathContexts(contextClass)); contexts.addAll(getContexts(getConfigurationRoot())); contexts.addAll(getLdapContexts(ai)); contexts.addAll(getMongoContexts()); return contexts.toArray(new String[contexts.size()]); }
/** * Gets an individual ConfigStream (an InputStream and its location string) for the given path. The path reference * must be to a single item, not a folder. * * @param path * the path to the config stream. * @return the ConfigStream * @throws ConfigException * in case of any problem, including if path is a folder. */ public static ConfigDataSource.ConfigStream getConfigStream(String path) throws ConfigException { ConfigDataSource source = getConfigDataSource(path); try { if (source.isFolder()) throw new ConfigException("more than one stream found"); } catch (IOException e) { throw new ConfigException("cannot get stream: " + e, e); } Iterator<ConfigDataSource.ConfigStream> ii = source.iterator(); return ii.hasNext() ? ii.next() : null; }
/** * Gets a property from a java Properties, or a system property or process environment variable value, in that order. * If none is found, null is returned. * * @param properties * the Properties object * @param key * the string name of the property or environment variable. * @return the property or environment value, or null if none was found. */ public static String getPropOrEnv(Properties properties, String key) { String it = properties.getProperty(key); return it == null ? getPropOrEnv(key) : it; }
/** * Sets the System properties for those given to the new values, and adds properties that do not exist. Expands any * initial dollar-bracket-name-bracket sequence with its environment variable or pre-existing system property value. * * @param theProperties * the set of properties to add and update. */ public static void setSystemPropertiesExpanded(Properties theProperties) { for (Map.Entry<Object, Object> entry : theProperties.entrySet()) System.setProperty(entry.getKey().toString(), getInitialPropertyExpanded(entry.getValue().toString())); }
public static List<String> getMongoContexts() { List<String> mongo = new ArrayList<String>(); String mongoInfo = ConfigUtils.getPropOrEnv("MONGO_HOME"); //if (!CommonUtils.isEmptyTrimmed(mongoInfo)) if(mongoInfo != null && !CommonUtils.isEmptyTrimmed(mongoInfo)) { mongo.add(mongoInfo); } else { mongo.add("mongo:null"); } return mongo; }
/** * @param initParams * the initParams to set */ public void setInitParams(Map<String, String> initParams) { if (m_initParams == null) { m_initParams = new HashMap<String, String>(); } else { m_initParams.clear(); } for (String initParamKey : initParams.keySet()) { m_initParams.put(initParamKey, ConfigUtils.getInitialPropertyExpanded(initParams.get(initParamKey))); } }
/** * Returns the ldap urls to get configuration information from. Currently only one ldap url is returned, and only if * the LDAPINFORMATION property or env var is populated. * * @return the list of ldap urls */ public static List<String> getLdapContexts(ApplicationInformation ai) { List<String> ldap = new ArrayList<String>(); String ldapInfo = ConfigUtils.getPropOrEnv("LDAPINFORMATION"); if (ldapInfo != null) { int indexOfAt = ldapInfo.indexOf('@'); if (indexOfAt != -1 && ai.containsKey("ldapHostPort") && ldapInfo.charAt(indexOfAt + 1) == '/') { ldapInfo = ldapInfo.substring(0, indexOfAt + 1) + ai.get("ldapHostPort") + ldapInfo.substring(indexOfAt + 1); } else if (indexOfAt != -1 && !ai.containsKey("ldapHostPort") && ldapInfo.charAt(indexOfAt + 1) == '/') { throw new RuntimeException("Ldap host/port not set"); } if (!ldapInfo.contains("application=") && ai.containsKey("applicationName")) ldapInfo = addToUrlEnd(ldapInfo, "application=" + ai.get("applicationName")); if (!ldapInfo.contains("version=") && ai.containsKey("configVersion")) ldapInfo = addToUrlEnd(ldapInfo, "version=" + ai.get("configVersion")); if (!ldapInfo.contains("scope=")) ldapInfo = addToUrlEnd(ldapInfo, "scope=" + ai.get("scope")); } if (!CommonUtils.isEmptyTrimmed(ldapInfo)) ldap.add(ldapInfo); return ldap; }
/** * Writes a text file from a list of lines to a file by the given name and path. The path can optionally be prefixed * with a ${system.property}. * * @param theName * the file name, with optional System property prefix. * @param theContents * List of content lines. * @throws IOException */ public static void writeTextFile(String theName, List<String> theContents) throws IOException { theName = getInitialPropertyExpanded(theName); File file = new File(theName); if (file.isFile() && !file.delete()) { throw new IOException("Failed to delete " + file.getCanonicalFile()); } PrintWriter writer = new PrintWriter(file); try { for (Iterator<String> ii = theContents.iterator(); ii.hasNext();) writer.println(ii.next()); } finally { writer.close(); } } }
String configChangeEventTopic = ConfigUtils.getPropOrEnv("CONFIGNOTIFICATIONTOPIC"); if (configChangeEventTopic == null || configChangeEventTopic.equals("")) configChangeEventTopic = s_topic;
public void setSource(Object source) throws ConfigException { try { Master m; if (source instanceof InputStream) m = new Master((InputStream) source); else if (source instanceof String) m = new Master(ConfigUtils.getInitialPropertyExpanded((String) source)); else throw new ConfigException("not InputStream or String file name: " + source); initialize(m); } catch (IOException e) { throw new ConfigException("cannot initialize dns with " + source, e); } LOGGER.info( "Initializing transient DNS source from " + source); m_source = source; }
String zonefileloc = ConfigUtils.getPropOrEnv("MONGOLOCATIONZONEFILE"); //KEEPME
protected Context getContext() { if (getWebAppcontextPath() != null) { m_context = new WebAppContext( null,ConfigUtils .getInitialPropertyExpanded(getContextPath())); m_context.setResourceBase(getResourceBase()); getContexts().addHandler(m_context); getServer().setHandler(getContexts()); } else if (m_context == null) { getServer().setHandler(getContexts()); m_context = new Context(m_contexts, getContextPath(), Context.SESSIONS); if (getResourceBase() != null) { m_context.setResourceBase(getResourceBase()); } } return m_context; }