List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
private Properties readProperties(InputStream is) throws IOException { try {//from w w w . ja va 2s . c o m // Properies are defined as name=value pairs where value may be over several lines Properties properties = new Properties(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; String lastName = null; while ((line = br.readLine()) != null) { line = line.trim(); int equalsPos = line.indexOf("="); if ((equalsPos > 0) && ((equalsPos + 1) < line.length())) { String name = line.substring(0, equalsPos); String value = line.substring(equalsPos + 1); properties.setProperty(name, value); lastName = name; } else if (lastName != null) { properties.setProperty(lastName, String.valueOf(properties.get(lastName)) + line); } } return properties; } finally { IOUtils.closeQuietly(is); } }
From source file:pl.project13.maven.git.GitCommitIdMojo.java
private void appendPropertiesToReactorProjects(@NotNull Properties properties, @NotNull String trimmedPrefixWithDot) { for (MavenProject mavenProject : reactorProjects) { Properties mavenProperties = mavenProject.getProperties(); // TODO check message log.info("{}] project {}", mavenProject.getName(), mavenProject.getName()); for (Object key : properties.keySet()) { if (key.toString().startsWith(trimmedPrefixWithDot)) { mavenProperties.put(key, properties.get(key)); }//from ww w. j a v a 2 s . c o m } } }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
protected HttpClient configureClient(Properties props) throws SQLException { // Try to get credentials to use String user = props.getProperty(PARAM_USERNAME, null); if (user != null && user.trim().isEmpty()) user = null;//from w ww . j a v a2 s .c o m String password = props.getProperty(PARAM_PASSWORD, null); if (password != null && password.trim().isEmpty()) password = null; // If credentials then we use them if (user != null && password != null) { BasicCredentialsProvider credsProv = new BasicCredentialsProvider(); credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); return HttpClients.custom().setDefaultCredentialsProvider(credsProv).build(); } // else use a supplied or default client Object client = props.get(PARAM_CLIENT); if (client != null) { if (!(client instanceof HttpClient)) throw new SQLException("The " + PARAM_CLIENT + " parameter is specified but the value is not an object implementing the required HttpClient interface"); return (HttpClient) client; } return null; }
From source file:com.impetus.client.mongodb.MongoDBClientFactory.java
/** * Gets the connection.//from www .ja v a 2s . c om * * @return the connection */ private DB getConnection() { PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = puMetadata.getProperties(); String contactNode = null; String defaultPort = null; String keyspace = null; String poolSize = null; if (externalProperties != null) { contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES); defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT); keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE); poolSize = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); } if (contactNode == null) { contactNode = (String) props.get(PersistenceProperties.KUNDERA_NODES); } if (defaultPort == null) { defaultPort = (String) props.get(PersistenceProperties.KUNDERA_PORT); } if (keyspace == null) { keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE); } if (poolSize == null) { poolSize = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); } onValidation(contactNode, defaultPort); List<ServerAddress> addrs = new ArrayList<ServerAddress>(); MongoClient mongo = null; try { mongo = onSetMongoServerProperties(contactNode, defaultPort, poolSize, addrs); logger.info("Connected to mongodb at " + contactNode + " on port " + defaultPort); } catch (NumberFormatException e) { logger.error("Invalid format for MONGODB port, Unale to connect!" + "; Caused by:" + e.getMessage()); throw new ClientLoaderException(e); } catch (UnknownHostException e) { logger.error("Unable to connect to MONGODB at host " + contactNode + "; Caused by:" + e.getMessage()); throw new ClientLoaderException(e); } catch (MongoException e) { logger.error("Unable to connect to MONGODB; Caused by:" + e.getMessage()); throw new ClientLoaderException(e); } DB mongoDB = mongo.getDB(keyspace); try { MongoDBUtils.authenticate(props, externalProperties, mongoDB); } catch (ClientLoaderException e) { logger.error(e.getMessage()); throw e; } logger.info("Connected to mongodb at " + contactNode + " on port " + defaultPort); return mongoDB; }
From source file:com.splicemachine.derby.utils.SpliceAdmin.java
/** * Get the values of all properties for the current connection. * * @param rs array of result set objects that contains all of the defined properties * for the JVM, service, database, and app. * @throws SQLException Standard exception policy. **//* w w w .jav a 2 s .c om*/ public static void SYSCS_GET_ALL_PROPERTIES(ResultSet[] rs) throws SQLException { try { LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); TransactionController tc = lcc.getTransactionExecute(); // Fetch all the properties. Properties jvmProps = addTypeToProperties(System.getProperties(), "JVM", true); Properties dbProps = addTypeToProperties(tc.getProperties()); // Includes both database and service properties. ModuleFactory monitor = Monitor.getMonitorLite(); Properties appProps = addTypeToProperties(monitor.getApplicationProperties(), "APP", false); // Merge the properties using the correct search order. // SEARCH ORDER: JVM, Service, Database, App appProps.putAll(dbProps); // dbProps already has been overwritten with service properties. appProps.putAll(jvmProps); ArrayList<ExecRow> rows = new ArrayList<>(appProps.size()); // Describe the format of the input rows (ExecRow). // // Columns of "virtual" row: // KEY VARCHAR // VALUE VARCHAR // TYPE VARCHAR (JVM, SERVICE, DATABASE, APP) DataValueDescriptor[] dvds = new DataValueDescriptor[] { new SQLVarchar(), new SQLVarchar(), new SQLVarchar() }; int numCols = dvds.length; ExecRow dataTemplate = new ValueRow(numCols); dataTemplate.setRowArray(dvds); // Transform the properties into rows. Sort the properties by key first. ArrayList<String> keyList = new ArrayList<>(); for (Object o : appProps.keySet()) { if (o instanceof String) keyList.add((String) o); } Collections.sort(keyList); for (String key : keyList) { String[] typedValue = (String[]) appProps.get(key); dvds[0].setValue(key); dvds[1].setValue(typedValue[0]); dvds[2].setValue(typedValue[1]); rows.add(dataTemplate.getClone()); } // Describe the format of the output rows (ResultSet). ResultColumnDescriptor[] columnInfo = new ResultColumnDescriptor[numCols]; columnInfo[0] = new GenericColumnDescriptor("KEY", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 50)); columnInfo[1] = new GenericColumnDescriptor("VALUE", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 40)); columnInfo[2] = new GenericColumnDescriptor("TYPE", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 10)); EmbedConnection defaultConn = (EmbedConnection) getDefaultConn(); Activation lastActivation = defaultConn.getLanguageConnection().getLastActivation(); IteratorNoPutResultSet resultsToWrap = new IteratorNoPutResultSet(rows, columnInfo, lastActivation); resultsToWrap.openCore(); EmbedResultSet ers = new EmbedResultSet40(defaultConn, resultsToWrap, false, null, true); rs[0] = ers; } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } }
From source file:io.warp10.script.WarpScriptLib.java
public static void registerExtensions() { Properties props = WarpConfig.getProperties(); if (null == props) { return;//from w w w . java2 s . c om } // // Extract the list of extensions // Set<String> ext = new LinkedHashSet<String>(); if (props.containsKey(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS)) { String[] extensions = props.getProperty(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS).split(","); for (String extension : extensions) { ext.add(extension.trim()); } } for (Object key : props.keySet()) { if (!key.toString().startsWith(Configuration.CONFIG_WARPSCRIPT_EXTENSION_PREFIX)) { continue; } ext.add(props.get(key).toString().trim()); } // Sort the extensions List<String> sortedext = new ArrayList<String>(ext); sortedext.sort(null); boolean failedExt = false; // // Determine the possible jar from which WarpScriptLib was loaded // String wsljar = null; URL wslurl = WarpScriptLib.class .getResource('/' + WarpScriptLib.class.getCanonicalName().replace('.', '/') + ".class"); if (null != wslurl && "jar".equals(wslurl.getProtocol())) { wsljar = wslurl.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); } for (String extension : sortedext) { // If the extension name contains '#', remove everything up to the last '#', this was used as a sorting prefix if (extension.contains("#")) { extension = extension.replaceAll("^.*#", ""); } try { // // Locate the class using the current class loader // URL url = WarpScriptLib.class.getResource('/' + extension.replace('.', '/') + ".class"); if (null == url) { LOG.error("Unable to load extension '" + extension + "', make sure it is in the class path."); failedExt = true; continue; } Class cls = null; // // If the class was located in a jar, load it using a specific class loader // so we can have fat jars with specific deps, unless the jar is the same as // the one from which WarpScriptLib was loaded, in which case we use the same // class loader. // if ("jar".equals(url.getProtocol())) { String jarfile = url.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); ClassLoader cl = WarpScriptLib.class.getClassLoader(); // If the jar differs from that from which WarpScriptLib was loaded, create a dedicated class loader if (!jarfile.equals(wsljar)) { cl = new WarpClassLoader(jarfile, WarpScriptLib.class.getClassLoader()); } cls = Class.forName(extension, true, cl); } else { cls = Class.forName(extension, true, WarpScriptLib.class.getClassLoader()); } //Class cls = Class.forName(extension); WarpScriptExtension wse = (WarpScriptExtension) cls.newInstance(); wse.register(); System.out.println("LOADED extension '" + extension + "'"); } catch (Exception e) { throw new RuntimeException(e); } } if (failedExt) { throw new RuntimeException("Some WarpScript extensions could not be loaded, aborting."); } }
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.java
/** * Builds the white list collection.//from w w w .jav a 2 s.c om * * @param whiteList * the white list * @return the collection */ private Collection<InetSocketAddress> buildWhiteListCollection(String whiteList) { String[] list = whiteList.split(Constants.COMMA); Collection<InetSocketAddress> whiteListCollection = new ArrayList<InetSocketAddress>(); PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = persistenceUnitMetadata.getProperties(); int defaultPort = 9042; if (externalProperties != null && externalProperties.get(PersistenceProperties.KUNDERA_PORT) != null) { try { defaultPort = Integer.parseInt((String) externalProperties.get(PersistenceProperties.KUNDERA_PORT)); } catch (NumberFormatException e) { logger.error("Port in persistence.xml should be integer"); } } else { try { defaultPort = Integer.parseInt((String) props.get(PersistenceProperties.KUNDERA_PORT)); } catch (NumberFormatException e) { logger.error("Port in persistence.xml should be integer"); } } for (String node : list) { if (node.indexOf(Constants.COLON) > 0) { String[] parts = node.split(Constants.COLON); whiteListCollection.add(new InetSocketAddress(parts[0], Integer.parseInt(parts[1]))); } else { whiteListCollection.add(new InetSocketAddress(node, defaultPort)); } } return whiteListCollection; }
From source file:com.impetus.client.couchdb.CouchDBClientFactory.java
@Override protected Object createPoolOrConnection() { PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata(getPersistenceUnit()); Properties props = puMetadata.getProperties(); String contactNode = null;// w w w .java 2s. c o m String defaultPort = null; String keyspace = null; String poolSize = null; String userName = null; String password = null; String maxConnections = null; if (externalProperties != null) { contactNode = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES); defaultPort = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT); keyspace = (String) externalProperties.get(PersistenceProperties.KUNDERA_KEYSPACE); poolSize = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); userName = (String) externalProperties.get(PersistenceProperties.KUNDERA_USERNAME); password = (String) externalProperties.get(PersistenceProperties.KUNDERA_PASSWORD); maxConnections = (String) externalProperties.get(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_TOTAL); } if (contactNode == null) { contactNode = (String) props.get(PersistenceProperties.KUNDERA_NODES); } if (defaultPort == null) { defaultPort = (String) props.get(PersistenceProperties.KUNDERA_PORT); } if (keyspace == null) { keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE); } if (poolSize == null) { poolSize = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); } if (userName == null) { userName = props.getProperty(PersistenceProperties.KUNDERA_USERNAME); password = props.getProperty(PersistenceProperties.KUNDERA_PASSWORD); } onValidation(contactNode, defaultPort); try { SchemeSocketFactory ssf = null; ssf = PlainSocketFactory.getSocketFactory(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme(CouchDBConstants.PROTOCOL, Integer.parseInt(defaultPort), ssf)); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry); httpClient = new DefaultHttpClient(ccm); httpHost = new HttpHost(contactNode, Integer.parseInt(defaultPort), CouchDBConstants.PROTOCOL); httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); // httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, // props.getSocketTimeout()); // httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, // props.getConnectionTimeout()); if (!StringUtils.isBlank(maxConnections)) { ccm.setMaxTotal(Integer.parseInt(maxConnections)); ccm.setDefaultMaxPerRoute(Integer.parseInt(maxConnections)); } // basic authentication if (userName != null && password != null) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials( new AuthScope(contactNode, Integer.parseInt(defaultPort)), new UsernamePasswordCredentials(userName, password)); } // request interceptor ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws IOException { if (logger.isInfoEnabled()) { RequestLine requestLine = request.getRequestLine(); logger.info( ">> " + requestLine.getMethod() + " " + URI.create(requestLine.getUri()).getPath()); } } }); // response interceptor ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws IOException { if (logger.isInfoEnabled()) logger.info("<< Status: " + response.getStatusLine().getStatusCode()); } }); } catch (Exception e) { logger.error("Error Creating HTTP client, caoused by {}. ", e); throw new IllegalStateException(e); } return httpClient; }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorFactoryIcfImpl.java
/** * Scan class path for connector bundles * /*w w w .j a va 2s . c om*/ * @return Set of all bundle URL */ private Set<URL> scanClassPathForBundles() { Set<URL> bundle = new HashSet<URL>(); // scan class path for bundles Enumeration<URL> en = null; try { // Search all jars in classpath en = ConnectorFactoryIcfImpl.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); } catch (IOException ex) { LOGGER.debug("Error during reding content from class path"); } // Find which one is ICF connector while (en.hasMoreElements()) { URL u = en.nextElement(); Properties prop = new Properties(); LOGGER.trace("Scan classloader resource: " + u.toString()); try { // read content of META-INF/MANIFEST.MF InputStream is = u.openStream(); // skip if unreadable if (is == null) { continue; } // Convert to properties prop.load(is); } catch (IOException ex) { LOGGER.trace("Unable load: " + u + " [" + ex.getMessage() + "]"); } if (null != prop.get("ConnectorBundle-Name")) { LOGGER.info("Discovered ICF bundle on CLASSPATH: " + prop.get("ConnectorBundle-Name") + " version: " + prop.get("ConnectorBundle-Version")); // hack to split MANIFEST from name try { URL tmp = new URL(toUrl(u.getPath().split("!")[0])); if (isThisBundleCompatible(tmp)) { bundle.add(tmp); } else { LOGGER.warn("Skip loading ICF bundle {} due error occured", tmp); } } catch (MalformedURLException e) { LOGGER.error("This never happend we hope. URL:" + u.getPath(), e); throw new SystemException(e); } } } return bundle; }
From source file:cn.calm.osgi.conter.FelixOsgiHost.java
protected void addExportedPackages(Properties strutsConfigProps, Properties configProps) { String[] rootPackages = StringUtils.split(strutsConfigProps.getProperty("scanning.package.includes"), ","); List<String> exportedPackages = new ArrayList<String>(); // build a list of subpackages StringBuilder strB = new StringBuilder(); // org.osgi.framework;version="[1.4,2)" for (String rootPackage : rootPackages) { String sp[] = StringUtils.split(rootPackage, ";"); strB.delete(0, strB.length());//from ww w. j a v a 2 s . com strB.append(sp[0]); strB.append(";version=\""); try { strB.append(sp[1]); } catch (Exception e) { strB.append("0.0.0"); } strB.append("\""); exportedPackages.add(strB.toString()); } // // // make a string with the exported packages and add it to the system // // properties if (!exportedPackages.isEmpty()) { String systemPackages = (String) configProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES); systemPackages = StringUtils.removeEnd(systemPackages, ",") + "," + StringUtils.join(exportedPackages, ","); configProps.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); } System.out.println(exportedPackages); }