com.univocity.api.net
Class HttpRequest

java.lang.Object
  extended by com.univocity.api.net.HttpMessage
      extended by com.univocity.api.net.HttpRequest
All Implemented Interfaces:
Cloneable

public class HttpRequest
extends HttpMessage
implements Cloneable

A reusable, cloneable HTTP request configuration, with support for parameterization of the URL. Example of a URL with 2 parameters (QUERY and PERIOD): "https://www.google.com/?q={QUERY}#q={QUERY}&tbs=qdr:{PERIOD}" Use setUrlParameter(String, Object) to set the values of any parameters so that getUrl() generates the final URL.

Author:
uniVocity Software Pty Ltd - dev@univocity.com
See Also:
RequestMethod, HttpResponse, HttpResponseReader, UrlReaderProvider

Field Summary
 
Fields inherited from class com.univocity.api.net.HttpMessage
cookies, headers, requestMethod
 
Constructor Summary
protected HttpRequest(String url, RateLimiter rateLimiter)
          Creates a new request for a given request URL
 
Method Summary
 void addCookies(Map<String,String> cookies)
          Adds the given cookies to the Cookie HTTP header.
 void addDataParameter(DataParameter dataParameter)
          Adds a data parameter to the body of RequestMethod.POST requests as a plain String
 void addDataParameter(String paramName, Object value)
          Adds a parameter to the body of RequestMethod.POST requests as a plain String
 void addDataParameter(String key, String filename, InputStream inputStream)
          Add an input stream as a request data parameter.
 void addDataParameter(String key, String filename, InputStream inputStream, String contentType)
          Add an input stream as a request data parameter.
 void addDataParameter(String key, String filename, ResourceProvider<InputStream> inputStreamProvider)
          Add an input stream as a request data parameter.
 void addDataParameter(String key, String filename, ResourceProvider<InputStream> inputStreamProvider, String contentType)
          Add an input stream as a request data parameter.
 void addDataParameters(Collection<DataParameter> data)
          Adds multiple data parameters to this HTTP request
 void addDataParameters(Map<String,?> data)
          Adds multiple data parameters to the body of this request
 void addDataParameters(Map<String,String[]> params, String... keys)
          Adds multiple parameters to the body of RequestMethod.POST requests as a plain Strings.
 void addHeader(String header, String value)
          Associates a value to a header.
 void addHeader(String header, String value, boolean encode)
          Associates a value to a header.
 void addHeaders(Map<String,String> headers)
          Adds the given values to the existing list of headers.
 void addHeaders(Map<String,String> headers, boolean encode)
          Adds the given values to the existing list of headers..
 void clearDataParameters()
          Removes all data parameters set on the body of this request.
 void clearUrlParameters()
          Clears all values assigned to all parameters of the URL provided in the constructor of this class.
 HttpRequest clone()
          Clones this request and all its configurations.
 boolean equals(Object o)
           
 int getBodySizeLimit()
          Returns the size limit when reading the HTTP response body, effectively truncating the response if the number of characters read exceed the given limit.
 Charset getCharset()
          Returns the charset to be used when reading the response resulting from this HTTP request.
 String getCharsetName()
          Returns the name of the charset to be used when reading the response resulting from this HTTP request.
 String getCharsetName(String defaultIfNull)
          Returns the name of the charset to be used when reading the response resulting from this HTTP request.
 List<DataParameter> getData()
          Returns the data parameters sent by on the body of this request if it is a RequestMethod.POST request.
 List<DataParameter> getDataParameter(String paramName)
          Returns the values associated with a parameter of the body a RequestMethod.POST request
 DataParameter getFirstDataParameter(String key)
          Returns the first DataParameter details associated with a given data parameter name.
 boolean getFollowRedirects()
          Returns a flag indicating if the request should follow redirects.
 Charset getPostDataCharset()
          Returns the POST data character set for x-www-form-urlencoded POST data
 String getPostDataCharsetName()
          Returns the name of the POST data character set for x-www-form-urlencoded POST data
 Proxy getProxy()
          Returns the the proxy this request should use to connect to
 char[] getProxyPassword()
          Returns the password to be used when connecting with a proxy
 String getProxyUser()
          Returns the username to be used when authenticating with a proxy
 RateLimiter getRateLimiter()
          Returns the RateLimiter associated with this request, if any.
 String getRequestBody()
          Returns the plain request body to be sent by this request.
 SSLSocketFactory getSslSocketFactory()
          Get the current custom SSL socket factory, if any.
 int getTimeout()
          Returns the time limit (in milliseconds) for an initial connection to be established from this request.
 String getUrl()
          Returns the request URL, with any parameters replaced by their values (if any)
 Object getUrlParameter(String parameterName)
          Returns the value of a given parameter of the URL provided in the constructor of this class.
 String getUrlParameter(String parameterName, boolean decode)
          Returns the value of a given parameter of the URL provided in the constructor of this class.
 Set<String> getUrlParameters()
          Returns the names of all available URL parameters in an unmodifiable set.
 int hashCode()
           
 boolean isIgnoreHttpErrors()
          Returns whether this HTTP request to ignore HTTP errors returned by the remote server and process the response anyway.
 String printDetails()
          Returns a String with all relevant details of this HTTP request, including cookies, headers, data
 void removeCookie(String name)
          Removes a given cookie and its value from the Cookie header of this HTTP request
 void removeDataParameter(String paramName)
          Removes a given data parameter from the body of a RequestMethod.POST request
 void removeHeader(String name)
          Removes a given header and all values associated with it from this HTTP request
 void setBodySizeLimit(int limit)
          Defines a size limit when reading the HTTP response body, effectively truncating the response if the number of characters read exceed the given limit.
 void setCharset(Charset charset)
          Defines a charset to be used when reading the response resulting from this HTTP request.
 void setCharset(String charset)
          Defines a charset to be used when reading the response resulting from this HTTP request.
 void setCookie(String cookie, String value)
          Sets a cookie to be added to the Cookie HTTP header.
 void setCookies(Map<String,String> cookies)
          Replaces the cookies to be added to the Cookie HTTP header.
 void setDataParameter(DataParameter dataParameter)
          Adds/replaces a parameter of the body of RequestMethod.POST requests as a plain String
 void setDataParameter(String paramName, Object value)
          Replaces/adds a data parameter to the body of this request
 void setDataParameters(Map<String,String[]> params, String... keys)
          Sets multiple parameters to the body of RequestMethod.POST requests as a plain Strings.
 void setFollowRedirects(boolean followRedirects)
          Configures the request to follow redirects.
 void setHeader(String header, String value)
          Defines a header and its value.
 void setHeader(String header, String value, boolean encode)
          Defines a header and its value.
 void setHeaders(Map<String,String> headers)
          Replaces any previous headers with the given values.
 void setHeaders(Map<String,String> headers, boolean encode)
          Replaces any previous headers with the given values.
 void setIgnoreHttpErrors(boolean ignoreHttpErrors)
          Configures the this HTTP request to ignore HTTP errors returned by the remote server and process the response anyway.
 void setKeepAliveEnabled(boolean enableKeepAlive)
          reused for further requests, or to close if the connection should be discarded and closed as soon as the Sets the Connection request header to explicitly to keep-alive if the connection is meant to be response is processed.
 void setPostDataCharset(Charset postDataCharset)
          Sets the POST data character set for x-www-form-urlencoded POST data
 void setPostDataCharset(String charsetName)
          Sets the POST data character set for x-www-form-urlencoded POST data
 void setProxy(Proxy.Type proxyType, String host, int port, String user, char[] password)
          Configures this request to connect through a proxy.
 void setProxy(Proxy proxy)
          Configures this request to connect through a proxy.
 void setProxy(Proxy proxy, String user)
          Configures this request to connect through a proxy with authentication.
 void setProxy(Proxy proxy, String user, char[] password)
          Configures this request to connect through a proxy with authentication.
 void setProxy(String host, int port)
          Configures this request to connect through a proxy.
 void setProxy(String host, int port, String user)
          Configures this request to connect through a proxy.
 void setProxy(String host, int port, String user, char[] password)
          Configures this request to connect through a proxy.
 void setRateLimiter(RateLimiter rateLimiter)
          Associates a RateLimiter with this request to prevent multiple simultaneous requests.
 void setReferrer(String referrer)
          Defines a Referer request header that identifies the address of the web-page that linked to the resource being requested.
 void setRequestBody(String body)
          Defines a plain request body to be sent by this request.
 void setRequestMethod(RequestMethod httpMethodType)
          Sets the RequestMethod to be used by this request.
 void setSslSocketFactory(SSLSocketFactory sslSocketFactory)
          Set a custom SSL socket factory.
 void setTimeout(int timeout)
          Defines a time limit (in milliseconds) for an initial connection to be established from this request.
 void setUrl(String url)
          Modifies the URL this HTTP request.
 void setUrlParameter(String parameterName, Object parameterValue)
          Assigns a value to a given parameter of the URL provided in the constructor of this class.
 void setUrlParameter(String parameterName, Object parameterValue, boolean encode)
          Assigns a value to a given parameter of the URL provided in the constructor of this class.
 void setUserAgent(String userAgent)
          Defines a User-Agent request header, which identifies the user agent originating the request.
 String toString()
           
 
