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, URI uri)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestBuilder
addBinayData(String elementName, byte[] data, String filename, String mimeType)
HttpRequestBuilder
addBinayData(String elementName, byte[] data, String filename, String mimeType, Charset charset)
HttpRequestBuilder
addHeader(String name, String value)
HttpRequestBuilder
addParameter(String name, String value)
HttpRequestBuilder
addParameter(String name, String value, org.apache.http.entity.ContentType contentType)
org.apache.http.client.methods.CloseableHttpResponse
build()
Performs the HTTP request to the server and returns the response.String
getUrl()
HttpRequestBuilder
setBasicAuthLogin(String login)
HttpRequestBuilder
setBasicAuthPassword(String pwd)
HttpRequestBuilder
setInputCharset(Charset inputCharset)
Sets the request character encoding.HttpRequestBuilder
setProxyServer(FcHttpRequestProps.ProxyProps proxyConfig)
Sets the following proxy server configuration parameters if defined inside theFcHttpRequestProps.ProxyProps
object: proxy server host proxy server port login for a proxy server authentication password for a proxy server authenticationHttpRequestBuilder
setProxyServerAuth(FcHttpRequestProps.ProxyAuthProps proxyAuth)
HttpRequestBuilder
setProxyServerAuthLogin(String login)
HttpRequestBuilder
setProxyServerAuthPassword(String pwd)
HttpRequestBuilder
setProxyServerHost(String host)
Sets the proxy server host.HttpRequestBuilder
setProxyServerPort(int port)
Sets the proxy server port.HttpRequestBuilder
supportsMessageBody(Boolean supportsMessageBody)
boolean
useBasicAuthentication()
boolean
useProxyServer()
boolean
useProxyServerAuthentication()
HttpRequestBuilder
withDisabledRedirectHandling(boolean disableRedirectHandling)
Enables/Disables automatic redirect handling.
-
-
-
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.
-
-
Method Detail
-
addBinayData
@Nonnull public HttpRequestBuilder addBinayData(@Nonnull String elementName, @Nullable byte[] data, @Nonnull String filename, @Nonnull String mimeType) throws Exception
- Throws:
Exception
-
addBinayData
@Nonnull public HttpRequestBuilder addBinayData(@Nonnull String elementName, @Nullable byte[] data, @Nonnull String filename, @Nonnull String mimeType, @Nonnull Charset charset) throws Exception
- Throws:
Exception
-
addHeader
@Nonnull public HttpRequestBuilder addHeader(@Nonnull String name, @Nonnull String value)
-
addParameter
@Nonnull public HttpRequestBuilder addParameter(@Nonnull String name, @Nonnull String value)
-
addParameter
@Nonnull public HttpRequestBuilder addParameter(@Nonnull String name, @Nonnull String value, @Nonnull org.apache.http.entity.ContentType contentType)
-
build
@Nonnull public org.apache.http.client.methods.CloseableHttpResponse build() throws IOException
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.
-
getUrl
@Nonnull public String getUrl()
- Returns:
- the request URL
-
setBasicAuthLogin
@Nonnull public HttpRequestBuilder setBasicAuthLogin(@Nullable String login)
-
setBasicAuthPassword
@Nonnull public HttpRequestBuilder setBasicAuthPassword(@Nullable String pwd)
-
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.ProxyProps
object:- 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)
-
setProxyServerAuthLogin
@Nonnull public HttpRequestBuilder setProxyServerAuthLogin(@Nullable String login)
-
setProxyServerAuthPassword
@Nonnull public HttpRequestBuilder setProxyServerAuthPassword(@Nullable String pwd)
-
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.
-
withDisabledRedirectHandling
@Nonnull public HttpRequestBuilder withDisabledRedirectHandling(boolean disableRedirectHandling)
Enables/Disables automatic redirect handling.- Parameters:
disableRedirectHandling
-true
orfalse
- Returns:
- This builder for chaining method calls.
-
supportsMessageBody
@Nonnull public HttpRequestBuilder supportsMessageBody(@Nullable Boolean supportsMessageBody)
- Parameters:
supportsMessageBody
- Whether this request supports a message body. When it does not, parameters are added as URL parameters and no files are included. Whennull
, a default is used based on the HTTP method.- Returns:
- This builder for chaining method calls.
-
useBasicAuthentication
public boolean useBasicAuthentication()
- Returns:
true
if an login and password for basic authentication is set, otherwisetrue
-
useProxyServer
public boolean useProxyServer()
- Returns:
true
if the host and port for a proxy server use is set, otherwisefalse
-
useProxyServerAuthentication
public boolean useProxyServerAuthentication()
- Returns:
true
if an login and password for proxy server authentication is set, otherwisefalse
-
-