Support multiple hosts for PostgreSQL and MySQL - #457
Open
pivotal-david-osullivan wants to merge 3 commits into
Open
Support multiple hosts for PostgreSQL and MySQL#457pivotal-david-osullivan wants to merge 3 commits into
pivotal-david-osullivan wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #128
java.net.URIcannot parse a multi-host authority such asjdbc:postgresql://host1:port1,host2:port2/database— it falls back toregistry-based parsing, where
getHost()returnsnullandgetPort()returns
-1, even thoughgetAuthority()still holds the full value.Changes
UriInfonow detects that fallback and, when the authority contains acomma, parses the host list manually.
getHost()/getPort()keepreturning the first host for backwards compatibility, and a new
getHostAndPort()accessor exposes the full list.getRawAuthority()rather than the percent-decodedgetAuthority(), so a password containing an encoded:,,or@is not mistaken for a delimiter. Decoding happens after splitting,
matching the existing
parseUserinfo()behaviour.PostgresqlJdbcUrlCreatorusesgetHostAndPort()so every hostsurvives into the generated JDBC URL.
MySqlJdbcUrlCreatordoes the same. MySQL and MariaDB support the samehost1,host2failover syntax, and it shares theUriInfocode path, sowithout this it would have silently emitted a first-host-only URL.
(for example SQL Server’s
;property=valuesuffix) keep their previousbehaviour and continue to be handled by their own creator.
Tests
UriInfoTests: multi-host with and without userinfo, a percent-encoded:in the password, a non-PostgreSQL (mysql) multi-host authority, anda single-host case asserting the standard path is unaffected.
PostgresqlJdbcTests/MySqlJdbcTests: end-to-end VCAP_SERVICESpayloads asserting all hosts reach the JDBC URL.