Methods inherited from class com.univocity.api.net.HttpMessage
getCookies, getCookieValue, getHeaders, getHeaderValue, getHeaderValues, getMultiHeaders, getReferrer, getRequestMethod, getUserAgent, hasCookie, hasHeader, hasHeaderWithValue, isKeepAliveEnabled
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpRequest

protected HttpRequest(String url,
                      RateLimiter rateLimiter)
Creates a new request for a given request URL

Parameters:
url - the request URL
rateLimiter - a RateLimiter to prevent the execution of excessive simultaneous requests.
Method Detail

getRateLimiter

public final RateLimiter getRateLimiter()
Returns the RateLimiter associated with this request, if any.

Returns:
the request rate limiter, if available.

setRateLimiter

public final void setRateLimiter(RateLimiter rateLimiter)
Associates a RateLimiter with this request to prevent multiple simultaneous requests.

Parameters:
rateLimiter - the rate limiter to be used when executing this request.

setUrl

public final void setUrl(String url)
Modifies the URL this HTTP request. Parameter values set in the previous URL will be re-applied on the new URL, if their names match.

Parameters:
url - the new request URL.

getBodySizeLimit

public final int getBodySizeLimit()
Returns the size limit when reading the HTTP response body, effectively truncating the response if the number of characters read exceed the given limit. Defaults to 0 (no limit)

