nl.nikhef.slcshttps
Class CAConnection

java.lang.Object
  extended by nl.nikhef.slcshttps.CAConnection

public class CAConnection
extends Object

This class provides methods to post data to a (CA) website and retrieve and store the response. Its behaviour is similar to HttpsURLConnection, but not similar enough to make it an extension of it.

Version:
0.1
Author:
Mischa Sallé
See Also:
HttpsURLConnection

Field Summary
private  HttpsURLConnection connection
          the actual connection to the CA.
protected  String POST_CONTENT_TYPE
          mime-type of HTTP POST contents is "application/x-www-form-urlencoded".
protected  String RESP_CONTENT_TYPE
          expected mime-type for a correct response type is "application/pkix-cert".
private  StringBuffer response
          response is filled by storeResponse() when getCert() fails and can be retrieved using getResponse().
private  int responseCode
          responseCode is set after posting data by postString(String).
private  String responseMessage
          responseMessage is set after posting data by postString(String).
 
Constructor Summary
CAConnection()
          Default constructor to force handling of calling without arguments.
CAConnection(String CA_URL)
          Constructs a CAConnection to the url specified by String CA_URL.
 
Method Summary
 X509Certificate getCert()
          Tries to retrieve a X509Certificate from the open connection, expecting content-type "application/pkix-cert".
 String getResponse()
          returns the CA output in String form, note that the output is only stored when it couldn't be interpreted as X509Certificate.
 int getResponseCode()
          returns the HTTP POST response code.
 String getResponseMessage()
          returns the HTTP POST response message, belonging to responseCode.
 int postString(String string)
          Sends String string to the opened URL using a HTTP POST with content-type "application/x-www-form-urlencoded".
private  int storeResponse()
          Stores the response from the server into the internal String field response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

private HttpsURLConnection connection
the actual connection to the CA.


responseCode

private int responseCode
responseCode is set after posting data by postString(String).


responseMessage

private String responseMessage
responseMessage is set after posting data by postString(String).


response

private StringBuffer response
response is filled by storeResponse() when getCert() fails and can be retrieved using getResponse().


POST_CONTENT_TYPE

protected final String POST_CONTENT_TYPE
mime-type of HTTP POST contents is "application/x-www-form-urlencoded".

See Also:
Constant Field Values

RESP_CONTENT_TYPE

protected final String RESP_CONTENT_TYPE
expected mime-type for a correct response type is "application/pkix-cert".

See Also:
Constant Field Values
Constructor Detail

CAConnection

public CAConnection()
             throws IOException
Default constructor to force handling of calling without arguments.

Throws:
IOException
See Also:
CAConnection(String)

CAConnection

public CAConnection(String CA_URL)
             throws IOException
Constructs a CAConnection to the url specified by String CA_URL.

Parameters:
CA_URL - String representation of the URL to talk to.
Throws:
IOException - for any error, including emptry URL.
Method Detail

postString

public int postString(String string)
               throws IOException
Sends String string to the opened URL using a HTTP POST with content-type "application/x-www-form-urlencoded".

Parameters:
string - data to send
Returns:
the HTTP responsecode (also stored internally) and can be obtained using getResponseCode().
Throws:
IOException - for any error.
See Also:
HttpURLConnection.getResponseCode()

getCert

public X509Certificate getCert()
                        throws CertificateException,
                               IOException
Tries to retrieve a X509Certificate from the open connection, expecting content-type "application/pkix-cert". Upon failure the response is stored in response and can be retrieved using getResponse().

Returns:
the retrieved X509Certificate.
Throws:
IOException - if we couldn't get a response from the server.
CertificateException - if the server responded but not with a valid certificate.

getResponseCode

public int getResponseCode()
returns the HTTP POST response code.

Returns:
int representing the HTTP POST response code
See Also:
getResponseMessage(), HttpURLConnection.getResponseCode()

getResponseMessage

public String getResponseMessage()
returns the HTTP POST response message, belonging to responseCode.

Returns:
String representing the HTTP POST response message
See Also:
getResponseCode()

getResponse

public String getResponse()
returns the CA output in String form, note that the output is only stored when it couldn't be interpreted as X509Certificate.

Returns:
String representing the CA output.

storeResponse

private int storeResponse()
                   throws IOException
Stores the response from the server into the internal String field response.

Returns:
number of lines read
Throws:
IOException


nl.nikhef.slcshttps Mischa Sallé - msalle(AT)nikhef.nl