Use constants for acme error prefixes

pull/30/head
Richard Körber 2016-07-27 22:55:42 +02:00
parent 91c402473f
commit 57194ce0fc
2 changed files with 16 additions and 11 deletions

View File

@ -56,6 +56,11 @@ import org.slf4j.LoggerFactory;
public class DefaultConnection implements Connection { public class DefaultConnection implements Connection {
private static final Logger LOG = LoggerFactory.getLogger(DefaultConnection.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultConnection.class);
public static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
@Deprecated
public static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
private static final Pattern BASE64URL_PATTERN = Pattern.compile("[0-9A-Za-z_-]+"); private static final Pattern BASE64URL_PATTERN = Pattern.compile("[0-9A-Za-z_-]+");
protected final HttpConnector httpConnector; protected final HttpConnector httpConnector;
@ -313,12 +318,12 @@ public class DefaultConnection implements Connection {
} }
switch (type) { switch (type) {
case "urn:acme:error:unauthorized": case ACME_ERROR_PREFIX + "unauthorized":
case "urn:ietf:params:acme:error:unauthorized": case ACME_ERROR_PREFIX_DEPRECATED + "unauthorized":
throw new AcmeUnauthorizedException(type, detail); throw new AcmeUnauthorizedException(type, detail);
case "urn:acme:error:rateLimited": case ACME_ERROR_PREFIX + "rateLimited":
case "urn:ietf:params:acme:error:rateLimited": case ACME_ERROR_PREFIX_DEPRECATED + "rateLimited":
throw new AcmeRateLimitExceededException(type, detail, getRetryAfterHeader()); throw new AcmeRateLimitExceededException(type, detail, getRetryAfterHeader());
default: default:

View File

@ -13,6 +13,8 @@
*/ */
package org.shredzone.acme4j.exception; package org.shredzone.acme4j.exception;
import org.shredzone.acme4j.connector.DefaultConnection;
/** /**
* An exception that is thrown when the ACME server returned an error. It contains * An exception that is thrown when the ACME server returned an error. It contains
* further details of the cause. * further details of the cause.
@ -20,9 +22,6 @@ package org.shredzone.acme4j.exception;
public class AcmeServerException extends AcmeException { public class AcmeServerException extends AcmeException {
private static final long serialVersionUID = 5971622508467042792L; private static final long serialVersionUID = 5971622508467042792L;
private static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
private static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
private final String type; private final String type;
/** /**
@ -56,11 +55,12 @@ public class AcmeServerException extends AcmeException {
* @return ACME error type, or {@code null} if this is not an * @return ACME error type, or {@code null} if this is not an
* {@code "urn:ietf:params:acme:error"} * {@code "urn:ietf:params:acme:error"}
*/ */
@SuppressWarnings("deprecation")
public String getAcmeErrorType() { public String getAcmeErrorType() {
if (type.startsWith(ACME_ERROR_PREFIX)) { if (type.startsWith(DefaultConnection.ACME_ERROR_PREFIX)) {
return type.substring(ACME_ERROR_PREFIX.length()); return type.substring(DefaultConnection.ACME_ERROR_PREFIX.length());
} else if (type.startsWith(ACME_ERROR_PREFIX_DEPRECATED)) { } else if (type.startsWith(DefaultConnection.ACME_ERROR_PREFIX_DEPRECATED)) {
return type.substring(ACME_ERROR_PREFIX_DEPRECATED.length()); return type.substring(DefaultConnection.ACME_ERROR_PREFIX_DEPRECATED.length());
} else { } else {
return null; return null;
} }