Returns:
the maximum number of characters to read from the response

setBodySizeLimit

public final void setBodySizeLimit(int limit)
Defines a size limit when reading the HTTP response body, effectively truncating the response if the number of characters read exceed the given limit. Defaults to 0 (no limit)

Parameters:
limit - the maximum number of characters to read from the response

getRequestBody

public final String getRequestBody()
Returns the plain request body to be sent by this request.

Returns:
the request body String.

setRequestBody

public final void setRequestBody(String body)
Defines a plain request body to be sent by this request.

Parameters:
body - the request body String.

getPostDataCharset

public final Charset getPostDataCharset()
Returns the POST data character set for x-www-form-urlencoded POST data

Returns:
the character set used to encode the POST data

getPostDataCharsetName

public final String getPostDataCharsetName()
Returns the name of the POST data character set for x-www-form-urlencoded POST data

Returns:
the name of the character set used to encode the POST data

setPostDataCharset

public final void setPostDataCharset(String charsetName)
Sets the POST data character set for x-www-form-urlencoded POST data

Parameters:
charsetName - name of the character set

setPostDataCharset

public final void setPostDataCharset(Charset postDataCharset)
Sets the POST data character set for x-www-form-urlencoded POST data

Parameters:
postDataCharset - the character set to use

setKeepAliveEnabled

public final void setKeepAliveEnabled(boolean enableKeepAlive)
reused for further requests, or to close if the connection should be discarded and closed as soon as the Sets the Connection request header to explicitly to keep-alive if the connection is meant to be response is processed.

Parameters:
enableKeepAlive - flag indicating whether or not the HTTP connection should be persistent (i.e kept alive).

setUserAgent

public final void setUserAgent(String userAgent)
Defines a User-Agent request header, which identifies the user agent originating the request.

