private JsonObject pollResourceUntilFinalized(AcmeAccount account, boolean staging, String resourceUrl) throws AcmeException { boolean statusFinalized; JsonObject jsonResponse; do { statusFinalized = true; HttpURLConnection connection = sendPostAsGetRequest(account, staging, resourceUrl, JSON_CONTENT_TYPE, HttpURLConnection.HTTP_OK); jsonResponse = getJsonResponse(connection); String status = jsonResponse.getString(STATUS); if (! status.equals(VALID) && ! status.equals(INVALID)) { // server still processing the client response, try again after some time statusFinalized = false; long retryAfterMilli = getRetryAfter(connection, true); if (retryAfterMilli > 0) { try { Thread.sleep(retryAfterMilli); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } } } while (! statusFinalized); return jsonResponse; }
String queryAccountStatus(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); return jsonResponse.getString(STATUS); }
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
/** * Get the resource URLs needed to perform operations from the ACME server. * * @param account the ACME account information to use (must not be {@code null}) * @param staging whether or not the staging server URL should be used * @return a map of ACME resources to URLs * @throws AcmeException if an error occurs while attempting to get the resource URLs from the ACME server */ public Map<AcmeResource, URL> getResourceUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); final Map<AcmeResource, URL> resourceUrls = account.getResourceUrls(staging); if (resourceUrls.isEmpty()) { HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); try { for (AcmeResource resource : AcmeResource.values()) { String resourceUrl = getOptionalJsonString(directoryJson, resource.getValue()); URL url = resourceUrl != null ? new URL(resourceUrl) : null; resourceUrls.put(resource, url); } } catch (MalformedURLException e) { throw acme.unableToRetrieveAcmeServerDirectoryUrls(e); } } return resourceUrls; }
throw acme.unexpectedResponseCodeFromAcmeServer(responseCode, responseMessage); JsonObject jsonResponse = getJsonResponse(connection); String type = getOptionalJsonString(jsonResponse, TYPE); if (type != null) {
getEncodedJson(payloadBuilder.build()), HttpURLConnection.HTTP_CREATED); String authorizationUrl = getLocation(connection); JsonObject jsonResponse = getJsonResponse(connection); AcmeChallenge selectedChallenge = respondToChallenges(account, staging, jsonResponse); try {
Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); JsonObject metadata = directoryJson.getJsonObject(META); if (metadata == null) {
.add(IDENTIFIERS, identifiersBuilder.build()); HttpURLConnection connection = sendPostRequestWithRetries(account, staging, newOrderUrl, false, getEncodedJson(payloadBuilder.build()), HttpURLConnection.HTTP_CREATED); JsonObject jsonResponse = getJsonResponse(connection); final String finalizeOrderUrl = jsonResponse.getString(FINALIZE); final JsonArray authorizationsArray = jsonResponse.getJsonArray(AUTHORIZATIONS); for (String authorizationUrl : authorizationUrls) { connection = sendPostAsGetRequest(account, staging, authorizationUrl, JSON_CONTENT_TYPE, HttpURLConnection.HTTP_OK); jsonResponse = getJsonResponse(connection); AcmeChallenge selectedChallenge = respondToChallenges(account, staging, jsonResponse); if (selectedChallenge != null) {
private JsonObject pollResourceUntilFinalized(String resourceUrl) throws AcmeException { boolean statusFinalized; JsonObject jsonResponse; do { statusFinalized = true; HttpURLConnection connection = sendGetRequest(resourceUrl, HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); jsonResponse = getJsonResponse(connection); String status = jsonResponse.getString(STATUS); if (! status.equals(VALID) && ! status.equals(INVALID)) { // server still processing the client response, try again after some time statusFinalized = false; long retryAfterMilli = getRetryAfter(connection, true); if (retryAfterMilli > 0) { try { Thread.sleep(retryAfterMilli); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } } } while (! statusFinalized); return jsonResponse; }
private JsonObject pollResourceUntilFinalized(String resourceUrl) throws AcmeException { boolean statusFinalized; JsonObject jsonResponse; do { statusFinalized = true; HttpURLConnection connection = sendGetRequest(resourceUrl, HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); jsonResponse = getJsonResponse(connection); String status = jsonResponse.getString(STATUS); if (! status.equals(VALID) && ! status.equals(INVALID)) { // server still processing the client response, try again after some time statusFinalized = false; long retryAfterMilli = getRetryAfter(connection, true); if (retryAfterMilli > 0) { try { Thread.sleep(retryAfterMilli); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } } } while (! statusFinalized); return jsonResponse; }
private JsonObject pollResourceUntilFinalized(AcmeAccount account, boolean staging, String resourceUrl) throws AcmeException { boolean statusFinalized; JsonObject jsonResponse; do { statusFinalized = true; HttpURLConnection connection = sendPostAsGetRequest(account, staging, resourceUrl, JSON_CONTENT_TYPE, HttpURLConnection.HTTP_OK); jsonResponse = getJsonResponse(connection); String status = jsonResponse.getString(STATUS); if (! status.equals(VALID) && ! status.equals(INVALID)) { // server still processing the client response, try again after some time statusFinalized = false; long retryAfterMilli = getRetryAfter(connection, true); if (retryAfterMilli > 0) { try { Thread.sleep(retryAfterMilli); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } } } while (! statusFinalized); return jsonResponse; }
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
String queryAccountStatus(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostAsGetRequest(account, staging, getAccountUrl(account, staging), null, HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); return jsonResponse.getString(STATUS); }
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostRequestWithRetries(account, staging, getAccountUrl(account, staging), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
String[] queryAccountContactUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostRequestWithRetries(account, staging, getAccountUrl(account, staging), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); JsonArray contactsArray = jsonResponse.getJsonArray(CONTACT); if (contactsArray != null && contactsArray.size() > 0) { List<String> contacts = new ArrayList<>(contactsArray.size()); for (JsonString contact : contactsArray.getValuesAs(JsonString.class)) { contacts.add(contact.getString()); } return contacts.toArray(new String[contacts.size()]); } return null; }
String queryAccountStatus(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostRequestWithRetries(account, staging, getAccountUrl(account, staging), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); return jsonResponse.getString(STATUS); }
String queryAccountStatus(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); HttpURLConnection connection = sendPostRequestWithRetries(account, staging, getAccountUrl(account, staging), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); JsonObject jsonResponse = getJsonResponse(connection); return jsonResponse.getString(STATUS); }
/** * Get the resource URLs needed to perform operations from the ACME server. * * @param account the ACME account information to use (must not be {@code null}) * @param staging whether or not the staging server URL should be used * @return a map of ACME resources to URLs * @throws AcmeException if an error occurs while attempting to get the resource URLs from the ACME server */ public Map<AcmeResource, URL> getResourceUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); final Map<AcmeResource, URL> resourceUrls = account.getResourceUrls(staging); if (resourceUrls.isEmpty()) { HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); try { for (AcmeResource resource : AcmeResource.values()) { String resourceUrl = getOptionalJsonString(directoryJson, resource.getValue()); URL url = resourceUrl != null ? new URL(resourceUrl) : null; resourceUrls.put(resource, url); } } catch (MalformedURLException e) { throw acme.unableToRetrieveAcmeServerDirectoryUrls(e); } } return resourceUrls; }
/** * Get the resource URLs needed to perform operations from the ACME server. * * @param account the ACME account information to use (must not be {@code null}) * @param staging whether or not the staging server URL should be used * @return a map of ACME resources to URLs * @throws AcmeException if an error occurs while attempting to get the resource URLs from the ACME server */ public Map<AcmeResource, URL> getResourceUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); final Map<AcmeResource, URL> resourceUrls = account.getResourceUrls(staging); if (resourceUrls.isEmpty()) { HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); try { for (AcmeResource resource : AcmeResource.values()) { String resourceUrl = getOptionalJsonString(directoryJson, resource.getValue()); URL url = resourceUrl != null ? new URL(resourceUrl) : null; resourceUrls.put(resource, url); } } catch (MalformedURLException e) { throw acme.unableToRetrieveAcmeServerDirectoryUrls(e); } } return resourceUrls; }
/** * Get the resource URLs needed to perform operations from the ACME server. * * @param account the ACME account information to use (must not be {@code null}) * @param staging whether or not the staging server URL should be used * @return a map of ACME resources to URLs * @throws AcmeException if an error occurs while attempting to get the resource URLs from the ACME server */ public Map<AcmeResource, URL> getResourceUrls(AcmeAccount account, boolean staging) throws AcmeException { Assert.checkNotNullParam("account", account); final Map<AcmeResource, URL> resourceUrls = account.getResourceUrls(staging); if (resourceUrls.isEmpty()) { HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); try { for (AcmeResource resource : AcmeResource.values()) { String resourceUrl = getOptionalJsonString(directoryJson, resource.getValue()); URL url = resourceUrl != null ? new URL(resourceUrl) : null; resourceUrls.put(resource, url); } } catch (MalformedURLException e) { throw acme.unableToRetrieveAcmeServerDirectoryUrls(e); } } return resourceUrls; }