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
Connection
sendRequest
in interface Connection
url
- URL
to send the request to.session
- Session
instance to be used for trackingAcmeException
public void sendSignedRequest(URL url, JSONBuilder claims, Session session) throws AcmeException
Connection
sendSignedRequest
in interface Connection
url
- URL
to send the request to.claims
- JSONBuilder
containing claims. Must not be null
.session
- Session
instance to be used for signing and trackingAcmeException
public int accept(int... httpStatus) throws AcmeException
Connection
AcmeException
matching the error.accept
in interface Connection
httpStatus
- Acceptable HTTP statesAcmeException
public JSON readJsonResponse() throws AcmeException
Connection
readJsonResponse
in interface Connection
AcmeException
public X509Certificate readCertificate() throws AcmeException
Connection
readCertificate
in interface Connection
X509Certificate
that was read.AcmeException
public void handleRetryAfter(String message) throws AcmeException
Connection
AcmeRetryAfterException
if the last status was HTTP Accepted and
a Retry-After header was received.handleRetryAfter
in interface Connection
message
- Message to be sent along with the AcmeRetryAfterException
AcmeException
public void updateSession(Session session)
Connection
Session
by evaluating the HTTP response header.updateSession
in interface Connection
session
- Session
instance to be updatedpublic URL getLocation()
Connection
Location
header.
Relative links are resolved against the last request's URL.
getLocation
in interface Connection
URL
, or null
if no Location header was setpublic URL getLink(String relation)
Connection
Relative links are resolved against the last request's URL. If there is more than one relation, the first one is returned.
getLink
in interface Connection
relation
- Link relationURL
, or null
if there was no such relation linkpublic URI getLinkAsURI(String relation)
Connection
Relative links are resolved against the last request's URL. If there is more than one relation, the first one is returned.
getLinkAsURI
in interface Connection
relation
- Link relationURI
, or null
if there was no such relation linkpublic void close()
Connection
Connection
, releasing all resources.close
in interface AutoCloseable
close
in interface Connection
Copyright © 2015–2019. All rights reserved.