Parameters:
userAgent - the new User-Agent value

setReferrer

public final void setReferrer(String referrer)
Defines a Referer request header that identifies the address of the web-page that linked to the resource being requested.

Parameters:
referrer - the new Referer value

addHeader

public final void addHeader(String header,
                            String value)
Associates a value to a header. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs Existing values associated with the given header will remain.

Parameters:
header - the header name
value - the header value

addHeader

public final void addHeader(String header,
                            String value,
                            boolean encode)
Associates a value to a header. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs Existing values associated with the given header will remain.

Parameters:
header - the header name
value - the header value
encode - flag indicating whether to encode the given value

setHeader

public final void setHeader(String header,
                            String value)
Defines a header and its value. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs Existing values associated with the given header will be removed.

Parameters:
header - the header name
value - the header value

setHeader

public final void setHeader(String header,
                            String value,
                            boolean encode)
Defines a header and its value. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs. Existing values associated with the given header will be removed.

Parameters:
header - the header name
value - the new header value
encode - flag indicating whether the value should be encoded

setHeaders

public final void setHeaders(Map<String,String> headers)
Replaces any previous headers with the given values. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs Existing values associated with the given headers will be removed.

Parameters:
headers - a map of headers names and their values. Previous values will be discarded

addHeaders

public final void addHeaders(Map<String,String> headers)
Adds the given values to the existing list of headers. New header names will be added as required. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs

Parameters:
headers - a map of header names and their values.

setHeaders

public final void setHeaders(Map<String,String> headers,
                             boolean encode)
Replaces any previous headers with the given values. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs Existing values associated with the given header will be removed.

Parameters:
headers - a map of headers names and their values. Previous values will be discarded
encode - flag indicating whether values should be encoded

addHeaders

public final void addHeaders(Map<String,String> headers,
                             boolean encode)
Adds the given values to the existing list of headers.. New header names will be added as required. All headers are transmitted after the request line (the first line of a HTTP message), in the format of comma-separated name-value pairs

Parameters:
headers - a map of header names and their values.
encode - flag indicating whether values should be encoded

setCookie

public final void setCookie(String cookie,
                            String value)
Sets a cookie to be added to the Cookie HTTP header. All cookies are sent in this header in the format of semicolon-separated name-value pairs.

Parameters:
cookie - the cookie name
value - the cookie value

setCookies

public final void setCookies(Map<String,String> cookies)
Replaces the cookies to be added to the Cookie HTTP header. All cookies are sent in this header in the format of semicolon-separated name-value pairs.

Parameters:
cookies - a map of cookie names and their values. Previous values will be discarded

addCookies

public final void addCookies(Map<String,String> cookies)
Adds the given cookies to the Cookie HTTP header. All cookies are sent in this header in the format of semicolon-separated name-value pairs.

Parameters:
cookies - a map of cookie names and their values.

removeCookie

public final void removeCookie(String name)
Removes a given cookie and its value from the Cookie header of this HTTP request

Parameters:
name - the name of the cookie to be removed.

setTimeout

public final void setTimeout(int timeout)
Defines a time limit (in milliseconds) for an initial connection to be established from this request. Defaults to 0 (no timeout).

Parameters:
timeout - the time limit to wait until a connection is established.

setRequestMethod

public final void setRequestMethod(RequestMethod httpMethodType)
Sets the RequestMethod to be used by this request. The method type identifies an action to be performed on the identified (remote) resource. Defaults to RequestMethod.GET

Parameters:
httpMethodType - the HTTP method to use

getUrl

public final String getUrl()
Returns the request URL, with any parameters replaced by their values (if any)

Returns:
the URL that will be used to invoke the HTTP request.

setUrlParameter

public final void setUrlParameter(String parameterName,
                                  Object parameterValue)
Assigns a value to a given parameter of the URL provided in the constructor of this class. The value will be used to modify the address that will be accessed by this HTTP request. Calling getUrl() will return the updated target URL of this request. Parameters without values won't be replaced in the URL.

Parameters:
parameterName - name of the parameter enclosed within { and } in the URL
parameterValue - value of the given parameter, to replace the parameter name in the URL
Throws:
IllegalArgumentException - if the parameter name does not exist

