List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:com.jaeksoft.searchlib.web.AbstractServlet.java
protected static URI buildUri(URI uri, String additionalPath, String indexName, String login, String apiKey, String additionnalQuery) throws URISyntaxException { StringBuilder path = new StringBuilder(uri.getPath()); if (additionalPath != null) path.append(additionalPath);/*from ww w .ja v a 2 s.c om*/ StringBuilder query = new StringBuilder(); if (indexName != null) { query.append("index="); query.append(indexName); } if (login != null) { query.append("&login="); query.append(login); } if (apiKey != null) { query.append("&key="); query.append(apiKey); } if (additionnalQuery != null) { if (query.length() > 0) query.append("&"); query.append(additionnalQuery); } return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path.toString(), query.toString(), uri.getFragment()); }
From source file:com.nebhale.cyclinglibrary.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() throws URISyntaxException { String dbUrlProperty = System.getenv(DB_URL_PROPERTY_NAME); Assert.hasText(dbUrlProperty,//from w w w.j a v a2 s .c o m String.format("The enviroment variable '%s' must be specified", DB_URL_PROPERTY_NAME)); URI dbUri = new URI(dbUrlProperty); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); dataSource.setUsername(username); dataSource.setPassword(password); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.migrate(); return dataSource; }
From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactory.java
private RestTemplate restTemplate(String serviceUrl) { RestTemplate restTemplate = new RestTemplate(); try {/*w w w. ja v a 2s .c om*/ URI serviceURI = new URI(serviceUrl); if (serviceURI.getUserInfo() != null) { String[] credentials = serviceURI.getUserInfo().split(":"); if (credentials.length == 2) { restTemplate.getInterceptors() .add(new BasicAuthorizationInterceptor(credentials[0], credentials[1])); } } } catch (URISyntaxException ignore) { } restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter()); return restTemplate; }
From source file:pgsql.connection.PooledConnectionFactory.java
private void initializeConnectionPool(BasicDataSource connectionPool, URI databaseUri) { final String dbUrl = "jdbc:postgresql://" + databaseUri.getHost() + databaseUri.getPath(); if (databaseUri.getUserInfo() != null) { connectionPool.setUsername(databaseUri.getUserInfo().split(":")[0]); connectionPool.setPassword(databaseUri.getUserInfo().split(":")[1]); }/*from ww w . jav a 2 s. co m*/ connectionPool.setDriverClassName("org.postgresql.Driver"); connectionPool.setUrl(dbUrl); connectionPool.setInitialSize(1); }
From source file:org.mulgara.scon.Connection.java
/** * Encodes a URI if it looks like it needs it. * @param u The URI to encode, if needed. * @return a minimally encoded URI./*from w ww . ja v a2 s.c om*/ */ private static final String enc(URI u) { try { // if there is no query, then just return the unencoded URI String query = u.getRawQuery(); if (query == null) return u.toString(); // encode the query, and add it to the end of the URI String encQuery = encode(query); String encU = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), encQuery, u.getFragment()).toString(); // if the partial encoding works, then return it if (decode(encU).equals(u.toString())) return encU; // nothing else worked, so encode it fully return encode(u.toString()); } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to encode a URI", e); } }
From source file:com.thoughtworks.go.util.command.UrlArgument.java
@Override public String forDisplay() { try {// www .ja va 2 s .c o m URI uri = new URI(sanitizeUrl()); if (uri.getUserInfo() != null) { uri = new URI(uri.getScheme(), clean(uri.getScheme(), uri.getUserInfo()), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } return uri.toString(); } catch (URISyntaxException e) { return url; } }
From source file:com.anrisoftware.simplerest.owncloud.DefaultOwncloudAccount.java
/** * Creates an the Owncloud account.//ww w .ja va 2s . com * * @param uri * the {@link URI} containing the user name, password and base * URI as {@code https://user:password@host/path} */ @AssistedInject public DefaultOwncloudAccount(@Assisted URI uri) { String[] split = split(uri.getUserInfo(), ":"); setUser(split[0]); setPassword(split[1]); setBaseUri(uri); }
From source file:org.apache.camel.component.xmpp.XmppComponent.java
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { if (endpointCache.containsKey(uri)) { if (LOG.isDebugEnabled()) { LOG.debug("Using cached endpoint for URI " + uri); }//from w w w . java 2s . co m return endpointCache.get(uri); } if (LOG.isDebugEnabled()) { LOG.debug("Creating new endpoint for URI " + uri); } XmppEndpoint endpoint = new XmppEndpoint(uri, this); URI u = new URI(uri); endpoint.setHost(u.getHost()); endpoint.setPort(u.getPort()); if (u.getUserInfo() != null) { endpoint.setUser(u.getUserInfo()); } String remainingPath = u.getPath(); if (remainingPath != null) { if (remainingPath.startsWith("/")) { remainingPath = remainingPath.substring(1); } // assume its a participant if (remainingPath.length() > 0) { endpoint.setParticipant(remainingPath); } } endpointCache.put(uri, endpoint); return endpoint; }
From source file:com.alehuo.wepas2016projekti.configuration.ProductionConfiguration.java
/** * Heroku -palvelussa kytetn PostgreSQL -tietokantaa tiedon * tallentamiseen. Tm metodi hakee herokusta tietokantayhteyden * mahdollistavat ympristmuuttujat./* w w w . j a v a 2 s.c om*/ * * @return @throws URISyntaxException */ @Bean public BasicDataSource dataSource() throws URISyntaxException { URI dbUri = new URI(System.getenv("DATABASE_URL")); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setUrl(dbUrl); basicDataSource.setUsername(username); basicDataSource.setPassword(password); //Autocommit pois plt basicDataSource.setDefaultAutoCommit(false); return basicDataSource; }
From source file:com.openshift.internal.client.ApplicationSSHSessionIntegrationTest.java
private Session createSSHSession(String sshUrl) throws JSchException, URISyntaxException { JSch.setConfig("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); jsch.addIdentity(SSHKeyTestUtils.SSH_TEST_PRIVATEKEY, SSHKeyTestUtils.DEFAULT_PASSPHRASE); URI sshUri = new URI(sshUrl); Session session = jsch.getSession(sshUri.getUserInfo(), sshUri.getHost()); session.connect();/*from ww w.j av a 2s. c om*/ return session; }