Minor code cleanup

pull/55/head
Richard Körber 2018-01-14 14:41:44 +01:00
parent c7917b3c44
commit e528cad215
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
1 changed files with 21 additions and 7 deletions

View File

@ -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);
}
}
}