getUrlParameter

public final Object getUrlParameter(String parameterName)
Returns the value of a given parameter of the URL provided in the constructor of this class. The value will be used to modify the address that will be accessed by this HTTP request. Calling getUrl() will return the updated target URL of this request. Parameters without values won't be replaced in the URL.

Parameters:
parameterName - name of the parameter enclosed within { and } in the URL
Returns:
value of the given parameter, to replace the parameter name in the URL
Throws:
IllegalArgumentException - if the parameter name does not exist

getUrlParameters

public final Set<String> getUrlParameters()
Returns the names of all available URL parameters in an unmodifiable set.

Returns:
the available parameters in the URL

setUrlParameter

public final void setUrlParameter(String parameterName,
                                  Object parameterValue,
                                  boolean encode)
Assigns a value to a given parameter of the URL provided in the constructor of this class. The value will be used to modify the address that will be accessed by this HTTP request. Calling getUrl() will return the updated target URL of this request. Parameters without values won't be replaced in the URL.

Parameters:
parameterName - name of the parameter enclosed within { and } in the URL
parameterValue - value of the given parameter, to replace the parameter name in the URL
encode - flag indicating whether to encode the given parameter value. If the value is already encoded, it won't be encoded again.
Throws:
IllegalArgumentException - if the parameter name does not exist

getCharsetName

public final String getCharsetName(String defaultIfNull)
Returns the name of the charset to be used when reading the response resulting from this HTTP request. This will take precedence over the charset defined in the Content-Type header of the HTTP response.

Parameters:
defaultIfNull - a default charset name to return if the result of getCharsetName() is null
Returns:
the charset name

getUrlParameter

public final String getUrlParameter(String parameterName,
                                    boolean decode)
Returns the value of a given parameter of the URL provided in the constructor of this class. The value will be used to modify the address that will be accessed by this HTTP request. Calling getUrl() will return the updated target URL of this request. Parameters without values won't be replaced in the URL.

Parameters:
parameterName - name of the parameter enclosed within { and } in the URL
decode - flag indicating whether to decode the value associated with the given parameter name.
Returns:
value of the given parameter, to replace the parameter name in the URL
Throws:
IllegalArgumentException - if the parameter name does not exist

clearUrlParameters

public final void clearUrlParameters()
Clears all values assigned to all parameters of the URL provided in the constructor of this class. Calling getUrl() after this method will return the original URL with parameters provided in the constructor.


getTimeout

public final int getTimeout()
Returns the time limit (in milliseconds) for an initial connection to be established from this request. Defaults to 0 (no timeout).

Returns:
the current timeout value.

getFollowRedirects

public final boolean getFollowRedirects()
Returns a flag indicating if the request should follow redirects. If enabled, HttpResponse.getRedirectionUrl() should return the redirection URL if this request was redirected. Defaults to true.

Returns:
a flag indicating whether or not the request is configured to follow redirects.

setFollowRedirects

public final void setFollowRedirects(boolean followRedirects)
Configures the request to follow redirects. If enabled, HttpResponse.getRedirectionUrl() should return the redirection URL if this request was redirected. Defaults to true.

Parameters:
followRedirects - flag indicating whether or not to follow redirects.

addDataParameter

public final void addDataParameter(DataParameter dataParameter)
Adds a data parameter to the body of RequestMethod.POST requests as a plain String

Parameters:
dataParameter - the data parameter

removeDataParameter

public final void removeDataParameter(String paramName)
Removes a given data parameter from the body of a RequestMethod.POST request

Parameters:
paramName - the parameter name

getDataParameter

public final List<DataParameter> getDataParameter(String paramName)
Returns the values associated with a parameter of the body a RequestMethod.POST request

Parameters:
paramName - the parameter name
Returns:
all values associated with the given parameter name.

setDataParameter

public final void setDataParameter(DataParameter dataParameter)
Adds/replaces a parameter of the body of RequestMethod.POST requests as a plain String

Parameters:
dataParameter - the new/updated data parameter

setDataParameters

public final void setDataParameters(Map<String,String[]> params,
                                    String... keys)
