|
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; |
@@ -479,18 +479,18 @@ public Path getFitbitUserCredentialsPath() { |
479 | 479 | return Paths.get(getString(FITBIT_USER_CREDENTIALS_DIR_CONFIG)); |
480 | 480 | } |
481 | 481 |
|
482 | | - public HttpUrl getFitbitUserRepositoryUrl() { |
| 482 | + public Url getFitbitUserRepositoryUrl() { |
483 | 483 | String urlString = getString(FITBIT_USER_REPOSITORY_URL_CONFIG).trim(); |
484 | 484 | if (urlString.charAt(urlString.length() - 1) != '/') { |
485 | 485 | urlString += '/'; |
486 | 486 | } |
487 | | - HttpUrl url = HttpUrl.parse(urlString); |
488 | | - if (url == null) { |
| 487 | + try { |
| 488 | + return URLBuilder(urlString).build(); |
| 489 | + } catch (URLParserException ex) { |
489 | 490 | throw new ConfigException(FITBIT_USER_REPOSITORY_URL_CONFIG, |
490 | 491 | getString(FITBIT_USER_REPOSITORY_URL_CONFIG), |
491 | | - "User repository URL " + urlString + " cannot be parsed as URL."); |
| 492 | + "User repository URL " + urlString + " cannot be parsed as URL: " + ex); |
492 | 493 | } |
493 | | - return url; |
494 | 494 | } |
495 | 495 |
|
496 | 496 | public Headers getClientCredentials() { |
@@ -533,15 +533,17 @@ public String getFitbitUserRepositoryClientSecret() { |
533 | 533 | return getPassword(FITBIT_USER_REPOSITORY_CLIENT_SECRET_CONFIG).value(); |
534 | 534 | } |
535 | 535 |
|
536 | | - public URL getFitbitUserRepositoryTokenUrl() { |
| 536 | + public Url getFitbitUserRepositoryTokenUrl() { |
537 | 537 | String value = getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG); |
538 | 538 | if (value == null || value.isEmpty()) { |
539 | 539 | return null; |
540 | 540 | } else { |
541 | 541 | try { |
542 | | - return new URL(getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG)); |
543 | | - } catch (MalformedURLException e) { |
544 | | - throw new ConfigException("Fitbit user repository token URL is invalid."); |
| 542 | + return URLBuilder(value).build(); |
| 543 | + } catch (URLParserException ex) { |
| 544 | + throw new ConfigException(FITBIT_USER_REPOSITORY_URL_CONFIG, |
| 545 | + getString(FITBIT_USER_REPOSITORY_URL_CONFIG), |
| 546 | + "Fitbit user repository token URL " + value + " cannot be parsed as URL: " + ex); |
545 | 547 | } |
546 | 548 | } |
547 | 549 | } |
|
0 commit comments