org.springframework.cloud.util.UriInfo Java Examples
The following examples show how to use
org.springframework.cloud.util.UriInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpServiceInfoCreator.java From spring-cloud-lattice with Apache License 2.0 | 6 votes |
@Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { if (uriInfo.getScheme() == null) { throw new IllegalArgumentException("Missing scheme in amqp URI: " + uriInfo); } if (uriInfo.getHost() == null) { throw new IllegalArgumentException("Missing authority in amqp URI: " + uriInfo); } if (uriInfo.getUserName() == null || uriInfo.getPassword() == null) { throw new IllegalArgumentException("Missing userinfo in amqp URI: " + uriInfo); } String path = uriInfo.getPath(); if (path == null) { //NO-OP, this is the default vhost } else { // Check that the path only has a single segment. As we have an authority component // in the URI, paths always begin with a slash. if (path.indexOf('/') != -1) { throw new IllegalArgumentException("Multiple segments in path of amqp URI: " + uriInfo); } } return uriInfo; }
Example #2
Source File: SmtpServiceInfoCreator.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
public SmtpServiceInfo createServiceInfo(Map<String, Object> serviceData) { String id = getId(serviceData); Map<String, Object> credentials = getCredentials(serviceData); String uri = getUriFromCredentials(credentials); if (uri == null) { String host = getStringFromCredentials(credentials, "host", "hostname"); int port = getIntFromCredentials(credentials, "port"); if (port == -1) { port = DEFAULT_SMTP_PORT; } String username = getStringFromCredentials(credentials, "user", "username"); String password = getStringFromCredentials(credentials, "password"); uri = new UriInfo(SmtpServiceInfo.SMTP_SCHEME, host, port, username, password).toString(); } return new SmtpServiceInfo(id, uri); }
Example #3
Source File: AmqpServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
@Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { if (uriInfo.getScheme() == null) { throw new IllegalArgumentException("Missing scheme in amqp URI: " + uriInfo); } if (uriInfo.getHost() == null) { throw new IllegalArgumentException("Missing authority in amqp URI: " + uriInfo); } if (uriInfo.getUserName() == null || uriInfo.getPassword() == null) { throw new IllegalArgumentException("Missing userinfo in amqp URI: " + uriInfo); } String path = uriInfo.getPath(); if (path != null) { // Check that the path only has a single segment. As we have an authority component // in the URI, paths always begin with a slash. if (path.indexOf('/') != -1) { throw new IllegalArgumentException("Multiple segments in path of amqp URI: " + uriInfo); } } return uriInfo; }
Example #4
Source File: HystrixAmqpServiceInfo.java From spring-cloud-services-connector with Apache License 2.0 | 5 votes |
private String assembleAddresses(List<String> uris) { List<String> addresses = new ArrayList<>(); for (String uri : uris) { UriInfo uriInfo = new UriInfo(uri); int port = getSchemeBasedPort(uriInfo.getPort(), uriInfo.getScheme()); addresses.add(uriInfo.getHost() + ":" + port); } return StringUtils.arrayToCommaDelimitedString(addresses.toArray()); }
Example #5
Source File: AbstractCloudFoundryConnectorRelationalServiceTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
protected String getRelationalPayload(String templateFile, String serviceName, String hostname, int port, String user, String password, String name) { String payload = readTestDataFile(templateFile); payload = payload.replace("$serviceName", serviceName); payload = payload.replace("$hostname", hostname); payload = payload.replace("$port", Integer.toString(port)); payload = payload.replace("$user", UriInfo.urlEncode(user)); payload = payload.replace("$password", UriInfo.urlEncode(password)); payload = payload.replace("$name", name); return payload; }
Example #6
Source File: RelationalServiceInfoCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
public SI createServiceInfo(Map<String, Object> serviceData) { String id = getId(serviceData); Map<String,Object> credentials = getCredentials(serviceData); String jdbcUrl = getStringFromCredentials(credentials, "jdbcUrl"); String uri = getUriFromCredentials(credentials); if (uri == null) { String host = getStringFromCredentials(credentials, "hostname", "host"); int port = getIntFromCredentials(credentials, "port"); String username = getStringFromCredentials(credentials, "user", "username"); String password = (String) credentials.get("password"); String database = (String) credentials.get("name"); if (host != null) { uri = new UriInfo(getDefaultUriScheme(), host, port, username, password, database).toString(); } } if (uri == null) { uri = jdbcUrl; } return createServiceInfo(id, uri, jdbcUrl); }
Example #7
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
private void assertUriInfoEquals(UriInfo result, String host, int port, String username, String password, String path, String query) { assertEquals(host, result.getHost()); assertEquals(port, result.getPort()); assertEquals(username, result.getUserName()); assertEquals(password, result.getPassword()); assertEquals(path, result.getPath()); assertEquals(query, result.getQuery()); }
Example #8
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void createWithExplicitParameters() { String uri = "mysql://joe:joes_password@localhost:1527/big_db"; UriInfo result = factory.createUri("mysql", "localhost", 1527, "joe", "joes_password", "big_db"); assertUriInfoEquals(result, "localhost", 1527, "joe", "joes_password", "big_db", null); assertEquals(uri, result.getUriString()); }
Example #9
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void createWithUsernameNoPassword() { String uri = "mysql://joe@localhost:1527/big_db"; UriInfo result = factory.createUri(uri); assertUriInfoEquals(result, "localhost", 1527, "joe", null, "big_db", null); assertEquals(uri, result.getUriString()); }
Example #10
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void createNoUsernamePassword() { String uri = "mysql://localhost:1527/big_db"; UriInfo result = factory.createUri(uri); assertUriInfoEquals(result, "localhost", 1527, null, null, "big_db", null); assertEquals(uri, result.getUriString()); }
Example #11
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void createUriWithQuery() { String uri = "mysql://joe:joes_password@localhost:1527/big_db?p1=v1&p2=v2"; UriInfo result = factory.createUri(uri); assertUriInfoEquals(result, "localhost", 1527, "joe", "joes_password", "big_db", "p1=v1&p2=v2"); assertEquals(uri, result.getUriString()); }
Example #12
Source File: StandardUriInfoFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void createUri() { String uri = "mysql://joe:joes_password@localhost:1527/big_db"; UriInfo result = factory.createUri(uri); assertUriInfoEquals(result, "localhost", 1527, "joe", "joes_password", "big_db", null); assertEquals(uri, result.getUriString()); }
Example #13
Source File: RelationalServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
private String formatUserinfo() { if (getUserName() != null && getPassword() != null) { return String.format("?user=%s&password=%s", UriInfo.urlEncode(getUserName()), UriInfo.urlEncode(getPassword())); } if (getUserName() != null) { return String.format("?user=%s", UriInfo.urlEncode(getUserName())); } return ""; }
Example #14
Source File: MongoDbFactoryFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public MongoServiceInfo getTestServiceInfo(String id) { return new MongoServiceInfo(id, new UriInfo("mongodb", "host", 0, "username", "password", "db").getUriString()); }
Example #15
Source File: SqlServerServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
@Override protected String buildJdbcUrl() { return String.format("jdbc:%s://%s:%d;database=%s;user=%s;password=%s", jdbcUrlDatabaseType, getHost(), getPort(), getPath(), UriInfo.urlEncode(getUserName()), UriInfo.urlEncode(getPassword())); }
Example #16
Source File: UriBasedServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
protected UriInfo getUriInfo() { return uriInfo; }
Example #17
Source File: CloudFoundryConnectorMysqlServiceTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
private String getJdbcUrl(String hostname, int port, String name, String user, String password) { return String.format("jdbc:mysql://%s:%d/%s?user=%s&password=%s", hostname, port, name, UriInfo.urlEncode(user), UriInfo.urlEncode(password)); }
Example #18
Source File: CloudFoundryConnectorOracleServiceTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
private String getJdbcUrl(String hostname, int port, String name, String user, String password) { return String.format("%s%s:thin:%s/%s@%s:%d/%s", JDBC_PREFIX, "oracle", UriInfo.urlEncode(user), UriInfo.urlEncode(password), hostname, port, name); }
Example #19
Source File: CloudFoundryConnectorSqlServerServiceTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
private String getJdbcUrl(String hostname, int port, String scheme, String name, String username, String password) { return String.format("%s%s://%s:%d;database=%s;user=%s;password=%s", JDBC_PREFIX, scheme, hostname, port, name, UriInfo.urlEncode(username), UriInfo.urlEncode(password)); }
Example #20
Source File: CloudFoundryConnectorPostgresqlServiceTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
private String getJdbcUrl(String hostname, int port, String user, String password, String name) { return String.format("jdbc:postgresql://%s:%d/%s?user=%s&password=%s", hostname, port, name, UriInfo.urlEncode(user), UriInfo.urlEncode(password)); }
Example #21
Source File: UriBasedServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 2 votes |
/** * Validate the URI and clean it up by using defaults for any missing information, if possible. * * @param uriInfo * uri info based on parsed payload * @return cleaned up uri info */ protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { return uriInfo; }