net.rcarz.jiraclient
Class RestClient

java.lang.Object
  extended by net.rcarz.jiraclient.RestClient

public class RestClient
extends Object

A simple REST client that speaks JSON.


Constructor Summary
RestClient(org.apache.http.client.HttpClient httpclient, URI uri)
          Creates a REST client instance with a URI.
 
Method Summary
 URI buildURI(String path)
          Build a URI from a path.
 URI buildURI(String path, Map<String,String> params)
          Build a URI from a path and query parmeters.
 net.sf.json.JSON delete(String path)
          Executes an HTTP DELETE with the given path.
 net.sf.json.JSON delete(URI uri)
          Executes an HTTP DELETE with the given URI.
 net.sf.json.JSON get(String path)
          Executes an HTTP GET with the given path.
 net.sf.json.JSON get(URI uri)
          Executes an HTTP GET with the given URI.
 net.sf.json.JSON post(String path, net.sf.json.JSON payload)
          Executes an HTTP POST with the given path and payload.
 net.sf.json.JSON post(URI uri, net.sf.json.JSON payload)
          Executes an HTTP POST with the given URI and payload.
 net.sf.json.JSON post(URI uri, String payload)
          Executes an HTTP POST with the given URI and payload.
 net.sf.json.JSON put(String path, net.sf.json.JSON payload)
          Executes an HTTP PUT with the given path and payload.
 net.sf.json.JSON put(URI uri, net.sf.json.JSON payload)
          Executes an HTTP PUT with the given URI and payload.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestClient

public RestClient(org.apache.http.client.HttpClient httpclient,
                  URI uri)
Creates a REST client instance with a URI.

Parameters:
httpclient - Underlying HTTP client to use
uri - Base URI of the remote REST service
Method Detail

buildURI

public URI buildURI(String path)
             throws URISyntaxException
Build a URI from a path.

Parameters:
path - Path to append to the base URI
Returns:
the full URI
Throws:
URISyntaxException - when the path is invalid

buildURI

public URI buildURI(String path,
                    Map<String,String> params)
             throws URISyntaxException
Build a URI from a path and query parmeters.

Parameters:
path - Path to append to the base URI
params - Map of key value pairs
Returns:
the full URI
Throws:
URISyntaxException - when the path is invalid

delete

public net.sf.json.JSON delete(URI uri)
                        throws RestException,
                               IOException
Executes an HTTP DELETE with the given URI.

Parameters:
uri - Full URI of the remote endpoint
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs

delete

public net.sf.json.JSON delete(String path)
                        throws RestException,
                               IOException,
                               URISyntaxException
Executes an HTTP DELETE with the given path.

Parameters:
path - Path to be appended to the URI supplied in the construtor
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs
URISyntaxException - when an error occurred appending the path to the URI

get

public net.sf.json.JSON get(URI uri)
                     throws RestException,
                            IOException
Executes an HTTP GET with the given URI.

Parameters:
uri - Full URI of the remote endpoint
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs

get

public net.sf.json.JSON get(String path)
                     throws RestException,
                            IOException,
                            URISyntaxException
Executes an HTTP GET with the given path.

Parameters:
path - Path to be appended to the URI supplied in the construtor
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs
URISyntaxException - when an error occurred appending the path to the URI

post

public net.sf.json.JSON post(URI uri,
                             net.sf.json.JSON payload)
                      throws RestException,
                             IOException
Executes an HTTP POST with the given URI and payload.

Parameters:
uri - Full URI of the remote endpoint
payload - JSON-encoded data to send to the remote service
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs

post

public net.sf.json.JSON post(URI uri,
                             String payload)
                      throws RestException,
                             IOException
Executes an HTTP POST with the given URI and payload. At least one JIRA REST endpoint expects malformed JSON. The payload argument is quoted and sent to the server with the application/json Content-Type header. You should not use this function when proper JSON is expected.

Parameters:
uri - Full URI of the remote endpoint
payload - Raw string to send to the remote service
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs
See Also:
https://jira.atlassian.com/browse/JRA-29304

post

public net.sf.json.JSON post(String path,
                             net.sf.json.JSON payload)
                      throws RestException,
                             IOException,
                             URISyntaxException
Executes an HTTP POST with the given path and payload.

Parameters:
path - Path to be appended to the URI supplied in the construtor
payload - JSON-encoded data to send to the remote service
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs
URISyntaxException - when an error occurred appending the path to the URI

put

public net.sf.json.JSON put(URI uri,
                            net.sf.json.JSON payload)
                     throws RestException,
                            IOException
Executes an HTTP PUT with the given URI and payload.

Parameters:
uri - Full URI of the remote endpoint
payload - JSON-encoded data to send to the remote service
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs

put

public net.sf.json.JSON put(String path,
                            net.sf.json.JSON payload)
                     throws RestException,
                            IOException,
                            URISyntaxException
Executes an HTTP PUT with the given path and payload.

Parameters:
path - Path to be appended to the URI supplied in the construtor
payload - JSON-encoded data to send to the remote service
Returns:
JSON-encoded result or null when there's no content returned
Throws:
RestException - when an HTTP-level error occurs
IOException - when an error reading the response occurs
URISyntaxException - when an error occurred appending the path to the URI


Copyright © 2013. All Rights Reserved.