Package com.atlassian.bamboo.rest.utils
Class RESTCall<M extends org.apache.http.client.methods.HttpRequestBase>
- java.lang.Object
-
- com.atlassian.bamboo.rest.utils.RESTCall<M>
-
- All Implemented Interfaces:
AutoCloseable
public abstract class RESTCall<M extends org.apache.http.client.methods.HttpRequestBase> extends Object implements AutoCloseable
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRequestHeader(String key, String value)
protected void
assertExecuted()
protected void
assertNotExecuted()
protected void
beforeExecute()
void
close()
void
execute()
static org.apache.http.client.HttpClient
getHttpClientWithTimeout(String scheme)
M
getMethod()
InputStream
getResponseAsStream()
String
getResponseAsString()
byte[]
getResponseBody()
Returns the response body as a byte array.com.google.common.collect.Multimap<String,String>
getResponseHeaders()
int
getStatusCode()
org.apache.http.StatusLine
getStatusLine()
URI
getURI()
protected void
marshal(Object obj, OutputStream out)
void
release()
Releases the resources held by the underlying HTTP request.void
setBasicCredentials(String username, String password)
Configured this call to use Basic HTTP Authentication using the specified username and password.void
setMarshalledClasses(Class... classes)
String
toString()
protected Object
unmarshal(InputStream in)
<T> T
unmarshal(Class<T> responseType)
-
-
-
Method Detail
-
getHttpClientWithTimeout
public static org.apache.http.client.HttpClient getHttpClientWithTimeout(String scheme)
- Parameters:
scheme
- target scheme for the REST call, e.g. 'http' or 'https', required to properly set up proxy settings
-
setMarshalledClasses
public void setMarshalledClasses(Class... classes) throws javax.xml.bind.JAXBException
- Throws:
javax.xml.bind.JAXBException
-
marshal
protected void marshal(Object obj, OutputStream out) throws javax.xml.bind.JAXBException
- Throws:
javax.xml.bind.JAXBException
-
unmarshal
protected Object unmarshal(InputStream in) throws javax.xml.bind.JAXBException
- Throws:
javax.xml.bind.JAXBException
-
unmarshal
public <T> T unmarshal(Class<T> responseType) throws IOException, javax.xml.bind.JAXBException
- Throws:
IOException
javax.xml.bind.JAXBException
-
setBasicCredentials
public void setBasicCredentials(String username, 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
-
-
execute
public void execute()
-
beforeExecute
protected void beforeExecute()
-
getStatusCode
public int getStatusCode()
-
getStatusLine
public org.apache.http.StatusLine getStatusLine()
-
getResponseBody
public byte[] getResponseBody()
Returns the response body as a byte array.This assertion must be called after the call has been executed successfully, or it will fail the test.
- Returns:
- the response body as a byte array.
-
getResponseAsStream
public InputStream getResponseAsStream()
-
getResponseAsString
public String getResponseAsString()
-
getURI
public URI getURI()
-
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.
-
assertExecuted
protected void assertExecuted()
-
assertNotExecuted
protected void assertNotExecuted()
-
getMethod
public M getMethod()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
-