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.SSEResourceHttp 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 classClient.SBHostVerifierstatic classClient.SBTrustManagerprotected static classClient.Session
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_TLS
-
Constructor Summary
Constructors Modifier Constructor Description protectedClient(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)voidclose()Close the http clientjava.lang.Stringdelete(java.lang.String uri, java.lang.String data, java.util.Map headers)Get the http response by DELETE http methodjava.lang.Stringget(java.lang.String uri)Get the http response on urijava.lang.Stringget(java.lang.String uri, java.util.Map headers)Get the http response on uri with http headersstatic ClientgetDefaultClient()Create a default http clientjava.lang.StringgetHeader(java.lang.String header)Get the http header from last http responsejava.lang.StringgetHeaders()Get the all http headers from last http responseorg.apache.http.HttpResponsegetLastHTTPResponse()Get the last http responsejava.lang.StringgetResponseBody()Get the http response body from last http responseintgetStatusCode()Get the last http response status codelong[]getTimeStatistics()Get the connect time and read timebooleanisReleased()Resource interfacestatic Clientopen(java.lang.String host)Open a default http client to host, and the default port is 80static Clientopen(java.lang.String host, int port)Open a default http client to host and portstatic Clientopen(java.lang.String host, int port, java.lang.String tlsVersion)Open a http client to host and port with specific TLS versionstatic Clientopen(java.lang.String host, int port, java.lang.String user, java.lang.String pass)Open a default http client to host with credentialsstatic Clientopen(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 Clientopen(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.Stringpost(java.lang.String uri, java.lang.String data, java.util.Map headers)Get the http response by POST http methodjava.lang.Stringput(java.lang.String uri, java.lang.String data, java.util.Map headers)Get the http response by PUT http methodvoidrelease()Release the http clientjava.lang.Stringrequest(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 responsevoidsetAuthentication(java.lang.String user, java.lang.String pass)Set the authentication for get and post methodvoidsetConnectTimeout(int connTOMillis)Set the connect timeoutvoidsetFollowRedirect(boolean follow)Enable or disable to follow redirectvoidsetHTTPProxy(java.lang.String host, int port)Set the http proxy without credentialsvoidsetHTTPProxy(java.lang.String host, int port, java.lang.String user, java.lang.String pass)Set the http proxy with credentials, only support BASIC authentication methodvoidsetReadTimeout(int readTOMillis)Set the read timeoutjava.lang.StringtoString()
-
-
-
Method Detail
-
isReleased
public boolean isReleased()
Resource interface- Specified by:
isReleasedin classcom.logicmonitor.common.sse.utils.SSEResource
-
release
public void release()
Release the http client- Specified by:
releasein classcom.logicmonitor.common.sse.utils.SSEResource
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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.IOExceptionSet 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.IOExceptionSet 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.IOExceptionSet 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.IOExceptionSet 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.IOExceptionSet 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.IOExceptionEnable 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionSend 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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.IOExceptionGet 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
-
-