diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java index f129e1d7..2ba2448f 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java @@ -426,13 +426,7 @@ public class DefaultConnection implements Connection { if ("userActionRequired".equals(error)) { URI tos = collectLinks("terms-of-service").stream() .findFirst() - .map(it -> { - try { - return conn.getURL().toURI().resolve(it); - } catch (URISyntaxException ex) { - throw new AcmeProtocolException("Invalid TOS URI", ex); - } - }) + .map(this::resolveUri) .orElse(null); throw new AcmeUserActionRequiredException(problem, tos); } @@ -532,4 +526,24 @@ public class DefaultConnection implements Connection { } } + /** + * Resolves a relative URI against the connection's last URL. + * + * @param uri + * URI to resolve + * @return Absolute URI of the given link, or {@code null} if the URI was + * {@code null}. + */ + private URI resolveUri(String uri) { + if (uri == null) { + return null; + } + + try { + return conn.getURL().toURI().resolve(uri); + } catch (URISyntaxException ex) { + throw new AcmeProtocolException("Invalid URI", ex); + } + } + }