Package org.kawanfw.sql.api.server.util
Class SimpleHttpClient
java.lang.Object
org.kawanfw.sql.api.server.util.SimpleHttpClient
public class SimpleHttpClient extends Object
Simple HttpClient to use for the AceQL AWS (Authentication Web Service)
- Since:
- 5.0
- Author:
- Nicolas de Pomereu
-
Field Summary
Fields Modifier and Type Field Description static boolean
TRACE_ON
If true, calls will be traced -
Constructor Summary
Constructors Constructor Description SimpleHttpClient(int connectTimeout, int readTimeout)
Default constructor. -
Method Summary
Modifier and Type Method Description String
callWithGet(String url, Map<String,String> parametersMap)
Allows to call a remote URL in GET mode and pass parameters.String
callWithPost(URL url, Map<String,String> parametersMap)
Allows to call a remote URL in POST mode and pass parameters.int
getConnectTimeout()
Gets the connect timeout.int
getHttpStatusCode()
Gets the HTTP status codeString
getHttpStatusMessage()
Gets the HTTP status messagestatic String
getPostDataString(Map<String,String> requestParams)
Formats and URL encode the the post data for POST.int
getReadTimeout()
Get the read timeout.
-
Field Details
-
TRACE_ON
public static boolean TRACE_ONIf true, calls will be traced
-
-
Constructor Details
-
SimpleHttpClient
public SimpleHttpClient(int connectTimeout, int readTimeout)Default constructor.- Parameters:
connectTimeout
- connect timeout in millisecondsreadTimeout
- read timeout in milliseconds
-
-
Method Details
-
callWithPost
public String callWithPost(URL url, Map<String,String> parametersMap) throws IOException, ProtocolException, SocketTimeoutException, UnsupportedEncodingExceptionAllows to call a remote URL in POST mode and pass parameters.- Parameters:
url
- the URL to callparametersMap
- the parameters, empty if none. (Cannot be null).- Returns:
- the value returned by the call
- Throws:
IOException
- if an IOException occursProtocolException
- if a ProtocolException occursSocketTimeoutException
- if a if a ProtocolException occurs occursUnsupportedEncodingException
- if a if a ProtocolException occurs occurs
-
callWithGet
public String callWithGet(String url, Map<String,String> parametersMap) throws MalformedURLException, IOException, ProtocolException, UnsupportedEncodingExceptionAllows to call a remote URL in GET mode and pass parameters. Result is put in String.- Parameters:
url
- the URL to callparametersMap
- the parameters, empty if none. (Cannot be null).- Returns:
- the value returned by the call
- Throws:
MalformedURLException
- if a MalformedURLException occursIOException
- if an IOException occursProtocolException
- if a ProtocolException occursSocketTimeoutException
- if a if a ProtocolException occurs occursUnsupportedEncodingException
- if a if a ProtocolException occurs occurs
-
getPostDataString
public static String getPostDataString(Map<String,String> requestParams) throws UnsupportedEncodingExceptionFormats and URL encode the the post data for POST.- Parameters:
requestParams
- the parameter names and values- Returns:
- the formated and URL encoded string for the POST.
- Throws:
UnsupportedEncodingException
- if an UnsupportedEncodingException occurs
-
getConnectTimeout
public int getConnectTimeout()Gets the connect timeout.- Returns:
- the connect timeout.
-
getReadTimeout
public int getReadTimeout()Get the read timeout.- Returns:
- the read timeout.
-
getHttpStatusCode
public int getHttpStatusCode()Gets the HTTP status code- Returns:
- the HTTP status code
-
getHttpStatusMessage
Gets the HTTP status message- Returns:
- the HTTP status message
-