public class HttpClientRequest<T extends Request<?,?>,RESP extends Response> extends Object implements Request<HttpClientRequest<?,?>,HttpClientResponse>
Request.MethodType| Modifier and Type | Field and Description |
|---|---|
protected org.apache.http.client.protocol.HttpClientContext |
httpClientContext |
| Constructor and Description |
|---|
HttpClientRequest(org.apache.http.impl.client.CloseableHttpClient httpClient,
org.apache.http.client.protocol.HttpClientContext httpClientContext,
Request.MethodType initialMethodType,
String initialUrl) |
| Modifier and Type | Method and Description |
|---|---|
HttpClientRequest |
addBasicAuthentication(String hostname,
String username,
String password)
Adds basic authentication to the request.
|
HttpClientRequest |
addHeader(String headerName,
String headerValue)
Adds the specified header to the request, not overwriting any previous value.
|
HttpClientRequest |
addRequestParameters(String... params)
Sets parameters of the request.
|
String |
execute()
Executes a request and if response is successful, returns response as a string.
|
void |
execute(ResponseHandler<? super HttpClientResponse> responseHandler)
Executes the request.
|
<RET> RET |
executeAndReturn(ReturningResponseHandler<? super HttpClientResponse,RET> responseHandler)
Executes the request and returns a result value.
|
Map<String,List<String>> |
getHeaders() |
HttpClientRequest |
setConnectionTimeout(int connectionTimeout)
Setting connection timeout in milliseconds.
|
HttpClientRequest |
setEntity(Object entity)
Set an entity as the request body
|
HttpClientRequest |
setFiles(List<RequestFilePart> requestBodyFiles)
Sets file parts of the request.
|
HttpClientRequest |
setFollowRedirects(boolean follow)
Sets whether the request should transparently follow a redirect from the server.
|
HttpClientRequest |
setHeader(String headerName,
String headerValue)
Sets the specified header to the request, overwriting any previous value.
|
HttpClientRequest |
setRequestBody(String requestBody)
Sets the body of the request.
|
HttpClientRequest |
setRequestBody(String requestBodyString,
String contentTypeString)
Sets the body of the request.
|
HttpClientRequest |
setSoTimeout(int soTimeout)
Setting socket timeout in milliseconds.
|
HttpClientRequest |
setUrl(String url) |
protected final org.apache.http.client.protocol.HttpClientContext httpClientContext
public HttpClientRequest(org.apache.http.impl.client.CloseableHttpClient httpClient,
org.apache.http.client.protocol.HttpClientContext httpClientContext,
Request.MethodType initialMethodType,
String initialUrl)
public String execute() throws ResponseException
RequestResponse.getResponseBodyAsString()execute in interface Request<HttpClientRequest<?,?>,HttpClientResponse>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 specifiedpublic void execute(ResponseHandler<? super HttpClientResponse> responseHandler) throws ResponseException
Requestexecute in interface Request<HttpClientRequest<?,?>,HttpClientResponse>responseHandler - Callback handler of the response.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 specifiedpublic <RET> RET executeAndReturn(ReturningResponseHandler<? super HttpClientResponse,RET> responseHandler) throws ResponseException
RequestexecuteAndReturn in interface Request<HttpClientRequest<?,?>,HttpClientResponse>responseHandler - Callback handler of the response.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 specifiedpublic Map<String,List<String>> getHeaders()
getHeaders in interface Request<HttpClientRequest<?,?>,HttpClientResponse>public HttpClientRequest addBasicAuthentication(String hostname, String username, String password)
RequestaddBasicAuthentication in interface Request<HttpClientRequest<?,?>,HttpClientResponse>username - The user namepassword - The passwordpublic HttpClientRequest setConnectionTimeout(int connectionTimeout)
RequestsetConnectionTimeout in interface Request<HttpClientRequest<?,?>,HttpClientResponse>connectionTimeout - The timeout in millisecondspublic HttpClientRequest setSoTimeout(int soTimeout)
RequestsetSoTimeout in interface Request<HttpClientRequest<?,?>,HttpClientResponse>soTimeout - the timeout in millisecondspublic HttpClientRequest setUrl(String url)
setUrl in interface Request<HttpClientRequest<?,?>,HttpClientResponse>url - the url to requestpublic HttpClientRequest setRequestBody(String requestBody)
RequestRequest.MethodType.POST and Request.MethodType.PUT can have a request body.setRequestBody in interface Request<HttpClientRequest<?,?>,HttpClientResponse>requestBody - the body of the requestpublic HttpClientRequest setRequestBody(String requestBodyString, String contentTypeString)
RequestRequest.MethodType.POST and Request.MethodType.PUT can have a request body.setRequestBody in interface Request<HttpClientRequest<?,?>,HttpClientResponse>requestBodyString - the body of the requestcontentTypeString - the contentType of the requestpublic HttpClientRequest setFiles(List<RequestFilePart> requestBodyFiles)
RequestRequest.MethodType.POST and Request.MethodType.PUT can have file parts.setFiles in interface Request<HttpClientRequest<?,?>,HttpClientResponse>requestBodyFiles - the file parts, cannot be null.public HttpClientRequest addRequestParameters(String... params)
RequestRequest.MethodType.POST can 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, etcaddRequestParameters in interface Request<HttpClientRequest<?,?>,HttpClientResponse>params - parameters of the request in as name, value pairspublic HttpClientRequest addHeader(String headerName, String headerValue)
RequestaddHeader in interface Request<HttpClientRequest<?,?>,HttpClientResponse>headerName - the header's nameheaderValue - the header's valueRequestFactory.supportsHeader()public HttpClientRequest setHeader(String headerName, String headerValue)
RequestsetHeader in interface Request<HttpClientRequest<?,?>,HttpClientResponse>headerName - the header's nameheaderValue - the header's valueRequestFactory.supportsHeader()public HttpClientRequest setFollowRedirects(boolean follow)
RequestsetFollowRedirects in interface Request<HttpClientRequest<?,?>,HttpClientResponse>follow - set this to false to have the request not transparently follow redirects.public HttpClientRequest setEntity(Object entity)
RequestsetEntity in interface Request<HttpClientRequest<?,?>,HttpClientResponse>entity - the request entity to be marshalled, not nullCopyright © 2015 Atlassian. All rights reserved.