mirror of https://github.com/shred/acme4j
Fix style issues
parent
232a243e92
commit
b3fc9a732c
|
@ -118,7 +118,7 @@ public class Authorization extends AcmeResource {
|
|||
@SuppressWarnings("unchecked")
|
||||
public <T extends Challenge> T findChallenge(String type) {
|
||||
Collection<Challenge> result = findCombination(type);
|
||||
return (result != null ? (T) result.iterator().next() : null);
|
||||
return result != null ? (T) result.iterator().next() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +217,7 @@ public class Authorization extends AcmeResource {
|
|||
update();
|
||||
} catch (AcmeRetryAfterException ex) {
|
||||
// ignore... The object was still updated.
|
||||
LOG.debug("Retry-After", ex);
|
||||
} catch (AcmeException ex) {
|
||||
throw new AcmeProtocolException("Could not load lazily", ex);
|
||||
}
|
||||
|
@ -233,47 +234,47 @@ public class Authorization extends AcmeResource {
|
|||
protected void unmarshalAuthorization(Map<String, Object> json) {
|
||||
this.status = Status.parse((String) json.get("status"), Status.PENDING);
|
||||
|
||||
String expires = (String) json.get("expires");
|
||||
if (expires != null) {
|
||||
this.expires = TimestampParser.parse(expires);
|
||||
String jsonExpires = (String) json.get("expires");
|
||||
if (jsonExpires != null) {
|
||||
expires = TimestampParser.parse(jsonExpires);
|
||||
}
|
||||
|
||||
Map<String, Object> identifier = (Map<String, Object>) json.get("identifier");
|
||||
if (identifier != null) {
|
||||
String type = (String) identifier.get("type");
|
||||
Map<String, Object> jsonIdentifier = (Map<String, Object>) json.get("identifier");
|
||||
if (jsonIdentifier != null) {
|
||||
String type = (String) jsonIdentifier.get("type");
|
||||
if (type != null && !"dns".equals(type)) {
|
||||
throw new AcmeProtocolException("Unknown authorization type: " + type);
|
||||
}
|
||||
this.domain = (String) identifier.get("value");
|
||||
domain = (String) jsonIdentifier.get("value");
|
||||
}
|
||||
|
||||
Collection<Map<String, Object>> challenges =
|
||||
Collection<Map<String, Object>> jsonChallenges =
|
||||
(Collection<Map<String, Object>>) json.get("challenges");
|
||||
List<Challenge> cr = new ArrayList<>();
|
||||
for (Map<String, Object> c : challenges) {
|
||||
for (Map<String, Object> c : jsonChallenges) {
|
||||
Challenge ch = getSession().createChallenge(c);
|
||||
if (ch != null) {
|
||||
cr.add(ch);
|
||||
}
|
||||
}
|
||||
this.challenges = cr;
|
||||
challenges = cr;
|
||||
|
||||
Collection<List<Number>> combinations =
|
||||
Collection<List<Number>> jsonCombinations =
|
||||
(Collection<List<Number>>) json.get("combinations");
|
||||
if (combinations != null) {
|
||||
List<List<Challenge>> cmb = new ArrayList<>(combinations.size());
|
||||
for (List<Number> c : combinations) {
|
||||
if (jsonCombinations != null) {
|
||||
List<List<Challenge>> cmb = new ArrayList<>(jsonCombinations.size());
|
||||
for (List<Number> c : jsonCombinations) {
|
||||
List<Challenge> clist = new ArrayList<>(c.size());
|
||||
for (Number n : c) {
|
||||
clist.add(cr.get(n.intValue()));
|
||||
}
|
||||
cmb.add(clist);
|
||||
}
|
||||
this.combinations = cmb;
|
||||
combinations = cmb;
|
||||
} else {
|
||||
List<List<Challenge>> cmb = new ArrayList<>(1);
|
||||
cmb.add(cr);
|
||||
this.combinations = cmb;
|
||||
combinations = cmb;
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
|
|
@ -79,7 +79,7 @@ public class Metadata {
|
|||
*/
|
||||
public String get(String key) {
|
||||
Object value = meta.get(key);
|
||||
return (value != null ? value.toString() : null);
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,7 +95,7 @@ public class Metadata {
|
|||
public URI getUri(String key) {
|
||||
Object uri = meta.get(key);
|
||||
try {
|
||||
return (uri != null ? new URI(uri.toString()) : null);
|
||||
return uri != null ? new URI(uri.toString()) : null;
|
||||
} catch (URISyntaxException ex) {
|
||||
throw new AcmeProtocolException("Bad URI: " + uri, ex);
|
||||
}
|
||||
|
|
|
@ -335,6 +335,7 @@ public class Registration extends AcmeResource {
|
|||
update();
|
||||
} catch (AcmeRetryAfterException ex) {
|
||||
// ignore... The object was still updated.
|
||||
LOG.debug("Retry-After", ex);
|
||||
} catch (AcmeException ex) {
|
||||
throw new AcmeProtocolException("Could not load lazily", ex);
|
||||
}
|
||||
|
|
|
@ -29,11 +29,13 @@ public enum Status {
|
|||
* no match
|
||||
*/
|
||||
public static Status parse(String str) {
|
||||
try {
|
||||
return valueOf(str.toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return Status.UNKNOWN;
|
||||
String check = str.toUpperCase();
|
||||
for (Status s : values()) {
|
||||
if (s.name().equals(check)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +49,7 @@ public enum Status {
|
|||
* no match, or {@code def} if the str was {@code null}
|
||||
*/
|
||||
public static Status parse(String str, Status def) {
|
||||
return (str != null ? parse(str) : def);
|
||||
return str != null ? parse(str) : def;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -198,7 +198,8 @@ public class DefaultConnection implements Connection {
|
|||
|
||||
String response = "";
|
||||
try {
|
||||
InputStream in = (conn.getResponseCode() < 400 ? conn.getInputStream() : conn.getErrorStream());
|
||||
InputStream in =
|
||||
conn.getResponseCode() < 400 ? conn.getInputStream() : conn.getErrorStream();
|
||||
if (in != null) {
|
||||
response = readStream(in);
|
||||
result = JsonUtil.parseJson(response);
|
||||
|
@ -311,7 +312,7 @@ public class DefaultConnection implements Connection {
|
|||
}
|
||||
}
|
||||
|
||||
return (!result.isEmpty() ? result : null);
|
||||
return !result.isEmpty() ? result : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -334,7 +335,7 @@ public class DefaultConnection implements Connection {
|
|||
|
||||
// HTTP-date
|
||||
long date = conn.getHeaderFieldDate("Retry-After", 0L);
|
||||
return (date != 0 ? new Date(date) : null);
|
||||
return date != 0 ? new Date(date) : null;
|
||||
} catch (Exception ex) {
|
||||
throw new AcmeProtocolException("Bad retry-after header value: " + header, ex);
|
||||
}
|
||||
|
@ -410,12 +411,13 @@ public class DefaultConnection implements Connection {
|
|||
* Log all HTTP headers in debug mode.
|
||||
*/
|
||||
private void logHeaders() {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
Map<String, List<String>> headers = conn.getHeaderFields();
|
||||
for (String key : headers.keySet()) {
|
||||
for (String value : headers.get(key)) {
|
||||
LOG.debug("HEADER {}: {}", key, value);
|
||||
}
|
||||
if (!LOG.isDebugEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
LOG.debug("HEADER {}: {}", entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
package org.shredzone.acme4j.connector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A generic HTTP connector. It connects to the given URI with a 10 seconds connection and
|
||||
* read timeout.
|
||||
|
@ -32,16 +35,17 @@ public class HttpConnector {
|
|||
|
||||
static {
|
||||
StringBuilder agent = new StringBuilder("acme4j");
|
||||
try {
|
||||
|
||||
try (InputStream in = HttpConnector.class.getResourceAsStream("/org/shredzone/acme4j/version.properties")) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(HttpConnector.class.getResourceAsStream("/org/shredzone/acme4j/version.properties"));
|
||||
prop.load(in);
|
||||
agent.append('/').append(prop.getProperty("version"));
|
||||
} catch (IOException ex) {
|
||||
// Ignore, just don't use a version
|
||||
LoggerFactory.getLogger(HttpConnector.class).warn("Could not read library version", ex);
|
||||
}
|
||||
|
||||
agent.append(" Java/").append(System.getProperty("java.version"));
|
||||
|
||||
USER_AGENT = agent.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ public class AcmeRateLimitExceededException extends AcmeServerException {
|
|||
public AcmeRateLimitExceededException(String type, String detail, Date retryAfter, Collection<URI> documents) {
|
||||
super(type, detail);
|
||||
this.retryAfter = retryAfter;
|
||||
this.documents = (documents != null ? Collections.unmodifiableCollection(documents) : null);
|
||||
this.documents =
|
||||
documents != null ? Collections.unmodifiableCollection(documents) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +53,7 @@ public class AcmeRateLimitExceededException extends AcmeServerException {
|
|||
* moment is not known.
|
||||
*/
|
||||
public Date getRetryAfter() {
|
||||
return (retryAfter != null ? new Date(retryAfter.getTime()) : null);
|
||||
return retryAfter != null ? new Date(retryAfter.getTime()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ public class AcmeRetryAfterException extends AcmeException {
|
|||
* Returns the retry-after date returned by the server.
|
||||
*/
|
||||
public Date getRetryAfter() {
|
||||
return (retryAfter != null ? new Date(retryAfter.getTime()) : null);
|
||||
return retryAfter != null ? new Date(retryAfter.getTime()) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.regex.Pattern;
|
|||
*
|
||||
* @see <a href="https://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a>
|
||||
*/
|
||||
public class TimestampParser {
|
||||
public final class TimestampParser {
|
||||
|
||||
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||
"^(\\d{4})-(\\d{2})-(\\d{2})T"
|
||||
|
@ -36,6 +36,10 @@ public class TimestampParser {
|
|||
private static final Pattern TZ_PATTERN = Pattern.compile(
|
||||
"([+-])(\\d{2}):?(\\d{2})$");
|
||||
|
||||
private TimestampParser() {
|
||||
// Utility class without constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a RFC 3339 formatted date.
|
||||
*
|
||||
|
@ -58,15 +62,14 @@ public class TimestampParser {
|
|||
int minute = Integer.parseInt(m.group(5));
|
||||
int second = Integer.parseInt(m.group(6));
|
||||
|
||||
String msStr = m.group(7);
|
||||
if (msStr == null) {
|
||||
msStr = "000";
|
||||
} else {
|
||||
while (msStr.length() < 3) {
|
||||
msStr += '0';
|
||||
}
|
||||
StringBuilder msStr = new StringBuilder();
|
||||
if (m.group(7) != null) {
|
||||
msStr.append(m.group(7));
|
||||
}
|
||||
int ms = Integer.parseInt(msStr);
|
||||
while (msStr.length() < 3) {
|
||||
msStr.append('0');
|
||||
}
|
||||
int ms = Integer.parseInt(msStr.toString());
|
||||
|
||||
String tz = m.group(8);
|
||||
if ("Z".equalsIgnoreCase(tz)) {
|
||||
|
|
Loading…
Reference in New Issue