Package org.apache.ofbiz.base.util
Class HttpClient
java.lang.Object
org.apache.ofbiz.base.util.HttpClient
Send HTTP GET/POST requests.
The main problem with current implementation is that it does not handle connections release. You must rely on the OS to release them (timeout).
-
Constructor Summary
ConstructorDescriptionCreates an empty HttpClient object.HttpClient
(String url) Creates a new HttpClient object.HttpClient
(String url, Map<String, Object> parameters) Creates a new HttpClient object.Creates a new HttpClient object.HttpClient
(URL url) Creates a new HttpClient object.HttpClient
(URL url, Map<String, Object> parameters) Creates a new HttpClient object.Creates a new HttpClient object. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
checkHttpRequest
(String url) void
followRedirects
(boolean followRedirects) Enables this request to follow redirect 3xx codes (default true)get()
Invoke HTTP request GET.boolean
Do we trust any certificateReturns the alias of the client certificate to be used for this SSL connection.Returns the content typeReturn a Map of headers.int
Returns the current server hostname verification levelboolean
Return keep-alive settingReturn a Map of parameters.int
Gets response code.Returns the content of the response.Returns the content encoding of the response.int
Returns the content length of the responseReturns the content-type of the response.getResponseHeader
(String header) Returns the value of the specified named response header field.getResponseHeaderField
(int n) Returns the value for the nth response header field.getResponseHeaderFieldKey
(int n) Returns the key for the nth response header field.Invoke HTTP request GET.Returns the stream charsetgetUrl()
Return a string representing the requested URL.static String
getUrlContent
(String url) post()
Invoke HTTP request POST.Invoke HTTP request POST and pass raw stream.Invoke HTTP request POST.void
setAllowUntrusted
(boolean trustAny) Allow untrusted server certificatesvoid
setBasicAuthInfo
(String basicAuthUsername, String basicAuthPassword) Sets basic auth info.void
setClientCertificateAlias
(String alias) Sets the client certificate alias (from the keystore) to use for this SSL connection.void
setContentType
(String contentType) Sets the content-typevoid
setDebug
(boolean debug) When true overrides Debug.verboseOn() and forces debugging for this instancevoid
Set an individual header for this request.void
setHeaders
(Map<String, String> headers) Set the headers for this request.void
setHostVerificationLevel
(int level) Sets the server hostname verification levelvoid
setKeepAlive
(boolean keepAlive) Toggle keep-alive settingvoid
setLineFeed
(boolean lineFeed) Turns on or off line feeds in the request.void
setParameter
(String name, String value) Set an individual parameter for this request.void
setParameters
(Map<String, Object> parameters) Set the parameters for this request.void
setRawStream
(String stream) Set the raw stream for posts.void
setStreamCharset
(String streamCharset) Sets the scream charsetvoid
setTimeout
(int timeout) Sets the timeout for waiting for the connection (default 30sec)void
Set the URL for this request.void
Set the URL for this request.
-
Constructor Details
-
HttpClient
public HttpClient()Creates an empty HttpClient object. -
HttpClient
Creates a new HttpClient object. -
HttpClient
Creates a new HttpClient object. -
HttpClient
Creates a new HttpClient object. -
HttpClient
Creates a new HttpClient object. -
HttpClient
Creates a new HttpClient object. -
HttpClient
Creates a new HttpClient object.
-
-
Method Details
-
setDebug
public void setDebug(boolean debug) When true overrides Debug.verboseOn() and forces debugging for this instance -
setTimeout
public void setTimeout(int timeout) Sets the timeout for waiting for the connection (default 30sec) -
followRedirects
public void followRedirects(boolean followRedirects) Enables this request to follow redirect 3xx codes (default true) -
setLineFeed
public void setLineFeed(boolean lineFeed) Turns on or off line feeds in the request. (default is on) -
setRawStream
Set the raw stream for posts. -
setUrl
Set the URL for this request. -
setUrl
Set the URL for this request. -
setParameters
Set the parameters for this request. -
setParameter
Set an individual parameter for this request. -
setHeaders
Set the headers for this request. -
setHeader
Set an individual header for this request. -
getHeaders
Return a Map of headers. -
getParameters
Return a Map of parameters. -
getUrl
Return a string representing the requested URL. -
setContentType
Sets the content-type -
getContentType
Returns the content type -
setStreamCharset
Sets the scream charset -
getStreamCharset
Returns the stream charset -
setKeepAlive
public void setKeepAlive(boolean keepAlive) Toggle keep-alive setting -
getKeepAlive
public boolean getKeepAlive()Return keep-alive setting -
setClientCertificateAlias
Sets the client certificate alias (from the keystore) to use for this SSL connection. -
getClientCertificateAlias
Returns the alias of the client certificate to be used for this SSL connection. -
setHostVerificationLevel
public void setHostVerificationLevel(int level) Sets the server hostname verification level -
getHostVerificationLevel
public int getHostVerificationLevel()Returns the current server hostname verification level -
setAllowUntrusted
public void setAllowUntrusted(boolean trustAny) Allow untrusted server certificates -
getAllowUntrusted
public boolean getAllowUntrusted()Do we trust any certificate -
setBasicAuthInfo
Sets basic auth info.- Parameters:
basicAuthUsername
- the basic auth usernamebasicAuthPassword
- the basic auth password
-
get
Invoke HTTP request GET.- Throws:
HttpClientException
-
getStream
Invoke HTTP request GET.- Throws:
HttpClientException
-
post
Invoke HTTP request POST.- Throws:
HttpClientException
-
post
Invoke HTTP request POST and pass raw stream.- Throws:
HttpClientException
-
postStream
Invoke HTTP request POST.- Throws:
HttpClientException
-
getResponseHeader
Returns the value of the specified named response header field.- Throws:
HttpClientException
-
getResponseHeaderFieldKey
Returns the key for the nth response header field.- Throws:
HttpClientException
-
getResponseHeaderField
Returns the value for the nth response header field. It returns null of there are fewer then n fields.- Throws:
HttpClientException
-
getResponseContent
Returns the content of the response.- Throws:
IOException
HttpClientException
-
getResponseContentType
Returns the content-type of the response.- Throws:
HttpClientException
-
getResponseContentLength
Returns the content length of the response- Throws:
HttpClientException
-
getResponseContentEncoding
Returns the content encoding of the response.- Throws:
HttpClientException
-
getResponseCode
Gets response code.- Returns:
- the response code
- Throws:
HttpClientException
- the http client exception
-
getUrlContent
- Throws:
HttpClientException
-
checkHttpRequest
- Throws:
HttpClientException
-