Package com.santaba.agent.groovyapi.http
Class Client
- java.lang.Object
-
- com.logicmonitor.common.sse.utils.SSEResource
-
- com.santaba.agent.groovyapi.http.Client
-
- Direct Known Subclasses:
SSLClient
public class Client extends com.logicmonitor.common.sse.utils.SSEResource
Http client, represents only the most basic contract for HTTP request execution. It imposes no restrictions or particular details on the request execution process and leaves the specifics of state management and authentication
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Client.SBHostVerifier
static class
Client.SBTrustManager
protected static class
Client.Session
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_TLS
-
Constructor Summary
Constructors Modifier Constructor Description protected
Client(org.apache.http.impl.client.DefaultHttpClient client)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static org.apache.http.impl.client.DefaultHttpClient
_createHTTPClient(org.apache.http.HttpHost defHost, java.lang.String tlsVersion)
void
close()
Close the http clientjava.lang.String
delete(java.lang.String uri, java.lang.String data, java.util.Map headers)
Get the http response by DELETE http methodjava.lang.String
get(java.lang.String uri)
Get the http response on urijava.lang.String
get(java.lang.String uri, java.util.Map headers)
Get the http response on uri with http headersstatic Client
getDefaultClient()
Create a default http clientjava.lang.String
getHeader(java.lang.String header)
Get the http header from last http responsejava.lang.String
getHeaders()
Get the all http headers from last http responseorg.apache.http.HttpResponse
getLastHTTPResponse()
Get the last http responsejava.lang.String
getResponseBody()
Get the http response body from last http responseint
getStatusCode()
Get the last http response status codelong[]
getTimeStatistics()
Get the connect time and read timeboolean
isReleased()
Resource interfacestatic Client
open(java.lang.String host)
Open a default http client to host, and the default port is 80static Client
open(java.lang.String host, int port)
Open a default http client to host and portstatic Client
open(java.lang.String host, int port, java.lang.String tlsVersion)
Open a http client to host and port with specific TLS versionstatic Client
open(java.lang.String host, int port, java.lang.String user, java.lang.String pass)
Open a default http client to host with credentialsstatic Client
open(java.lang.String host, int port, java.lang.String user, java.lang.String pass, java.lang.String tlsVersion)
Open a http client to host with credentials and specific TLS versionstatic Client
open(java.lang.String host, java.lang.String user, java.lang.String pass)
Open a default http client to host with credentials, and the default port is 80java.lang.String
post(java.lang.String uri, java.lang.String data, java.util.Map headers)
Get the http response by POST http methodjava.lang.String
put(java.lang.String uri, java.lang.String data, java.util.Map headers)
Get the http response by PUT http methodvoid
release()
Release the http clientjava.lang.String
request(org.apache.http.client.methods.HttpRequestBase method, java.lang.String uri, java.lang.String data, java.util.Map headers)
Send http request and return the http responsevoid
setAuthentication(java.lang.String user, java.lang.String pass)
Set the authentication for get and post methodvoid
setConnectTimeout(int connTOMillis)
Set the connect timeoutvoid
setFollowRedirect(boolean follow)
Enable or disable to follow redirectvoid
setHTTPProxy(java.lang.String host, int port)
Set the http proxy without credentialsvoid
setHTTPProxy(java.lang.String host, int port, java.lang.String user, java.lang.String pass)
Set the http proxy with credentials, only support BASIC authentication methodvoid
setReadTimeout(int readTOMillis)
Set the read timeoutjava.lang.String
toString()
-
-
-
Method Detail
-
isReleased
public boolean isReleased()
Resource interface- Specified by:
isReleased
in classcom.logicmonitor.common.sse.utils.SSEResource
-
release
public void release()
Release the http client- Specified by:
release
in classcom.logicmonitor.common.sse.utils.SSEResource
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDefaultClient
public static Client getDefaultClient() throws java.io.IOException
Create a default http client- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host) throws java.io.IOException
Open a default http client to host, and the default port is 80- Parameters:
host
- the target http host- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host, int port) throws java.io.IOException
Open a default http client to host and port- Parameters:
host
- the http hostport
- the http port- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host, int port, java.lang.String tlsVersion) throws java.io.IOException
Open a http client to host and port with specific TLS version- Parameters:
host
- the http hostport
- the http porttlsVersion
- tls version like TLS, TLSv1, TLSv1.1, TLSv1.2- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host, java.lang.String user, java.lang.String pass) throws java.io.IOException
Open a default http client to host with credentials, and the default port is 80- Parameters:
host
- the http hostuser
- the username for get or postpass
- the password for get or post- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host, int port, java.lang.String user, java.lang.String pass) throws java.io.IOException
Open a default http client to host with credentials- Parameters:
host
- the http hostport
- the http portuser
- the username for get or postpass
- the password for get or post- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
open
public static Client open(java.lang.String host, int port, java.lang.String user, java.lang.String pass, java.lang.String tlsVersion) throws java.io.IOException
Open a http client to host with credentials and specific TLS version- Parameters:
host
- the http hostport
- the http portuser
- the username for get or postpass
- the password for get or posttlsVersion
- tls version like TLS, TLSv1, TLSv1.1, TLSv1.2- Returns:
- Http client
- Throws:
java.io.IOException
- If some other I/O error occurs
-
close
public void close()
Close the http client- See Also:
release()
-
setAuthentication
public void setAuthentication(java.lang.String user, java.lang.String pass) throws java.io.IOException
Set the authentication for get and post method- Parameters:
user
- the usernamepass
- the password- Throws:
java.io.IOException
- See Also:
get(String)
,get(String, Map)
,post(String, String, Map)
-
setConnectTimeout
public void setConnectTimeout(int connTOMillis) throws java.io.IOException
Set the connect timeout- Parameters:
connTOMillis
- the connect timeout in milliseconds- Throws:
java.io.IOException
- If some other I/O error occurs
-
setReadTimeout
public void setReadTimeout(int readTOMillis) throws java.io.IOException
Set the read timeout- Parameters:
readTOMillis
- the read timeout in milliseconds- Throws:
java.io.IOException
- If some other I/O error occurs
-
setHTTPProxy
public void setHTTPProxy(java.lang.String host, int port) throws java.io.IOException
Set the http proxy without credentials- Parameters:
host
- the http proxy hostport
- the http proxy port- Throws:
java.io.IOException
- If some other I/O error occurs
-
setHTTPProxy
public void setHTTPProxy(java.lang.String host, int port, java.lang.String user, java.lang.String pass) throws java.io.IOException
Set the http proxy with credentials, only support BASIC authentication method- Parameters:
host
- the http proxy hostport
- the http proxy portuser
- the http proxy usernamepass
- the http proxy password- Throws:
java.io.IOException
- If some other I/O error occurs
-
setFollowRedirect
public void setFollowRedirect(boolean follow) throws java.io.IOException
Enable or disable to follow redirect- Parameters:
follow
- Whether the server jumps to the new address when the server returns to 301/302- Throws:
java.io.IOException
- If some other I/O error occurs
-
get
public java.lang.String get(java.lang.String uri) throws java.io.IOException
Get the http response on uri- Parameters:
uri
- the resource uri- Returns:
- This url content
- Throws:
java.io.IOException
- If some other I/O error occurs
-
get
public java.lang.String get(java.lang.String uri, java.util.Map headers) throws java.io.IOException
Get the http response on uri with http headers- Parameters:
uri
- the resource uriheaders
- the http headers map- Returns:
- This url content
- Throws:
java.io.IOException
- If some other I/O error occurs
-
post
public java.lang.String post(java.lang.String uri, java.lang.String data, java.util.Map headers) throws java.io.IOException
Get the http response by POST http method- Parameters:
uri
- the resource uridata
- the request bodyheaders
- the http headers map- Returns:
- This post request response text
- Throws:
java.io.IOException
- If some other I/O error occurs
-
put
public java.lang.String put(java.lang.String uri, java.lang.String data, java.util.Map headers) throws java.io.IOException
Get the http response by PUT http method- Parameters:
uri
- the resource uridata
- the request bodyheaders
- the http headers map- Returns:
- This post request response text
- Throws:
java.io.IOException
- If some other I/O error occurs
-
delete
public java.lang.String delete(java.lang.String uri, java.lang.String data, java.util.Map headers) throws java.io.IOException
Get the http response by DELETE http method- Parameters:
uri
- the resource uridata
- the request bodyheaders
- the http headers map- Returns:
- This post request response text
- Throws:
java.io.IOException
- If some other I/O error occurs
-
request
public java.lang.String request(org.apache.http.client.methods.HttpRequestBase method, java.lang.String uri, java.lang.String data, java.util.Map headers) throws java.io.IOException
Send http request and return the http response- Parameters:
method
- the http request methoduri
- the resource uridata
- the request bodyheaders
- the http headers map- Returns:
- This post request response text
- Throws:
java.io.IOException
- If some other I/O error occurs
-
getLastHTTPResponse
public org.apache.http.HttpResponse getLastHTTPResponse() throws java.io.IOException
Get the last http response- Returns:
- Last response
- Throws:
java.io.IOException
- If some other I/O error occurs- See Also:
get(String, Map)
,post(String, String, Map)
-
getStatusCode
public int getStatusCode() throws java.io.IOException
Get the last http response status code- Returns:
- The http status code of current request
- Throws:
java.io.IOException
- If some other I/O error occurs- See Also:
get(String, Map)
,post(String, String, Map)
-
getHeader
public java.lang.String getHeader(java.lang.String header) throws java.io.IOException
Get the http header from last http response- Parameters:
header
- the http header name- Returns:
- The value of header
- Throws:
java.io.IOException
- If some other I/O error occurs- See Also:
get(String, Map)
,post(String, String, Map)
-
getHeaders
public java.lang.String getHeaders() throws java.io.IOException
Get the all http headers from last http response- Returns:
- All header
- Throws:
java.io.IOException
- If some other I/O error occurs- See Also:
get(String, Map)
,post(String, String, Map)
-
getResponseBody
public java.lang.String getResponseBody() throws java.io.IOException
Get the http response body from last http response- Returns:
- The http response body
- Throws:
java.io.IOException
- If some other I/O error occurs- See Also:
get(String, Map)
,post(String, String, Map)
-
getTimeStatistics
public long[] getTimeStatistics() throws java.io.IOException
Get the connect time and read time- Returns:
- the connect time and read time
- Throws:
java.io.IOException
- If some other I/O error occurs
-
_createHTTPClient
protected static org.apache.http.impl.client.DefaultHttpClient _createHTTPClient(org.apache.http.HttpHost defHost, java.lang.String tlsVersion) throws java.io.IOException
- Throws:
java.io.IOException
-
-