edu.harvard.cfa.vo.tapclient.util
Class HttpClient

java.lang.Object
  extended by edu.harvard.cfa.vo.tapclient.util.HttpClient

public class HttpClient
extends java.lang.Object

A utility object which provides methods for RESTful interactions with a service.


Constructor Summary
HttpClient()
           
 
Method Summary
static java.lang.String asString(java.io.InputStream inputStream)
          Concatenates the entire InputStream into a String.
static java.io.InputStream delete(java.lang.String spec)
          Sends an HTTP DELETE request to the fully specified url spec.
static java.io.InputStream get(java.lang.String spec)
          Sends an HTTP GET request to the fully specified url spec.
static java.io.InputStream get(java.lang.String spec, java.util.Map parameters)
          Sends an HTTP GET request to the fully specified url spec.
protected static java.io.InputStream handleResponse(org.apache.http.HttpResponse response)
           
static java.io.InputStream post(java.lang.String spec)
          Sends an HTTP POST request to the fully specified url spec.
static java.io.InputStream post(java.lang.String spec, java.util.Map parameters)
          Sends an HTTP POST request to the fully specified url spec.
static java.io.InputStream post(java.lang.String spec, java.util.Map<java.lang.String,java.lang.String> parameters, java.util.Map<java.lang.String,java.net.URI> inlineContent)
          Sends an HTTP POST request to the fully specified url spec.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClient

public HttpClient()
Method Detail

get

public static java.io.InputStream get(java.lang.String spec)
                               throws HttpException,
                                      java.io.IOException
Sends an HTTP GET request to the fully specified url spec.

Parameters:
spec - the url.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.

get

public static java.io.InputStream get(java.lang.String spec,
                                      java.util.Map parameters)
                               throws HttpException,
                                      java.io.IOException
Sends an HTTP GET request to the fully specified url spec.

Parameters:
spec - the url.
parameters - the query parameters.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.
java.lang.NullPointerException - if the url is null.

post

public static java.io.InputStream post(java.lang.String spec)
                                throws HttpException,
                                       java.io.IOException
Sends an HTTP POST request to the fully specified url spec.

Parameters:
spec - the url.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.

post

public static java.io.InputStream post(java.lang.String spec,
                                       java.util.Map parameters)
                                throws HttpException,
                                       java.io.IOException
Sends an HTTP POST request to the fully specified url spec.

Parameters:
spec - the url.
parameters - the query parameters.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.

post

public static java.io.InputStream post(java.lang.String spec,
                                       java.util.Map<java.lang.String,java.lang.String> parameters,
                                       java.util.Map<java.lang.String,java.net.URI> inlineContent)
                                throws HttpException,
                                       java.io.IOException
Sends an HTTP POST request to the fully specified url spec.

Parameters:
spec - the url.
parameters - the query parameters.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.

delete

public static java.io.InputStream delete(java.lang.String spec)
                                  throws HttpException,
                                         java.io.IOException
Sends an HTTP DELETE request to the fully specified url spec.

Parameters:
spec - the url.
Returns:
the InputStream containing the server response.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - in case of a problem or if the connection was aborted.

handleResponse

protected static java.io.InputStream handleResponse(org.apache.http.HttpResponse response)
                                             throws HttpException,
                                                    java.io.IOException
Returns:
the InputStream containing the server respsonse.
Throws:
HttpException - if the HTTP Status Code is not 200(OK).
java.io.IOException - if the error occurs creating the InputStream.

asString

public static java.lang.String asString(java.io.InputStream inputStream)
                                 throws java.io.IOException
Concatenates the entire InputStream into a String.

Parameters:
inputStream - the InputStream to read into a String.
Returns:
a String containing the entire InputStream.
Throws:
java.io.IOException - if an error occurs handling the InputStream.