List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:org.pepstock.jem.commands.util.HttpUtil.java
/** * Performs the login using user and password * //w w w .ja v a 2 s.c om * @param user user to authenticate * @param password password to authenticate * @param url http URL to call * @param httpclient hhtp client already created * @throws ClientProtocolException if any errors occurs on calling the * servlet * @throws IOException if I/O error occurs */ private static void login(String user, String password, String url, HttpClient httpclient) throws ClientProtocolException, IOException { // account info in a properties Properties properties = new Properties(); properties.setProperty(USER_PROPERTY_KEY, user); properties.setProperty(PASSWORD_PROPERTY_KEY, password); StringWriter writer = new StringWriter(); properties.store(writer, "Account info"); // login // concats URL with query string String completeUrl = url + HttpUtil.LOGIN_QUERY_STRING; StringEntity entity = new StringEntity(writer.toString(), ContentType.create("text/plain", "UTF-8")); // prepares POST request and basic response handler HttpPost httppost = new HttpPost(completeUrl); httppost.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); // executes and no parsing // result must be only a string httpclient.execute(httppost, responseHandler); }
From source file:com.linkedin.drelephant.util.InfoExtractor.java
/** * Retrieve the spark properties from SPARK_EXTRA_JAVA_OPTIONS *//from w ww.ja va 2 s .co m * @param appData the Spark Application Data * @return The retrieved Spark properties */ public static Properties retrieveSparkProperties(SparkApplicationData appData) { Option<String> prop = appData.appConfigurationProperties().get(SPARK_EXTRA_JAVA_OPTIONS); Properties properties = new Properties(); if (prop.isDefined()) { try { Map<String, String> javaOptions = Utils.parseJavaOptions(prop.get()); for (String key : javaOptions.keySet()) { properties.setProperty(key, unescapeString(javaOptions.get(key))); } } catch (IllegalArgumentException e) { logger.error("Encountered error while parsing java options into urls: " + e.getMessage()); } } else { logger.error("Unable to retrieve the scheduler info for application [" + appData.appId() + "]. It does not contain [" + SPARK_EXTRA_JAVA_OPTIONS + "] property in its spark properties."); } return properties; }
From source file:com.izforge.izpack.util.LogUtils.java
private static void mergeLoggingConfiguration(Properties to, Properties from) { for (String fromName : from.stringPropertyNames()) { String fromValue = from.getProperty(fromName); if (fromName.matches("\\.?handlers") && to.containsKey(fromName)) { String oldValue = to.getProperty(fromName); if (!fromValue.equals(oldValue)) { to.setProperty(fromName, oldValue + ", " + fromValue); }//ww w . j av a 2 s .co m continue; } if (!to.containsKey(fromName)) { to.setProperty(fromName, fromValue); } } }
From source file:com.hmiard.blackwater.projects.Builder.java
/** * Building a new project.//from w w w . java 2s .c o m * * @param projectName String * @param serverNames ArrayList * @param location String */ public static void buildNewProject(String projectName, ArrayList<String> serverNames, String location, ConsoleEmulator consoleListener) { try { consoleListener.clean(); consoleListener.push("Project creation started...\n\n"); projectName = projectName.substring(0, 1).toUpperCase() + projectName.substring(1); String projectUrl = location + "\\" + projectName; buildFolder(projectUrl); buildFolder(projectUrl + "\\bin"); buildFolder(projectUrl + "\\src"); buildFolder(projectUrl + "\\.blackwater"); ArrayList<String> realServerNames = new ArrayList<>(); for (String name : serverNames) realServerNames.add(name.replace("!", "")); // Creating the configuration Properties configuration = new Properties(); File tokens = new File(projectUrl + "\\.blackwater\\tokens.properties"); configuration.setProperty("PATH", projectUrl); configuration.setProperty("NAME", projectName); configuration.setProperty("SERVERS", Parser.parseArrayToStringList(",", realServerNames)); configuration.setProperty("LAST_UPDATE", new Date().toString()); configuration.store(new FileOutputStream(tokens), "Blackwater build version : " + Start.VERSION); consoleListener.push("Tokens generated.\n"); // Creating composer.json... JSONObject composerJSON = new JSONObject(); JSONObject autoload = new JSONObject(); JSONObject psr0 = new JSONObject(); JSONObject require = new JSONObject(); autoload.put("psr-0", psr0); composerJSON.put("autoload", autoload); composerJSON.put("require", require); require.put("blackwater/blackwaterp", Start.blackwaterpVersion); File composer = new File(projectUrl + "\\composer.json"); if (!composer.createNewFile()) { consoleListener.push("\nWeird composer stuff happened... Aborting.\n"); return; } BufferedWriter cw = new BufferedWriter(new FileWriter(composer.getAbsoluteFile())); String content = composerJSON.toString(4).replaceAll("\\\\", ""); cw.write(content); cw.close(); consoleListener.push("File created : composer.json\n"); // Creating the servers... consoleListener.push("Server creation started...\n"); for (String name : serverNames) if (name.charAt(0) == '!') appendServer(projectUrl, name.replace("!", ""), consoleListener, false); else appendServer(projectUrl, name, consoleListener, true); // Copying composer.phar consoleListener.push("Installing local composer wrapper...\n"); copyFile(new File("resources/packages/composer.phar"), new File(composer.getParent() + "\\bin\\composer.phar")); // Building... consoleListener.push("Building dependencies...\n"); new Thread(new ChildProcess("php bin/composer.phar install", composer.getParentFile(), consoleListener, () -> { NewProjectAppScreenPresenter presenter = (NewProjectAppScreenPresenter) consoleListener.app; presenter.projectCreatedCallback(projectUrl, consoleListener); })).start(); } catch (JSONException | IOException e) { e.printStackTrace(); } }
From source file:it.infn.ct.InstantiateVM.java
public static String instantiateVM(JSONObject egiInput) { OCCI_ENDPOINT_HOST = (String) egiInput.get("endpoint"); RES_TPL = (String) egiInput.get("resourceTpl"); OS_TPL = (String) egiInput.get("osTpl"); PUBLIC_KEY_PATH = (String) egiInput.get("publicKey"); CONTEXT_PATH = (String) egiInput.get("contextualisation"); AUTH = (String) egiInput.get("auth"); TRUSTED_CERT_REPOSITORY_PATH = (String) egiInput.get("trustedCertificatesPath"); PROXY_PATH = (String) egiInput.get("proxyPath"); MIXIN = Arrays.asList(RES_TPL, OS_TPL); CONTEXT = Arrays.asList("public_key=" + PUBLIC_KEY_PATH, "user_data=" + CONTEXT_PATH); Boolean result = false;//from w ww.j ava2 s .c om String networkInterfaceLocation = ""; String networkInterfaceLocation_stripped = ""; Resource vm_resource = null; URI uri_location = null; if (verbose) { System.out.println(); if (ACTION != null && !ACTION.isEmpty()) System.out.println("[ACTION] = " + ACTION); else System.out.println("[ACTION] = Get dump model"); System.out.println("AUTH = " + AUTH); if (OCCI_ENDPOINT_HOST != null && !OCCI_ENDPOINT_HOST.isEmpty()) System.out.println("OCCI_ENDPOINT_HOST = " + OCCI_ENDPOINT_HOST); if (RESOURCE != null && !RESOURCE.isEmpty()) System.out.println("RESOURCE = " + RESOURCE); if (MIXIN != null && !MIXIN.isEmpty()) System.out.println("MIXIN = " + MIXIN); if (TRUSTED_CERT_REPOSITORY_PATH != null && !TRUSTED_CERT_REPOSITORY_PATH.isEmpty()) System.out.println("TRUSTED_CERT_REPOSITORY_PATH = " + TRUSTED_CERT_REPOSITORY_PATH); if (PROXY_PATH != null && !PROXY_PATH.isEmpty()) System.out.println("PROXY_PATH = " + PROXY_PATH); if (CONTEXT != null && !CONTEXT.isEmpty()) System.out.println("CONTEXT = " + CONTEXT); if (OCCI_PUBLICKEY_NAME != null && !OCCI_PUBLICKEY_NAME.isEmpty()) System.out.println("OCCI_PUBLICKEY_NAME = " + OCCI_PUBLICKEY_NAME); if (ATTRIBUTES != null && !ATTRIBUTES.isEmpty()) System.out.println("ATTRIBUTES = " + ATTRIBUTES); if (verbose) System.out.println("Verbose = True "); else System.out.println("Verbose = False "); } Properties properties = new Properties(); if (ACTION != null && !ACTION.isEmpty()) properties.setProperty("ACTION", ACTION); if (OCCI_ENDPOINT_HOST != null && !OCCI_ENDPOINT_HOST.isEmpty()) properties.setProperty("OCCI_ENDPOINT_HOST", OCCI_ENDPOINT_HOST); if (RESOURCE != null && !RESOURCE.isEmpty()) for (int i = 0; i < RESOURCE.size(); i++) { if ((!RESOURCE.get(i).equals("compute")) && (!RESOURCE.get(i).equals("storage")) && (!RESOURCE.get(i).equals("network")) && (!RESOURCE.get(i).equals("os_tpl")) && (!RESOURCE.get(i).equals("resource_tpl"))) properties.setProperty("OCCI_VM_RESOURCE_ID", RESOURCE.get(i)); else { properties.setProperty("RESOURCE", RESOURCE.get(i)); properties.setProperty("OCCI_VM_RESOURCE_ID", "empty"); } } if (MIXIN != null && !MIXIN.isEmpty()) for (int i = 0; i < MIXIN.size(); i++) { if (MIXIN.get(i).contains("template") || MIXIN.get(i).contains("os_tpl")) properties.setProperty("OCCI_OS_TPL", MIXIN.get(i)); if (MIXIN.get(i).contains("resource_tpl")) properties.setProperty("OCCI_RESOURCE_TPL", MIXIN.get(i)); } if (ATTRIBUTES != null && !ATTRIBUTES.isEmpty()) for (int i = 0; i < ATTRIBUTES.size(); i++) { if (ATTRIBUTES.get(i).contains("occi.core.title")) { String _OCCI_CORE_TITLE = ATTRIBUTES.get(i).substring(ATTRIBUTES.get(i).lastIndexOf("=") + 1); properties.setProperty("OCCI_CORE_TITLE", _OCCI_CORE_TITLE); } if (ATTRIBUTES.get(i).contains("occi.storage.size")) { String _OCCI_STORAGE_SIZE = ATTRIBUTES.get(i).substring(ATTRIBUTES.get(i).lastIndexOf("=") + 1); properties.setProperty("OCCI_STORAGE_SIZE", _OCCI_STORAGE_SIZE); } } properties.setProperty("TRUSTED_CERT_REPOSITORY_PATH", TRUSTED_CERT_REPOSITORY_PATH); properties.setProperty("PROXY_PATH", PROXY_PATH); if (CONTEXT != null && !CONTEXT.isEmpty()) { for (int i = 0; i < CONTEXT.size(); i++) { if (CONTEXT.get(i).contains("public_key")) properties.setProperty("PUBLIC_KEY_FILE", CONTEXT.get(i)); if (CONTEXT.get(i).contains("user_data")) properties.setProperty("USER_DATA", CONTEXT.get(i)); } } if (OCCI_PUBLICKEY_NAME != null && !OCCI_PUBLICKEY_NAME.isEmpty()) properties.setProperty("OCCI_PUBLICKEY_NAME", OCCI_PUBLICKEY_NAME); properties.setProperty("OCCI_AUTH", AUTH); try { HTTPAuthentication authentication = new VOMSAuthentication(PROXY_PATH); authentication.setCAPath(TRUSTED_CERT_REPOSITORY_PATH); Client client = new HTTPClient(URI.create(OCCI_ENDPOINT_HOST), authentication, MediaType.TEXT_PLAIN, false); //Connect client client.connect(); Model model = client.getModel(); EntityBuilder eb = new EntityBuilder(model); instantiatedVmId = doCreate(properties, eb, model, client, egiInput); System.out.println("VM ID: " + instantiatedVmId); return instantiatedVmId; } catch (CommunicationException ex) { throw new RuntimeException(ex); } }
From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java
protected static Properties createProperties() { Properties p = new Properties(); p.setProperty(JDBC_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver"); p.setProperty(JDBC_AUTO_COMMIT, "true"); p.setProperty(JDBC_DEBUG, "true"); p.setProperty(JDBC_ALWAYS_VERIFY, "true"); p.setProperty(JDBC_TEST_STATEMENT, "VALUES CURRENT_TIMESTAMP"); p.setProperty(JDBC_URL_ROOT + ".1", "jdbc:derby:memory:jdbc-failover-ds-1;create=true"); p.setProperty(JDBC_URL_ROOT + ".2", "jdbc:derby:memory:jdbc-failover-ds-2;create=true"); return p;//from ww w. java 2 s .c o m }
From source file:com.mozilla.fhr.consumer.FHRConsumer.java
/** * This method overrides KafkaConsumer but we can't annotate due to the way Java * determines types on static methods.//w w w. j av a 2s.c om */ public static KafkaConsumer fromOptions(CommandLine cmd) { Properties props = new Properties(); String propsFilePath = cmd.getOptionValue("properties"); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(propsFilePath))); props.load(reader); props.setProperty("groupid", cmd.getOptionValue("groupid")); } catch (FileNotFoundException e) { LOG.error("Could not find properties file", e); } catch (IOException e) { LOG.error("Error reading properties file", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { LOG.error("Error closing properties file", e); } } } int numThreads = props.containsKey("consumer.threads") ? Integer.parseInt(props.getProperty("consumer.threads")) : DEFAULT_NUM_THREADS; // if numthreads specified on command-line then override if (cmd.hasOption("numthreads")) { numThreads = Integer.parseInt(cmd.getOptionValue("numthreads")); } return new FHRConsumer(cmd.getOptionValue("topic"), props, numThreads); }
From source file:cpcc.vvrte.services.VirtualVehicleMigratorImpl.java
/** * @param virtualVehicle the virtual vehicle. * @param lastChunk true if this property object is going to be transferred in the last data chunk. * @return the virtual vehicle properties. *///from w ww.java 2 s. c o m private static Properties fillVirtualVehicleProps(VirtualVehicle virtualVehicle, boolean lastChunk) { Properties props = new Properties(); props.setProperty("name", virtualVehicle.getName()); props.setProperty("uuid", virtualVehicle.getUuid()); PropertyUtils.setProperty(props, "api.version", virtualVehicle.getApiVersion()); PropertyUtils.setProperty(props, "state", virtualVehicle.getPreMigrationState()); PropertyUtils.setProperty(props, "stateInfo", virtualVehicle.getStateInfo()); PropertyUtils.setProperty(props, "chunk", virtualVehicle.getChunkNumber()); if (virtualVehicle.getMigrationSource() != null) { PropertyUtils.setProperty(props, "migration.source", virtualVehicle.getMigrationSource().getName()); } if (virtualVehicle.getStartTime() != null) { PropertyUtils.setProperty(props, "start.time", virtualVehicle.getStartTime().getTime()); } if (virtualVehicle.getEndTime() != null) { PropertyUtils.setProperty(props, "end.time", virtualVehicle.getEndTime().getTime()); } if (lastChunk) { PropertyUtils.setProperty(props, "last.chunk", Boolean.TRUE); } return props; }
From source file:com.heliosapm.streams.collector.ds.pool.PoolConfig.java
/** * Undeploys the pool defined in the passed file * @param file The pool configuration file *///from w w w . j a va 2 s .com public static void undeployPool(final File file) { if (file == null) throw new IllegalArgumentException("The passed file was null"); if (!file.canRead()) throw new IllegalArgumentException("Cannot read file [" + file + "]"); if (pools.remove(file) != null) { final Properties p = URLHelper.readProperties(URLHelper.toURL(file)); final String poolName = p.getProperty(NAME.name().toLowerCase()); if (poolName == null) { p.setProperty("name", StringHelper.splitString(file.getName(), '.', true)[0]); } undeployPool(p); } }
From source file:com.mozilla.bagheera.consumer.KafkaConsumer.java
/** * Create a KafkaConsumer from the given command-line options * @param cmd// w w w . jav a2 s. c o m * @return */ public static KafkaConsumer fromOptions(CommandLine cmd) { Properties props = new Properties(); String propsFilePath = cmd.getOptionValue("properties"); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(propsFilePath))); props.load(reader); props.setProperty("groupid", cmd.getOptionValue("groupid")); } catch (FileNotFoundException e) { LOG.error("Could not find properties file", e); } catch (IOException e) { LOG.error("Error reading properties file", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { LOG.error("Error closing properties file", e); } } } int numThreads = props.containsKey("consumer.threads") ? Integer.parseInt(props.getProperty("consumer.threads")) : DEFAULT_NUM_THREADS; // if numthreads specified on command-line then override if (cmd.hasOption("numthreads")) { numThreads = Integer.parseInt(cmd.getOptionValue("numthreads")); } // construct consumer KafkaConsumer consumer = new KafkaConsumer(cmd.getOptionValue("topic"), props, numThreads); // setup validation pipeline if we need to if (cmd.hasOption("validatejson")) { ValidationPipeline vp = new ValidationPipeline(); vp.addFirst(new JsonValidator()); consumer.setValidationPipeline(vp); } return consumer; }