Skip to content

Commit

Permalink
fix: #6319 default port for CLI: set default port if not mentionned (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ouertani authored Oct 15, 2020
1 parent 56f9712 commit d46b147
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ private static List<URI> parseServerAddresses(final String serverAddresses) {

private static URI parseUri(final String serverAddress) {
try {
return new URL(serverAddress).toURI();
final URL url = new URL(serverAddress);
if (url.getPort() == -1) {
return new URL(serverAddress.concat(":") + url.getDefaultPort()).toURI();
}
return url.toURI();
} catch (final Exception e) {
throw new KsqlRestClientException(
"The supplied serverAddress is invalid: " + serverAddress, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ public void shouldParseHttpsAddress() throws Exception {
assertThat(ksqlRestClient.getServerAddress(), is(serverURI));
}

@Test
public void shouldParseHttpAddressWithoutPort() throws Exception {
// Given:
final String serverAddress = "http://singleServer";
final URI serverURI = new URI(serverAddress.concat(":80"));

// When:
KsqlRestClient ksqlRestClient = clientWithServerAddresses(serverAddress);

// Then:
assertThat(ksqlRestClient.getServerAddress(), is(serverURI));
}

@Test
public void shouldParseHttpsAddressWithoutPort() throws Exception {
// Given:
final String serverAddress = "https://singleServer";
final URI serverURI = new URI(serverAddress.concat(":443"));

// When:
KsqlRestClient ksqlRestClient = clientWithServerAddresses(serverAddress);

// Then:
assertThat(ksqlRestClient.getServerAddress(), is(serverURI));
}

private KsqlRestClient clientWithServerAddresses(final String serverAddresses) {
return KsqlRestClient.create(
serverAddresses,
Expand Down

0 comments on commit d46b147

Please sign in to comment.