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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRequestHeader
(String key, String value) protected void
protected void
protected void
void
close()
void
execute()
static org.apache.http.client.HttpClient
getHttpClientWithTimeout
(String scheme) byte[]
Returns the response body as a byte array.int
org.apache.http.StatusLine
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) toString()
protected Object
unmarshal
(InputStream in) <T> T
-
Constructor Details
-
RESTCall
-
RESTCall
-
-
Method Details
-
getHttpClientWithTimeout
- Parameters:
scheme
- target scheme for the REST call, e.g. 'http' or 'https', required to properly set up proxy settings
-
setMarshalledClasses
- Throws:
javax.xml.bind.JAXBException
-
marshal
- Throws:
javax.xml.bind.JAXBException
-
unmarshal
- Throws:
javax.xml.bind.JAXBException
-
unmarshal
- Throws:
IOException
javax.xml.bind.JAXBException
-
setBasicCredentials
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
-
-
addRequestHeader
-
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
-
getResponseAsString
-
getURI
-
getResponseHeaders
-
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
-
toString
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-