replace deprecated java.net.URL usage with java.net.URI (#94)

Deprecated in Java 20. Migrate URL parsing to backward compatible URI.
This commit is contained in:
Stefan Kalscheuer 2025-03-28 18:30:37 +01:00
parent 0127cf30be
commit dad35023eb
Signed by: stefan
GPG Key ID: 3887EC2A53B55430
2 changed files with 8 additions and 7 deletions

View File

@ -7,6 +7,9 @@
* Support Vault transit API (#89)
* Support PEM certificate string from `VAULT_CACERT` environment variable (#93)
### Improvements
* Replace deprecated `java.net.URL` usage with `java.net.URI` (#94)
### Dependencies
* Updated Jackson to 2.18.3 (#90)

View File

@ -22,10 +22,8 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -305,11 +303,11 @@ public final class HTTPVaultConnectorBuilder {
/* Parse URL from environment variable */
if (System.getenv(ENV_VAULT_ADDR) != null && !System.getenv(ENV_VAULT_ADDR).isBlank()) {
try {
var url = new URL(System.getenv(ENV_VAULT_ADDR));
this.host = url.getHost();
this.port = url.getPort();
this.tls = url.getProtocol().equals("https");
} catch (MalformedURLException e) {
var uri = new URI(System.getenv(ENV_VAULT_ADDR));
this.host = uri.getHost();
this.port = uri.getPort();
this.tls = uri.getScheme().equalsIgnoreCase("https");
} catch (URISyntaxException e) {
throw new ConnectionException("URL provided in environment variable malformed", e);
}
}