Skip to content

Commit 742db0e

Browse files
committed
Update OuraServiceUserRepository to kotlin and ktor
1 parent d9ae10f commit 742db0e

File tree

3 files changed

+267
-267
lines changed

3 files changed

+267
-267
lines changed

kafka-connect-oura-source/src/main/java/org/radarbase/connect/rest/oura/OuraRestSourceConnectorConfig.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.apache.kafka.common.config.ConfigDef.NO_DEFAULT_VALUE;
2121

22+
import static io.ktor.http.URLUtilsKt.URLBuilder;
2223
import java.lang.reflect.InvocationTargetException;
2324
import java.net.MalformedURLException;
2425
import java.net.URL;
@@ -44,6 +45,8 @@
4445
import org.apache.kafka.common.config.ConfigException;
4546
import org.apache.kafka.connect.errors.ConnectException;
4647
import org.radarbase.connect.rest.oura.user.OuraServiceUserRepository;
48+
import io.ktor.http.URLParserException;
49+
import io.ktor.http.Url;
4750

4851
public class OuraRestSourceConnectorConfig extends AbstractConfig {
4952
public static final Pattern COLON_PATTERN = Pattern.compile(":");
@@ -280,18 +283,18 @@ public OuraServiceUserRepository createUserRepository() {
280283
}
281284
}
282285

283-
public HttpUrl getOuraUserRepositoryUrl() {
286+
public Url getOuraUserRepositoryUrl() {
284287
String urlString = getString(OURA_USER_REPOSITORY_URL_CONFIG).trim();
285288
if (urlString.charAt(urlString.length() - 1) != '/') {
286289
urlString += '/';
287290
}
288-
HttpUrl url = HttpUrl.parse(urlString);
289-
if (url == null) {
291+
try {
292+
return URLBuilder(urlString).build();
293+
} catch (URLParserException ex) {
290294
throw new ConfigException(OURA_USER_REPOSITORY_URL_CONFIG,
291295
getString(OURA_USER_REPOSITORY_URL_CONFIG),
292-
"User repository URL " + urlString + " cannot be parsed as URL.");
296+
"User repository URL " + urlString + " cannot be parsed as URL: " + ex);
293297
}
294-
return url;
295298
}
296299

297300
public Headers getClientCredentials() {
@@ -314,15 +317,17 @@ public String getOuraUserRepositoryClientSecret() {
314317
return getPassword(OURA_USER_REPOSITORY_CLIENT_SECRET_CONFIG).value();
315318
}
316319

317-
public URL getOuraUserRepositoryTokenUrl() {
320+
public Url getOuraUserRepositoryTokenUrl() {
318321
String value = getString(OURA_USER_REPOSITORY_TOKEN_URL_CONFIG);
319322
if (value == null || value.isEmpty()) {
320323
return null;
321324
} else {
322325
try {
323-
return new URL(getString(OURA_USER_REPOSITORY_TOKEN_URL_CONFIG));
324-
} catch (MalformedURLException e) {
325-
throw new ConfigException("Oura user repository token URL is invalid.");
326+
return URLBuilder(value).build();
327+
} catch (URLParserException ex) {
328+
throw new ConfigException(OURA_USER_REPOSITORY_TOKEN_URL_CONFIG,
329+
getString(OURA_USER_REPOSITORY_TOKEN_URL_CONFIG),
330+
"Oura user repository token URL " + value + " cannot be parsed as URL: " + ex);
326331
}
327332
}
328333
}

kafka-connect-oura-source/src/main/java/org/radarbase/connect/rest/oura/user/OuraServiceUserRepository.java

Lines changed: 0 additions & 258 deletions
This file was deleted.

0 commit comments

Comments
 (0)