Sets multiple parameters to the body of RequestMethod.POST requests as a plain Strings. Multiple values can be associated with a parameter name. Any previous parameters will be removed. null or empty lists of values will cause an empty String to be associated with the parameter name.

Parameters:
params - the parameters and values associated with them. Multiple values can be associated with each parameter name.
keys - the specific keys to read from the given parameter map. Parameters will be added in the order defined by the key sequence. If the map doesn't contain a given key, a parameter named after the key will be created, assigning an empty String value to it. If no keys are provided, all elements of the map will be used.

addDataParameters

public final void addDataParameters(Map<String,String[]> params,
                                    String... keys)
Adds multiple parameters to the body of RequestMethod.POST requests as a plain Strings. Multiple values can be associated with a parameter name. null or empty lists of values will cause an empty String to be associated with the parameter name.

Parameters:
params - the parameters and values associated with them. Multiple values can be associated with each parameter name.
keys - the specific keys to read from the given parameter map. Parameters will be added in the order defined by the key sequence. If the map doesn't contain a given key, a parameter named after the key will be created, assigning an empty String value to it. If no keys are provided, all elements of the map will be used.

addDataParameter

public final void addDataParameter(String paramName,
                                   Object value)
Adds a parameter to the body of RequestMethod.POST requests as a plain String

Parameters:
paramName - the parameter name
value - the parameter value

setDataParameter

public final void setDataParameter(String paramName,
                                   Object value)
Replaces/adds a data parameter to the body of this request

Parameters:
paramName - the parameter name
value - the parameter value

getData

public final List<DataParameter> getData()
Returns the data parameters sent by on the body of this request if it is a RequestMethod.POST request.

Returns:
a map of data parameters and their values.

removeHeader

public final void removeHeader(String name)
Removes a given header and all values associated with it from this HTTP request

Parameters:
name - the name of the header to be removed

addDataParameter

public void addDataParameter(String key,
                             String filename,
                             InputStream inputStream,
                             String contentType)
Add an input stream as a request data parameter. For GETs, has no effect, but for POSTS this will upload the input stream.

Parameters:
key - data key (form item name)
filename - the name of the file to present to the remove server. Typically just the name, not path, component.
inputStream - the input stream to upload.
contentType - the Content Type (aka mimetype) to specify for this file. You must close the InputStream in a finally block.

addDataParameter

public void addDataParameter(String key,
                             String filename,
                             ResourceProvider<InputStream> inputStreamProvider,
                             String contentType)
Add an input stream as a request data parameter. For GETs, has no effect, but for POSTS this will upload the input stream.

Parameters:
key - data key (form item name)
filename - the name of the file to present to the remove server. Typically just the name, not path, component.
inputStreamProvider - the input stream provider to upload.
contentType - the Content Type (aka mimetype) to specify for this file. You must close the InputStream in a finally block.

addDataParameters

public void addDataParameters(Map<String,?> data)
Adds multiple data parameters to the body of this request

Parameters:
data - a map of data parameter names and their corresponding values

addDataParameter

public void addDataParameter(String key,
                             String filename,
                             InputStream inputStream)
Add an input stream as a request data parameter. For GETs, has no effect, but for POSTS this will upload the input stream.

Parameters:
key - data key (form item name)
filename - the name of the file to present to the remove server. Typically just the name, not path, component.
inputStream - the input stream to upload, that you probably obtained from a FileInputStream.

addDataParameter

public void addDataParameter(String key,
                             String filename,
                             ResourceProvider<InputStream> inputStreamProvider)
Add an input stream as a request data parameter. For GETs, has no effect, but for POSTS this will upload the input stream.

Parameters:
key - data key (form item name)
filename - the name of the file to present to the remove server. Typically just the name, not path, component.
inputStreamProvider - a callback provider that produces the input stream of the content to upload.

getFirstDataParameter

public DataParameter getFirstDataParameter(String key)
Returns the first DataParameter details associated with a given data parameter name.

Parameters:
key - the data parameter name
Returns:
the first DataParameter instance associated with the given name, or null if none.

addDataParameters

public final void addDataParameters(Collection<DataParameter> data)
Adds multiple data parameters to this HTTP request

