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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRequestHeader(String key, String value) protected voidprotected voidprotected voidvoidclose()voidexecute()static org.apache.http.client.HttpClientgetHttpClientWithTimeout(String scheme) byte[]Returns the response body as a byte array.intorg.apache.http.StatusLinegetURI()protected voidmarshal(Object obj, OutputStream out) voidrelease()Releases the resources held by the underlying HTTP request.voidsetBasicCredentials(String username, String password) Configured this call to use Basic HTTP Authentication using the specified username and password.voidsetBearerToken(String token) voidsetMarshalledClasses(Class... classes) toString()protected Objectunmarshal(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:
jakarta.xml.bind.JAXBException
-
marshal
- Throws:
jakarta.xml.bind.JAXBException
-
unmarshal
- Throws:
jakarta.xml.bind.JAXBException
-
unmarshal
- Throws:
IOExceptionjakarta.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-
-
setBearerToken
-
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:
closein interfaceAutoCloseable
-