Package de.xima.fc.http
Class HttpRequestBuilder
- java.lang.Object
 - 
- de.xima.fc.http.HttpRequestBuilder
 
 
- 
- Direct Known Subclasses:
 HttpPostRequestBuilder
public class HttpRequestBuilder extends Object
Builder for preparing and sending an HTTP request.- Since:
 - 7.0.1
 - Author:
 - XIMA MEDIA GmbH
 
 
- 
- 
Constructor Summary
Constructors Constructor Description HttpRequestBuilder(EHttpVerb method, String uri)HttpRequestBuilder(EHttpVerb method, URI uri)HttpRequestBuilder(String method, String uri)HttpRequestBuilder(String method, String uri, EHttpRequestType requestType)HttpRequestBuilder(String method, URI uri) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpRequestBuilderaddBinayData(String elementName, byte[] data, String filename, String mimeType)Deprecated.HttpRequestBuilderaddBinayData(String elementName, byte[] data, String filename, String mimeType, Charset charset)Deprecated.HttpRequestBuilderaddHeader(String name, String value)Adds a header field to the HTTP request.HttpRequestBuilderaddParameter(String name, String value)Deprecated.HttpRequestBuilderaddParameter(String name, String value, org.apache.http.entity.ContentType contentType)Deprecated.org.apache.http.client.methods.CloseableHttpResponsebuild()Deprecated.Usebuild(Charset).HttpResponseWrapperbuild(Charset outputCharset)Performs the HTTP request to the server and returns the response.IHttpBodyBuildercreateBuilder(EHttpRequestType type, boolean hasFiles)Creates an builder for the request typeICustomBodyDataBuilder<CustomBodyDataBuilder>customBuilder()IFileBodyBuilder<FileBodyBuilder>fileBuilder()IFormDataBodyBuilderformDataBuilder()URIgetUri()StringgetUrl()IMultipartBodyBuildermultipartBuilder()HttpRequestBuildersetBasicAuthLogin(String login)Sets the login name for performing an HTTP basic authentication.HttpRequestBuildersetBasicAuthPassword(String password)Sets the password for performing an HTTP basic authentication.HttpRequestBuildersetBody(org.apache.http.HttpEntity body)Sets the body content of the HTTP request.HttpRequestBuildersetInputCharset(Charset inputCharset)Sets the request character encoding.HttpRequestBuildersetProxyServer(FcHttpRequestProps.ProxyProps proxyConfig)Sets the following proxy server configuration parameters if defined inside theFcHttpRequestProps.ProxyPropsobject: proxy server host proxy server port login for a proxy server authentication password for a proxy server authenticationHttpRequestBuildersetProxyServerAuth(FcHttpRequestProps.ProxyAuthProps proxyAuth)Sets the login name and password of the proxy server, if one is used.HttpRequestBuildersetProxyServerAuthLogin(String login)Sets the login name for the proxy server, if one is used.HttpRequestBuildersetProxyServerAuthPassword(String password)Sets the password for the proxy server, if one is used.HttpRequestBuildersetProxyServerHost(String host)Sets the proxy server host.HttpRequestBuildersetProxyServerPort(int port)Sets the proxy server port.voidsetUri(URI uri)HttpRequestBuildersupportsMessageBody(boolean supportsMessageBody)IUrlDataBuilder<UrlDataBuilder>urliBuilder()booleanuseBasicAuthentication()booleanuseProxyServer()booleanuseProxyServerAuthentication()HttpRequestBuilderwithAllowInvalidCertificates(boolean allowInvalidCertificates)Sets whether to allow invalid certificates.HttpRequestBuilderwithConnectTimeout(Duration connectTimeout)Sets the connect timeout for the request.HttpRequestBuilderwithDisabledRedirectHandling(boolean disableRedirectHandling)Enables/Disables automatic redirect handling.HttpRequestBuilderwithReadTimeout(Duration readTimeout)Sets the read timeout for the request. 
 - 
 
- 
- 
Constructor Detail
- 
HttpRequestBuilder
public HttpRequestBuilder(@Nonnull EHttpVerb method, @Nonnull String uri) throws URISyntaxException- Parameters:
 method- HTTP method to use.uri- The request URL, must not benull- Throws:
 URISyntaxException- When the given string is not a valid URI.
 
- 
HttpRequestBuilder
public HttpRequestBuilder(@Nonnull EHttpVerb method, @Nonnull URI uri)- Parameters:
 method- HTTP method to use.uri- The request URL.
 
- 
HttpRequestBuilder
public HttpRequestBuilder(@Nonnull String method, @Nonnull String uri) throws URISyntaxException- Parameters:
 method- HTTP method to use.uri- The request URL, must not benull- Throws:
 URISyntaxException- When the given string is not a valid URI.
 
