|
17 | 17 |
|
18 | 18 | package org.radarbase.connect.rest.fitbit; |
19 | 19 |
|
| 20 | +import static io.ktor.http.URLUtilsKt.URLBuilder; |
20 | 21 | import static org.apache.kafka.common.config.ConfigDef.NO_DEFAULT_VALUE; |
21 | 22 |
|
22 | 23 | import java.lang.reflect.InvocationTargetException; |
23 | | -import java.net.MalformedURLException; |
24 | | -import java.net.URL; |
25 | 24 | import java.nio.charset.StandardCharsets; |
26 | 25 | import java.nio.file.Path; |
27 | 26 | import java.nio.file.Paths; |
|
31 | 30 | import java.util.List; |
32 | 31 | import java.util.Map; |
33 | 32 |
|
| 33 | +import io.ktor.http.URLParserException; |
| 34 | +import io.ktor.http.Url; |
34 | 35 | import okhttp3.Headers; |
35 | | -import okhttp3.HttpUrl; |
36 | 36 | import org.apache.kafka.common.config.ConfigDef; |
37 | 37 | import org.apache.kafka.common.config.ConfigDef.Importance; |
38 | 38 | import org.apache.kafka.common.config.ConfigDef.NonEmptyString; |
@@ -470,18 +470,18 @@ public Path getFitbitUserCredentialsPath() { |
470 | 470 | return Paths.get(getString(FITBIT_USER_CREDENTIALS_DIR_CONFIG)); |
471 | 471 | } |
472 | 472 |
|
473 | | - public HttpUrl getFitbitUserRepositoryUrl() { |
| 473 | + public Url getFitbitUserRepositoryUrl() { |
474 | 474 | String urlString = getString(FITBIT_USER_REPOSITORY_URL_CONFIG).trim(); |
475 | 475 | if (urlString.charAt(urlString.length() - 1) != '/') { |
476 | 476 | urlString += '/'; |
477 | 477 | } |
478 | | - HttpUrl url = HttpUrl.parse(urlString); |
479 | | - if (url == null) { |
| 478 | + try { |
| 479 | + return URLBuilder(urlString).build(); |
| 480 | + } catch (URLParserException ex) { |
480 | 481 | throw new ConfigException(FITBIT_USER_REPOSITORY_URL_CONFIG, |
481 | 482 | getString(FITBIT_USER_REPOSITORY_URL_CONFIG), |
482 | | - "User repository URL " + urlString + " cannot be parsed as URL."); |
| 483 | + "User repository URL " + urlString + " cannot be parsed as URL: " + ex); |
483 | 484 | } |
484 | | - return url; |
485 | 485 | } |
486 | 486 |
|
487 | 487 | public Headers getClientCredentials() { |
@@ -524,15 +524,17 @@ public String getFitbitUserRepositoryClientSecret() { |
524 | 524 | return getPassword(FITBIT_USER_REPOSITORY_CLIENT_SECRET_CONFIG).value(); |
525 | 525 | } |
526 | 526 |
|
527 | | - public URL getFitbitUserRepositoryTokenUrl() { |
| 527 | + public Url getFitbitUserRepositoryTokenUrl() { |
528 | 528 | String value = getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG); |
529 | 529 | if (value == null || value.isEmpty()) { |
530 | 530 | return null; |
531 | 531 | } else { |
532 | 532 | try { |
533 | | - return new URL(getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG)); |
534 | | - } catch (MalformedURLException e) { |
535 | | - throw new ConfigException("Fitbit user repository token URL is invalid."); |
| 533 | + return URLBuilder(value).build(); |
| 534 | + } catch (URLParserException ex) { |
| 535 | + throw new ConfigException(FITBIT_USER_REPOSITORY_URL_CONFIG, |
| 536 | + getString(FITBIT_USER_REPOSITORY_URL_CONFIG), |
| 537 | + "Fitbit user repository token URL " + value + " cannot be parsed as URL: " + ex); |
536 | 538 | } |
537 | 539 | } |
538 | 540 | } |
|
0 commit comments