public class HttpOCSPRequest
extends java.lang.Object
This class uses a HttpURLConnection
object for sending a request
to an OCSP responder by using the POST method. When creating a
HttpOCSPRequest
object supply the URL of the
OCSP responder and subsequently call method postRequest
for sending the OCSPRequest
to the server. The response from the server can be obtained by calling method
getOCSPResponse
, e.g.:
// the request to be send: OCSPRequest ocspRequest = ...; // the responder URL to post to: URL url = ...; // create the http request: HttpOCSPRequest httpOCSPRequest = new HttpOCSPRequest(url); // post the request int responseCode = httpOCSPRequest.postRequest(ocspRequest); if (responseCode/200 != 2) { System.out.println("Error connecting to " + responderUrl + ":"); System.out.println(httpOCSPRequest.getResponseMessage()); } else { System.out.println("Parse response: "); OCSPResponse ocspResponse = httpOCSPRequest.getOCSPResponse(); ... }
OCSPRequest
,
OCSPResponse
Constructor and Description |
---|
HttpOCSPRequest(java.net.URL responderUrl)
Creates a HttpOCSPRequest for the given responder url.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getHeaderField(int n)
Gets the value of the http response header field with the given index.
|
java.lang.String |
getHeaderField(java.lang.String name)
Gets the value of the http response header field with the given name.
|
java.lang.String |
getHeaderFieldKey(int n)
Gets the key of the http response header field with the given index.
|
OCSPResponse |
getOCSPResponse()
Returns the ocsp response sent by the server.
|
java.lang.String |
getResponseMessage()
Gets the http response message.
|
protected java.net.HttpURLConnection |
openConnection(java.net.URL responderUrl)
Opens the connection to the responder url.
|
int |
postRequest(OCSPRequest ocspRequest)
Posts the given ocsp request to the responder of this HttpOCSPRequest.
|
int |
sendGETRequest(OCSPRequest ocspRequest)
Uses the http GET command to send the given ocsp request to the responder
of this HttpOCSPRequest.
|
public HttpOCSPRequest(java.net.URL responderUrl)
responderUrl
- the url of the OCSP responderpublic int postRequest(OCSPRequest ocspRequest) throws java.io.IOException, UnknownResponseException
ocspRequest
- the OCSPrequest
to be postedjava.io.IOException
- if an I/O error occurs while reading the responseUnknownResponseException
- if the post has been successful, but the server uses an not
supported response typeprotected java.net.HttpURLConnection openConnection(java.net.URL responderUrl) throws java.io.IOException
This method is used by postRequest
and sendGETRequest(OCSPRequest)
to open the connection to the OCSP responder:
return (HttpURLConnection) responderUrl.openConnection();This method may be overridden by an application to do some application specific configurations for the HttpURLConnection object to be used, e.g. setting read/connect timeout:
URL responderUrl = new URL(...); HttpOCSPRequest httpOCSPRequest = new HttpOCSPRequest(responderUrl) { protected HttpURLConnection openConnection(URL responderUrl) throws IOException { HttpURLConnection con = super.openConnection(responderUrl); con.setConnectTimeout(...); con.setReadTimeout(...); return con; } };
responderUrl
- the responder urljava.io.IOException
- if the connection cannot be openedpublic int sendGETRequest(OCSPRequest ocspRequest) throws java.io.IOException, UnknownResponseException
post
the
request.ocspRequest
- the OCSPrequest
to be postedjava.io.IOException
- if an I/O error occurs while reading the responseUnknownResponseException
- if the post has been successful, but the server uses an not
supported response typepublic OCSPResponse getOCSPResponse()
public java.lang.String getResponseMessage()
public java.lang.String getHeaderField(java.lang.String name)
name
- the name of the http response header fieldnull
if there is no header field with the given name
or the request has yet not be send to the serverpublic java.lang.String getHeaderFieldKey(int n)
n
- the header indexnull
if there is no header field with the given index
or the request has yet not be send to the serverpublic java.lang.String getHeaderField(int n)
n
- the header indexnull
if there is no header field with the given
index or the request has yet not be send to the server