- 
HttpRequestBuilder
public HttpRequestBuilder(@Nonnull String method, @Nonnull String uri, EHttpRequestType requestType) throws URISyntaxException- Parameters:
 method- HTTP method to use.uri- The request URL, must not benullrequestType- The request type to use- Throws:
 URISyntaxException- When the given string is not a valid URI.
 
 - 
 
- 
Method Detail
- 
addBinayData
@Deprecated @Nonnull public HttpRequestBuilder addBinayData(@Nonnull String elementName, @Nullable byte[] data, @Nonnull String filename, @Nonnull String mimeType)
Deprecated.- Parameters:
 elementName- Name of the file.data- Binary data of the file.filename- Name of the file.mimeType- Mime type of the file.- Returns:
 - This builder for chaining method calls.
 
 
- 
addBinayData
@Deprecated @Nonnull public HttpRequestBuilder addBinayData(@Nonnull String elementName, @Nullable byte[] data, @Nonnull String filename, @Nonnull String mimeType, @Nonnull Charset charset)
Deprecated.- Parameters:
 elementName- Name of the file.data- Binary data of the file.filename- Name of the file.mimeType- Mime type of the file.charset- Charset of the file content.- Returns:
 - This builder for chaining method calls.
 
 
- 
addHeader
@Nonnull public HttpRequestBuilder addHeader(@Nonnull String name, @Nonnull String value)
Adds a header field to the HTTP request. Note that it is possible to have multiple header fields with the same name.- Parameters:
 name- Name of the header.value- Value of the header.- Returns:
 - This builder for chaining method calls.
 
 
- 
addParameter
@Deprecated @Nonnull public HttpRequestBuilder addParameter(@Nonnull String name, @Nonnull String value)
Deprecated.- Parameters:
 name- Name of the parameter to add.value- Value of the parameter to add.- Returns:
 - This builder for chaining method calls.
 
 
- 
addParameter
@Deprecated @Nonnull public HttpRequestBuilder addParameter(@Nonnull String name, @Nonnull String value, @Nonnull org.apache.http.entity.ContentType contentType)
Deprecated.- Parameters:
 name- Name of the parameter to add.value- Value of the parameter to add.contentType- Content type of the parameter.- Returns:
 - This builder for chaining method calls.
 
 
- 
build
@Deprecated @Nonnull public org.apache.http.client.methods.CloseableHttpResponse build() throws IOException
Deprecated.Usebuild(Charset).Performs the HTTP request to the server and returns the response.- Returns:
 - The response that was obtained from the server.
 - Throws:
 IOException- When a network failure occurred and data could not be sent to the remote host or the response could not be received.
 
- 
build
@Nonnull public HttpResponseWrapper build(Charset outputCharset) throws IOException
Performs the HTTP request to the server and returns the response.- Parameters:
 outputCharset- Charset used for the response content. Ifnull, a default charset is used.- Returns:
 - The response that was obtained from the server.
 - Throws:
 IOException- When a network failure occurred and data could not be sent to the remote host or the response could not be received.
 
- 
getUrl
@Nonnull public String getUrl()
- Returns:
 - The request URL
 
 
- 
getUri
public URI getUri()
- Returns:
 - The request URI
 
 
- 
setUri
public void setUri(URI uri)
- Parameters:
 uri- The request URI to set
 
- 
formDataBuilder
public IFormDataBodyBuilder formDataBuilder()
- Returns:
 - A builder for setting a form data body on the request (
application/x-www-form-urlencoded). This is a shortcut for callingsetBody(HttpEntity)with the appropriate entity. You must callIFormDataBodyBuilder.build()to add the multipart body to this request. 
 
- 
multipartBuilder
public IMultipartBodyBuilder multipartBuilder()
- Returns:
 - A builder for setting a multipart body on the request (
multipart/form-data). This is a shortcut for callingsetBody(HttpEntity)with the appropriate entity. You must callIHttpBodyBuilder.build()to add the multipart body to this request. 
 
- 
customBuilder
public ICustomBodyDataBuilder<CustomBodyDataBuilder> customBuilder()
- Returns:
 - A builder for custom request body. This is a shortcut for calling 
setBody(HttpEntity)with the appropriate entity. You must callIHttpBodyBuilder.build()to add the body to this request. 
 
- 
fileBuilder
public IFileBodyBuilder<FileBodyBuilder> fileBuilder()
- Returns:
 - A builder for an request body based on an file. This is a shortcut for calling
     
setBody(HttpEntity)with the appropriate entity. You must callIHttpBodyBuilder.build()to add the body to this request. 
 
- 
urliBuilder
public IUrlDataBuilder<UrlDataBuilder> urliBuilder()
- Returns:
 - A builder for an request body based on an file. This is a shortcut for calling 
setUri(URI)with the appropriate data. You must callIHttpBodyBuilder.build()to change the URL of this request. 
 
- 
createBuilder
public IHttpBodyBuilder createBuilder(EHttpRequestType type, boolean hasFiles)
Creates an builder for the request type- Parameters:
 type- the typehasFiles- flag which indicates if files should be transmitted when using the body typeEHttpRequestType.DYNAMIC.- Returns:
 - A builder based on the given parameters
 
 
