public abstract class AbstractHttpRequest extends Object implements HttpRequest
HttpRequest interface.
This abstract class is not part of the public API and should not be used publicly.
| Modifier and Type | Field and Description |
|---|---|
protected HttpRequestBody |
body
The request body.
|
protected List<Cookie> |
cookies
Cookie elements.
|
protected Map<String,HttpHeader> |
headers
HTTP Headers.
|
protected Map<String,HttpParameter> |
queryParams
Request parameters.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpRequest(HttpUrl endpoint,
HttpMethod method) |
| Modifier and Type | Method and Description |
|---|---|
HttpRequest |
acceptGzip()
Add
Accept-Encoding header with "gzip, deflate" value. |
HttpRequest |
acceptJson()
Add header to specify that accept type
is
"application/json". |
HttpRequest |
acceptLanguage(String lang)
Add
Accept-Language header. |
HttpRequest |
acceptXml()
Add header to specify that accept type
is
"application/xml". |
HttpRequest |
addAcceptEncoding(String encoding)
Add
Accept-Encoding header. |
HttpRequest |
addCookie(Cookie cookie)
Add cookie to http request.
|
HttpRequest |
addCookie(String name,
String value)
Add cookie to http request.
|
HttpRequest |
addCsrfToken(String token)
Add CSRF Token to http header (
X-Csrf-Token header). |
HttpRequest |
addHeader(HttpHeader header)
Add header.
|
HttpRequest |
addHeader(String name,
String value)
Add header.
|
HttpRequest |
addIfMatch(String etag)
Add
If-Match header with expected value. |
HttpRequest |
addIfModifiedSince(Date date)
Add
If-Modified-Since value with expected date (date will be translated
as GMT raw). |
HttpRequest |
addIfNoneMatch(String etag)
Add
If-None-Match header with expected value. |
HttpRequest |
addIfUnmodifiedSince(Date date)
Add
If-Unmodified-Since value with expected date (date will be translated
as GMT raw). |
HttpRequest |
addOrigin(String origin)
Add
Origin header. |
HttpRequest |
addQueryParam(String name,
String value)
Add query parameters: a query parameter is a parameter that will
follow the
? character in the request URL. |
HttpRequest |
addQueryParams(HttpParameter parameter,
HttpParameter... parameters)
Add collection of query parameters: a query parameter is a parameter that will
follow the
? character in the request URL. |
HttpRequest |
addReferer(String referer)
Add
Referer header. |
HttpRequest |
addXHttpMethodOverride(String method)
Add
X-Http-Method-Override value with HTTP verb to override. |
HttpRequest |
asFormUrlEncoded()
Add header to specify that content type
is
"application/x-www-form-urlencoded". |
HttpRequest |
asJson()
Add header to specify that content type
is
"application/json". |
HttpRequest |
asXml()
Add header to specify that content type
is
"application/xml". |
HttpRequest |
asXmlHttpRequest()
Most library (such as jQuery) add automatically header
named "X-Requested-With" with value "XMLHttpRequest", this
method add this header and can be used to simulate ajax
call.
|
protected abstract HttpResponse |
doExecute()
Execute request.
|
HttpResponse |
execute()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpResponse |
executeJson()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpResponse |
executeXml()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpUrl |
getEndpoint()
Request URL.
|
HttpMethod |
getMethod()
Return http request method.
|
protected boolean |
hasBody()
Check if the request have a body content (form parameters or request body value).
|
HttpRequest |
overrideDelete()
Add
X-Http-Method-Override value with DELETE value. |
HttpRequest |
overridePut()
Add @{code X-Http-Method-Override} value with
PUT value. |
HttpRequest |
setBody(HttpRequestBody body)
Set request body.
|
HttpRequest |
withUserAgent(String userAgent)
Add
User-Agent header to http request. |
protected final Map<String,HttpParameter> queryParams
? character in the URL.protected HttpRequestBody body
protected final Map<String,HttpHeader> headers
protected AbstractHttpRequest(HttpUrl endpoint, HttpMethod method)
public HttpUrl getEndpoint()
HttpRequestgetEndpoint in interface HttpRequestpublic HttpMethod getMethod()
HttpRequestgetMethod in interface HttpRequestpublic HttpRequest addHeader(String name, String value)
HttpRequestaddHeader in interface HttpRequestname - Header name.value - Header value.HttpRequest.addHeader(HttpHeader)public HttpRequest addHeader(HttpHeader header)
HttpRequestaddHeader in interface HttpRequestheader - The header.public HttpRequest asXmlHttpRequest()
HttpRequestasXmlHttpRequest in interface HttpRequestHttpHeaders.REQUESTED_WITH,
HttpHeaders.XML_HTTP_REQUESTpublic HttpRequest acceptLanguage(String lang)
HttpRequestAccept-Language header.acceptLanguage in interface HttpRequestlang - Accepted languages.HttpHeaders.ACCEPT_LANGUAGE,
https://tools.ietf.org/html/rfc7231#section-5.3.5public HttpRequest addAcceptEncoding(String encoding)
HttpRequestAccept-Encoding header.addAcceptEncoding in interface HttpRequestencoding - Encoding value.HttpHeaders.ACCEPT_ENCODING,
https://tools.ietf.org/html/rfc7231#section-5.3.4public HttpRequest acceptGzip()
HttpRequestAccept-Encoding header with "gzip, deflate" value.acceptGzip in interface HttpRequestHttpHeaders.ACCEPT_ENCODING,
https://tools.ietf.org/html/rfc7231#section-5.3.4,
HttpRequest.addAcceptEncoding(String)public HttpRequest addOrigin(String origin)
HttpRequestOrigin header.addOrigin in interface HttpRequestorigin - Origin value.HttpHeaders.ORIGIN,
https://tools.ietf.org/html/rfc6454public HttpRequest addReferer(String referer)
HttpRequestReferer header.addReferer in interface HttpRequestreferer - Referer value.HttpHeaders.REFERER,
https://tools.ietf.org/html/rfc7231#section-5.5.2public HttpRequest addIfNoneMatch(String etag)
HttpRequestIf-None-Match header with expected value.
This header should work with ETag header sent by server
response.addIfNoneMatch in interface HttpRequestetag - ETag value.HttpHeaders.IF_NONE_MATCH,
https://tools.ietf.org/html/rfc7232#section-3.2public HttpRequest addIfMatch(String etag)
HttpRequestIf-Match header with expected value.
This header should work with ETag header sent by server
response.addIfMatch in interface HttpRequestetag - ETag value.HttpHeaders.IF_MATCH,
https://tools.ietf.org/html/rfc7232#section-3.1public HttpRequest addIfModifiedSince(Date date)
HttpRequestIf-Modified-Since value with expected date (date will be translated
as GMT raw).addIfModifiedSince in interface HttpRequestdate - Date.HttpHeaders.IF_MODIFIED_SINCE,
https://tools.ietf.org/html/rfc7232#section-3.3public HttpRequest addIfUnmodifiedSince(Date date)
HttpRequestIf-Unmodified-Since value with expected date (date will be translated
as GMT raw).addIfUnmodifiedSince in interface HttpRequestdate - Date.HttpHeaders.IF_UNMODIFIED_SINCE,
https://tools.ietf.org/html/rfc7232#section-3.4public HttpRequest withUserAgent(String userAgent)
HttpRequestUser-Agent header to http request.withUserAgent in interface HttpRequestuserAgent - User-Agent value.HttpHeaders.USER_AGENT,
https://tools.ietf.org/html/rfc2616#section-14.43public HttpRequest asJson()
HttpRequest"application/json".asJson in interface HttpRequestHttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON,
https://www.w3.org/Protocols/rfc1341/4_Content-Type.htmlpublic HttpRequest asXml()
HttpRequest"application/xml".asXml in interface HttpRequestHttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML,
https://www.w3.org/Protocols/rfc1341/4_Content-Type.htmlpublic HttpRequest asFormUrlEncoded()
HttpRequest"application/x-www-form-urlencoded".asFormUrlEncoded in interface HttpRequestMediaType.APPLICATION_FORM_URL_ENCODED,
https://tools.ietf.org/html/draft-hoehrmann-urlencoded-01public HttpRequest addQueryParam(String name, String value)
HttpRequest? character in the request URL.addQueryParam in interface HttpRequestname - Parameter name.value - Parameter value.public HttpRequest addQueryParams(HttpParameter parameter, HttpParameter... parameters)
HttpRequest? character in the request URL.addQueryParams in interface HttpRequestparameter - Parameter.parameters - Optional next parameters.public HttpRequest setBody(HttpRequestBody body)
HttpRequest"POST", "PUT" or "PATCH" request only, otherwise
it will throw UnsupportedOperationException exception.setBody in interface HttpRequestbody - Body request.public HttpRequest acceptJson()
HttpRequest"application/json".acceptJson in interface HttpRequestHttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON,
https://tools.ietf.org/html/rfc7231#section-5.3.2public HttpRequest acceptXml()
HttpRequest"application/xml".acceptXml in interface HttpRequestHttpHeaders.ACCEPT,
MediaType.APPLICATION_XML,
https://tools.ietf.org/html/rfc7231#section-5.3.2public HttpRequest addXHttpMethodOverride(String method)
HttpRequestX-Http-Method-Override value with HTTP verb to override.
This method is generally used with POST request to override
PUT or DELETE requests.addXHttpMethodOverride in interface HttpRequestmethod - Http method to override.HttpHeaders.X_HTTP_METHOD_OVERRIDEpublic HttpRequest addCsrfToken(String token)
HttpRequestX-Csrf-Token header).addCsrfToken in interface HttpRequesttoken - Token value.HttpHeaders.X_CSRF_TOKENpublic HttpRequest overridePut()
HttpRequestPUT value.overridePut in interface HttpRequestHttpHeaders.X_HTTP_METHOD_OVERRIDE,
HttpRequest.addXHttpMethodOverride(String)public HttpRequest overrideDelete()
HttpRequestX-Http-Method-Override value with DELETE value.overrideDelete in interface HttpRequestHttpHeaders.X_HTTP_METHOD_OVERRIDE,
HttpRequest.addXHttpMethodOverride(String)public HttpRequest addCookie(Cookie cookie)
HttpRequestaddCookie in interface HttpRequestcookie - Cookie.HttpHeaders.COOKIE,
https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Cookie,
https://tools.ietf.org/html/rfc6265#section-5.4public HttpRequest addCookie(String name, String value)
HttpRequestaddCookie in interface HttpRequestname - Cookie name.value - Cookie value.HttpHeaders.COOKIE,
HttpRequest.addCookie(Cookie),
https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Cookie,
https://tools.ietf.org/html/rfc6265#section-5.4public HttpResponse execute()
HttpRequestexecute in interface HttpRequestpublic HttpResponse executeJson()
HttpRequest
This method automatically add json header (i.e
methods HttpRequest.asJson() and HttpRequest.acceptJson() will be automatically
be called before execution).
executeJson in interface HttpRequestHttpRequest.acceptJson(),
HttpRequest.asJson()public HttpResponse executeXml()
HttpRequest
This method automatically add xml header (i.e
methods HttpRequest.asXml() and HttpRequest.acceptXml() will be automatically
called before execution).
executeXml in interface HttpRequestHttpRequest.acceptXml(),
HttpRequest.asXml()protected boolean hasBody()
true if request has a body, false otherwise.protected abstract HttpResponse doExecute() throws Exception
HttpClientException.Exception - If an error occurred.Copyright © 2019. All rights reserved.