public class DefaultConnection extends Object implements Connection
Connection.| Modifier and Type | Field and Description |
|---|---|
protected HttpURLConnection |
conn |
protected HttpConnector |
httpConnector |
| Constructor and Description |
|---|
DefaultConnection(HttpConnector httpConnector)
Creates a new
DefaultConnection. |
| Modifier and Type | Method and Description |
|---|---|
int |
accept(int... httpStatus)
Checks if the HTTP response status is in the given list of acceptable HTTP states,
otherwise raises an
AcmeException matching the error. |
void |
close()
Closes the
Connection, releasing all resources. |
URL |
getLink(String relation)
Gets a relation link from the header.
|
URI |
getLinkAsURI(String relation)
Gets a relation link from the header.
|
URL |
getLocation()
Gets a location from the
Location header. |
void |
handleRetryAfter(String message)
Throws an
AcmeRetryAfterException if the last status was HTTP Accepted and
a Retry-After header was received. |
X509Certificate |
readCertificate()
Reads a certificate.
|
JSON |
readJsonResponse()
Reads a server response as JSON data.
|
void |
sendRequest(URL url,
Session session)
Sends a simple GET request.
|
void |
sendSignedRequest(URL url,
JSONBuilder claims,
Session session)
Sends a signed POST request.
|
void |
updateSession(Session session)
Updates a
Session by evaluating the HTTP response header. |
protected final HttpConnector httpConnector
protected HttpURLConnection conn
public DefaultConnection(HttpConnector httpConnector)
DefaultConnection.httpConnector - HttpConnector to be used for HTTP connectionspublic void sendRequest(URL url, Session session) throws AcmeException
ConnectionsendRequest in interface Connectionurl - URL to send the request to.session - Session instance to be used for trackingAcmeExceptionpublic void sendSignedRequest(URL url, JSONBuilder claims, Session session) throws AcmeException
ConnectionsendSignedRequest in interface Connectionurl - URL to send the request to.claims - JSONBuilder containing claims. Must not be null.session - Session instance to be used for signing and trackingAcmeExceptionpublic int accept(int... httpStatus) throws AcmeException
ConnectionAcmeException matching the error.accept in interface ConnectionhttpStatus - Acceptable HTTP statesAcmeExceptionpublic JSON readJsonResponse() throws AcmeException
ConnectionreadJsonResponse in interface ConnectionAcmeExceptionpublic X509Certificate readCertificate() throws AcmeException
ConnectionreadCertificate in interface ConnectionX509Certificate that was read.AcmeExceptionpublic void handleRetryAfter(String message) throws AcmeException
ConnectionAcmeRetryAfterException if the last status was HTTP Accepted and
a Retry-After header was received.handleRetryAfter in interface Connectionmessage - Message to be sent along with the AcmeRetryAfterExceptionAcmeExceptionpublic void updateSession(Session session)
ConnectionSession by evaluating the HTTP response header.updateSession in interface Connectionsession - Session instance to be updatedpublic URL getLocation()
ConnectionLocation header.
Relative links are resolved against the last request's URL.
getLocation in interface ConnectionURL, or null if no Location header was setpublic URL getLink(String relation)
ConnectionRelative links are resolved against the last request's URL. If there is more than one relation, the first one is returned.
getLink in interface Connectionrelation - Link relationURL, or null if there was no such relation linkpublic URI getLinkAsURI(String relation)
ConnectionRelative links are resolved against the last request's URL. If there is more than one relation, the first one is returned.
getLinkAsURI in interface Connectionrelation - Link relationURI, or null if there was no such relation linkpublic void close()
ConnectionConnection, releasing all resources.close in interface AutoCloseableclose in interface ConnectionCopyright © 2015–2019. All rights reserved.