- 
setBasicAuthLogin
@Nonnull public HttpRequestBuilder setBasicAuthLogin(@Nullable String login)
Sets the login name for performing an HTTP basic authentication.- Parameters:
 login- User name for the basic authentication.- Returns:
 - This builder for chaining method calls.
 
 
- 
setBasicAuthPassword
@Nonnull public HttpRequestBuilder setBasicAuthPassword(@Nullable String password)
Sets the password for performing an HTTP basic authentication.- Parameters:
 password- Password for the basic authentication.- Returns:
 - This builder for chaining method calls.
 
 
- 
setBody
public HttpRequestBuilder setBody(@Nonnull org.apache.http.HttpEntity body)
Sets the body content of the HTTP request.- Parameters:
 body- Data to be transmitted with the request.- Returns:
 - This builder for chaining method calls.
 - See Also:
 formDataBuilder,multipartBuilder
 
- 
setInputCharset
@Nonnull public HttpRequestBuilder setInputCharset(@Nonnull Charset inputCharset)
Sets the request character encoding.- Parameters:
 inputCharset- encoding character set- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServer
@Nonnull public HttpRequestBuilder setProxyServer(@Nullable FcHttpRequestProps.ProxyProps proxyConfig)
Sets the following proxy server configuration parameters if defined inside theFcHttpRequestProps.ProxyPropsobject:- proxy server host
 - proxy server port
 - login for a proxy server authentication
 - password for a proxy server authentication
 
- Parameters:
 proxyConfig- the proxy server configuration- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServerAuth
@Nonnull public HttpRequestBuilder setProxyServerAuth(@Nullable FcHttpRequestProps.ProxyAuthProps proxyAuth)
Sets the login name and password of the proxy server, if one is used.- Parameters:
 proxyAuth- Login name and user name for the proxy.- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServerAuthLogin
@Nonnull public HttpRequestBuilder setProxyServerAuthLogin(@Nullable String login)
Sets the login name for the proxy server, if one is used.- Parameters:
 login- Login name for the proxy- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServerAuthPassword
@Nonnull public HttpRequestBuilder setProxyServerAuthPassword(@Nullable String password)
Sets the password for the proxy server, if one is used.- Parameters:
 password- Password for the proxy- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServerHost
@Nonnull public HttpRequestBuilder setProxyServerHost(@Nullable String host)
Sets the proxy server host.- Parameters:
 host- proxy server host- Returns:
 - This builder for chaining method calls.
 
 
- 
setProxyServerPort
@Nonnull public HttpRequestBuilder setProxyServerPort(int port)
Sets the proxy server port.- Parameters:
 port- proxy server port- Returns:
 - This builder for chaining method calls.
 
 
- 
supportsMessageBody
@Nonnull public HttpRequestBuilder supportsMessageBody(boolean supportsMessageBody)
- Parameters:
 supportsMessageBody- Whether this request supports a message body. When it does not, no body will be set.- Returns:
 - This builder for chaining method calls.
 
 
- 
useBasicAuthentication
public boolean useBasicAuthentication()
- Returns:
 trueif an login and password for basic authentication is set, otherwisetrue
 
- 
useProxyServer
public boolean useProxyServer()
- Returns:
 trueif the host and port for a proxy server use is set, otherwisefalse
 
- 
useProxyServerAuthentication
public boolean useProxyServerAuthentication()
- Returns:
 trueif an login and password for proxy server authentication is set, otherwisefalse
 
- 
withDisabledRedirectHandling
@Nonnull public HttpRequestBuilder withDisabledRedirectHandling(boolean disableRedirectHandling)
Enables/Disables automatic redirect handling.- Parameters:
 disableRedirectHandling-trueorfalse- Returns:
 - This builder for chaining method calls.
 
 
- 
withAllowInvalidCertificates
public HttpRequestBuilder withAllowInvalidCertificates(boolean allowInvalidCertificates)
Sets whether to allow invalid certificates.- Parameters:
 allowInvalidCertificates- Whether to allow invalid certificates.- Returns:
 - This builder for chaining method calls.
 
 
- 
withConnectTimeout
public HttpRequestBuilder withConnectTimeout(Duration connectTimeout)
Sets the connect timeout for the request. The connect timeout is the time to wait for a connection to be established. When not set, a default value is used.- Parameters:
 connectTimeout- The connect timeout.- Returns:
 - This builder for chaining method calls.
 
 
- 
withReadTimeout
public HttpRequestBuilder withReadTimeout(Duration readTimeout)
Sets the read timeout for the request. The read timeout is the time to wait for data to be read from the server. When not set, a default value is used.- Parameters:
 readTimeout- The read timeout.- Returns:
 - This builder for chaining method calls.
 
 
 - 
 
 -