1919
2020import static org .apache .kafka .common .config .ConfigDef .NO_DEFAULT_VALUE ;
2121
22+ import static io .ktor .http .URLUtilsKt .URLBuilder ;
2223import java .lang .reflect .InvocationTargetException ;
2324import java .net .MalformedURLException ;
2425import java .net .URL ;
4445import org .apache .kafka .common .config .ConfigException ;
4546import org .apache .kafka .connect .errors .ConnectException ;
4647import org .radarbase .connect .rest .oura .user .OuraServiceUserRepository ;
48+ import io .ktor .http .URLParserException ;
49+ import io .ktor .http .Url ;
4750
4851public 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 }
0 commit comments