com.atlassian.bamboo.rest.util
Class RESTCall

java.lang.Object
  extended by com.atlassian.bamboo.rest.util.RESTCall
Direct Known Subclasses:
Delete, Get, Post, Put

public abstract class RESTCall
extends java.lang.Object


Constructor Summary
protected RESTCall(org.apache.commons.httpclient.HttpMethod method)
           
 
Method Summary
 void addRequestHeader(java.lang.String key, java.lang.String value)
           
protected  void assertExecuted()
           
protected  void assertNotExecuted()
           
 void execute()
           
protected abstract  java.lang.String getAction()
          Returns the HTTP action (POST/GET/HEAD/etc)
 java.io.InputStream getResponseAsStream()
           
 byte[] getResponseBody()
          Returns the response body as a byte array.
 int getStatusCode()
           
 java.net.URI getURI()
           
protected  void marshal(java.lang.Object obj, java.io.OutputStream out)
           
 void release()
          Releases the resources held by the underlying HTTP request.
 void setBasicCredentials(java.lang.String username, java.lang.String password)
          Configured this call to use Basic HTTP Authentication using the specified username and password.
 void setClientProxy()
           
 void setMarshalledClasses(java.lang.Class... classes)
           
<T> T
unmarshal(java.lang.Class<T> responseType)
           
protected  java.lang.Object unmarshal(java.io.InputStream in)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RESTCall

protected RESTCall(org.apache.commons.httpclient.HttpMethod method)
Method Detail

setMarshalledClasses

public void setMarshalledClasses(java.lang.Class... classes)
                          throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

getAction

protected abstract java.lang.String getAction()
Returns the HTTP action (POST/GET/HEAD/etc)

Returns:

marshal

protected void marshal(java.lang.Object obj,
                       java.io.OutputStream out)
                throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

unmarshal

protected java.lang.Object unmarshal(java.io.InputStream in)
                              throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

unmarshal

public <T> T unmarshal(java.lang.Class<T> responseType)
            throws java.io.IOException,
                   javax.xml.bind.JAXBException
Throws:
java.io.IOException
javax.xml.bind.JAXBException

assertExecuted

protected void assertExecuted()

assertNotExecuted

protected void assertNotExecuted()

setBasicCredentials

public void setBasicCredentials(java.lang.String username,
                                java.lang.String password)
Configured this call to use Basic HTTP Authentication using the specified username and password. This eliminates the need to manually encode the Basic authentication string in Authorization request header.

Parameters:
username -
password -

setClientProxy

public void setClientProxy()

addRequestHeader

public void addRequestHeader(java.lang.String key,
                             java.lang.String value)

execute

public void execute()

getStatusCode

public int getStatusCode()

getResponseBody

public byte[] getResponseBody()
Returns the response body as a byte array.

This assertion must be called after the call has been executed sucessfully, or it will fail the test.

Returns:
the response body as a byte array.

getResponseAsStream

public java.io.InputStream getResponseAsStream()
                                        throws java.io.IOException
Throws:
java.io.IOException

getURI

public java.net.URI getURI()
                    throws org.apache.commons.httpclient.URIException
Throws:
org.apache.commons.httpclient.URIException

release

public void release()
Releases the resources held by the underlying HTTP request. Always call this method (e.g. in a finally clause) to ensure all HTTP connections are properly closed.



Copyright © 2012 Atlassian. All Rights Reserved.