Parameters:
data - the data parameters to add

clearDataParameters

public final void clearDataParameters()
Removes all data parameters set on the body of this request.


setProxy

public final void setProxy(Proxy proxy)
Configures this request to connect through a proxy.

Parameters:
proxy - the proxy configuration.

setProxy

public final void setProxy(Proxy proxy,
                           String user)
Configures this request to connect through a proxy with authentication.

Parameters:
proxy - the proxy configuration.
user - the proxy user.

setProxy

public final void setProxy(Proxy proxy,
                           String user,
                           char[] password)
Configures this request to connect through a proxy with authentication.

Parameters:
proxy - the proxy configuration.
user - the proxy user.
password - the proxy password.

setProxy

public final void setProxy(String host,
                           int port)
Configures this request to connect through a proxy.

Parameters:
host - the proxy host.
port - the proxy port.

setProxy

public final void setProxy(String host,
                           int port,
                           String user)
Configures this request to connect through a proxy.

Parameters:
host - the proxy host.
port - the proxy port.
user - the proxy user.

setProxy

public final void setProxy(String host,
                           int port,
                           String user,
                           char[] password)
Configures this request to connect through a proxy.

Parameters:
host - the proxy host.
port - the proxy port.
user - the proxy user.
password - the proxy password

setProxy

public final void setProxy(Proxy.Type proxyType,
                           String host,
                           int port,
                           String user,
                           char[] password)
Configures this request to connect through a proxy.

Parameters:
proxyType - the type of proxy.
host - the proxy host.
port - the proxy port.
user - the proxy user.
password - the proxy password (note the char array is copied)

getProxyUser

public final String getProxyUser()
Returns the username to be used when authenticating with a proxy

Returns:
the proxy user

getProxyPassword

public final char[] getProxyPassword()
Returns the password to be used when connecting with a proxy

Returns:
the proxy password

getProxy

public final Proxy getProxy()
Returns the the proxy this request should use to connect to

Returns:
the proxy configuration

setCharset

public final void setCharset(String charset)
Defines a charset to be used when reading the response resulting from this HTTP request. This will take precedence over the charset defined in the Content-Type header of the HTTP response.

Parameters:
charset - the charset name

setCharset

public final void setCharset(Charset charset)
Defines a charset to be used when reading the response resulting from this HTTP request. This will take precedence over the charset defined in the Content-Type header of the HTTP response.

Parameters:
charset - the charset

getCharset

public final Charset getCharset()
Returns the charset to be used when reading the response resulting from this HTTP request. This will take precedence over the charset defined in the Content-Type header of the HTTP response.

Returns:
the charset

getCharsetName

public final String getCharsetName()
Returns the name of the charset to be used when reading the response resulting from this HTTP request. This will take precedence over the charset defined in the Content-Type header of the HTTP response.

Returns:
the charset name

isIgnoreHttpErrors

public final boolean isIgnoreHttpErrors()
Returns whether this HTTP request to ignore HTTP errors returned by the remote server and process the response anyway. Defaults to false.

Returns:
a flag indicating whether or not HTTP response code errors should be ignored/

setIgnoreHttpErrors

public final void setIgnoreHttpErrors(boolean ignoreHttpErrors)
Configures the this HTTP request to ignore HTTP errors returned by the remote server and process the response anyway. Defaults to false.

Parameters:
ignoreHttpErrors - flag indicating whether or not HTTP response code errors should be ignored

getSslSocketFactory

public final SSLSocketFactory getSslSocketFactory()
Get the current custom SSL socket factory, if any.

Returns:
custom SSL socket factory if set, null otherwise

setSslSocketFactory

public final void setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Set a custom SSL socket factory.

Parameters:
sslSocketFactory - SSL socket factory

clone

public final HttpRequest clone()
Clones this request and all its configurations. NOTE:Data parameters are reused and not cloned.

Overrides:
clone in class Object
Returns:
a copy of this request with all possible settings.

printDetails

public final String printDetails()
Returns a String with all relevant details of this HTTP request, including cookies, headers, data

Returns:
the details of this request

toString

public final String toString()
Overrides:
toString in class Object

equals

public final boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.