Package com.atlassian.sal.api.net
Interface Request<T extends Request<?,?>,RESP extends Response>
- Type Parameters:
T- the type of request used for method chaining
public interface Request<T extends Request<?,?>,RESP extends Response>
Interface Request represents a request to retrieve data. To execute a request call
execute(ResponseHandler).- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumRepresents type of network request -
Method Summary
Modifier and TypeMethodDescriptionaddBasicAuthentication(String hostname, String username, String password) Adds basic authentication to the request.Adds the specified header to the request, not overwriting any previous value.addRequestParameters(String... params) Sets parameters of the request.execute()Executes a request and if response is successful, returns response as a string.voidexecute(ResponseHandler<? super RESP> responseHandler) Executes the request.<RET> RETexecuteAndReturn(ReturningResponseHandler<? super RESP, RET> responseHandler) Executes the request and returns a result value.setConnectionTimeout(int connectionTimeout) Setting connection timeout in milliseconds.Set an entity as the request bodysetFiles(List<RequestFilePart> files) Sets file parts of the request.setFollowRedirects(boolean follow) Sets whether the request should transparently follow a redirect from the server.Sets the specified header to the request, overwriting any previous value.setRequestBody(String requestBody) Sets the body of the request.setRequestBody(String requestBody, String contentType) Sets the body of the request.setSoTimeout(int soTimeout) Setting socket timeout in milliseconds.
-
Method Details
-
setConnectionTimeout
Setting connection timeout in milliseconds.- Parameters:
connectionTimeout- The timeout in milliseconds- Returns:
- a reference to this object.
-
setSoTimeout
Setting socket timeout in milliseconds.- Parameters:
soTimeout- the timeout in milliseconds- Returns:
- a reference to this object.
-
setUrl
- Parameters:
url- the url to request- Returns:
- a reference to this object.
-
setRequestBody
Sets the body of the request. In default implementation only requests of typeRequest.MethodType.POSTandRequest.MethodType.PUTcan have a request body.- Parameters:
requestBody- the body of the request- Returns:
- a reference to this object.
-
setRequestBody
Sets the body of the request. In default implementation only requests of typeRequest.MethodType.POSTandRequest.MethodType.PUTcan have a request body.- Parameters:
requestBody- the body of the requestcontentType- the contentType of the request- Returns:
- a reference to this object.
-
setFiles
Sets file parts of the request. File parts can only be added if the request body is empty. Only requests of typeRequest.MethodType.POSTandRequest.MethodType.PUTcan have file parts.- Parameters:
files- the file parts, cannot be null.- Returns:
- a reference to this object.
- Throws:
IllegalArgumentException- if the method of this request is not a POST or PUT or files is NULL.IllegalStateException- if the request body for this request has already been set.- Since:
- 2.6
-
setEntity
Set an entity as the request body- Parameters:
entity- the request entity to be marshalled, not null- Returns:
- this Request object
-
addRequestParameters
Sets parameters of the request. In default implementation only requests of typeRequest.MethodType.POSTcan have parameters. For other requests include parameters in url. This method accepts an even number of arguments, in form of name, value, name, value, name, value, etc- Parameters:
params- parameters of the request in as name, value pairs- Returns:
- a reference to this object.
-
addBasicAuthentication
Adds basic authentication to the request.- Parameters:
username- The user namepassword- The password- Returns:
- a reference to this object.
-
addHeader
Adds the specified header to the request, not overwriting any previous value. Support for this operation is optional.- Parameters:
headerName- the header's nameheaderValue- the header's value- Returns:
- a reference to this object
- See Also:
-
setHeader
Sets the specified header to the request, overwriting any previous value. Support for this operation is optional.- Parameters:
headerName- the header's nameheaderValue- the header's value- Returns:
- a reference to this object
- See Also:
-
setFollowRedirects
Sets whether the request should transparently follow a redirect from the server. The default behavior is that when a response is received with a status code in the 300s, a new request is made using the location header of the response without notifying the client. Set this to false to turn this behavior off.- Parameters:
follow- set this to false to have the request not transparently follow redirects.- Returns:
- a reference to this object.
-
getHeaders
- Returns:
- an immutable Map of headers added to the request so far
- Since:
- 2.1
-
execute
Executes the request.- Parameters:
responseHandler- Callback handler of the response.- Throws:
ResponseProtocolException- If the server returned a malformed responseResponseTimeoutException- If a connection timeout or read timeout occurredResponseTransportException- If an I/O error occurred in request transportResponseException- For all errors not otherwise specified
-
execute
Executes a request and if response is successful, returns response as a string. @seeResponse.getResponseBodyAsString()- Returns:
- response as String
- Throws:
ResponseStatusException- If the server returned a response that contained an error codeResponseProtocolException- If the server returned a malformed responseResponseTimeoutException- If a connection timeout or read timeout occurredResponseTransportException- If an I/O error occurred in request transportResponseException- For all errors not otherwise specified
-
executeAndReturn
<RET> RET executeAndReturn(ReturningResponseHandler<? super RESP, RET> responseHandler) throws ResponseExceptionExecutes the request and returns a result value.- Parameters:
responseHandler- Callback handler of the response.- Throws:
ResponseProtocolException- If the server returned a malformed responseResponseTimeoutException- If a connection timeout or read timeout occurredResponseTransportException- If an I/O error occurred in request transportResponseException- For all errors not otherwise specified- Since:
- v2.2.0
-