Package org.symphonyoss.symphony.jcurl
Class JCurl.Builder
- java.lang.Object
-
- org.symphonyoss.symphony.jcurl.JCurl.Builder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JCurlbuild()Get an instance of JCurl with options configured by theBuilder().JCurl.BuilderconnectTimeout(int milliseconds)How long to wait for a connection to the remote resource.JCurl.Buildercookie(String name, String value)Send a custom cookie with the request.JCurl.Builderdata(String payload)Send a POST request with DATA as request body.JCurl.Builderexpect(int expectedStatus)Add HTTP STATUS as an expected response code.JCurl.Builderextract(String node)Iterate over a JSON array of objects returned by the call content and extract the value of NODE.JCurl.Builderextract(String label, String node)Extract NODE from a JSON object returned by the call and return as "LABEL=NODE".JCurl.BuilderextractCookies(boolean extract)Extract cookies returned by the call as KEY=VALUE pairs.JCurl.Builderform(String name, String value)Send a POST request with CONTENT as "key=value" pairs corresponding to a HTML form.JCurl.Builderheader(String name, String value)Send a custom header with the request.JCurl.Builderinsecure(boolean disableChecks)Disable checks for an HTTPS request.JCurl.Builderkeystore(String store)The keystore containing the certificate to use for authentication.JCurl.Buildermethod(JCurl.HttpMethod method)Set the HTTP type of the request.JCurl.BuildernonProxyHosts(String hosts)Bypass the proxy (if defined) for the specified list of |-separated hosts.JCurl.Builderproxy(String proxy)Proxy the request through the specified URL.JCurl.Builderquery(String name, String value)Set request query parameters to be appended to the target URL as "name=value" pairs separated by "&";JCurl.BuilderreadTimeout(int milliseconds)How long to wait for a response from the remote resource.JCurl.Builderstorepass(String pass)The keystore password.JCurl.Builderstoretype(String type)The keystore type.JCurl.BuildertrustAllCertificates(boolean disableChecks)Disable SSL certificate verification.JCurl.BuildertrustAllHostnames(boolean disableChecks)Disable SSL hostname verification.JCurl.Buildertrustpass(String pass)The truststore password.JCurl.Buildertruststore(String store)The truststore containing the server certificate.JCurl.Buildertrusttype(String type)The truststore type.JCurl.Builderurl(String url)The URL to connect to.JCurl.Builderverbosity(int level)Output verbosity.
-
-
-
Method Detail
-
method
public JCurl.Builder method(JCurl.HttpMethod method)
Set the HTTP type of the request. If not set, JCurl usesJCurl.HttpMethod.GET.- Parameters:
method-- Returns:
-
data
public JCurl.Builder data(String payload)
Send a POST request with DATA as request body.
Example:data("{\"message\": \"Hello world!\", \"format\": \"TEXT\"}".- Parameters:
payload-- Returns:
-
header
public JCurl.Builder header(String name, String value)
Send a custom header with the request.
Example:header("Content-Type", "application/json").- Parameters:
name-value-- Returns:
-
form
public JCurl.Builder form(String name, String value)
Send a POST request with CONTENT as "key=value" pairs corresponding to a HTML form. To specify a file, precede the file name with \"@\" (example:form("file", "@/my/test/file.txt").
Sets 'Content-Type: multipart/form-data'.- Parameters:
name-value-- Returns:
-
query
public JCurl.Builder query(String name, String value)
Set request query parameters to be appended to the target URL as "name=value" pairs separated by "&";- Parameters:
name-value-- Returns:
-
cookie
public JCurl.Builder cookie(String name, String value)
Send a custom cookie with the request.- Parameters:
name-value-- Returns:
-
extractCookies
public JCurl.Builder extractCookies(boolean extract)
Extract cookies returned by the call as KEY=VALUE pairs.- Parameters:
extract-- Returns:
-
extract
public JCurl.Builder extract(String label, String node)
Extract NODE from a JSON object returned by the call and return as "LABEL=NODE". Use "." to navigate within the JSON tree.
Example:extract("uid", "userSystemInfo.id")(returns \"uid=12345\").")- Parameters:
label-node-- Returns:
-
extract
public JCurl.Builder extract(String node)
Iterate over a JSON array of objects returned by the call content and extract the value of NODE. Seeextract(String, String)for more details.- Parameters:
node-- Returns:
-
expect
public JCurl.Builder expect(int expectedStatus)
Add HTTP STATUS as an expected response code. By default only HTTP 200 is expected as correct status.- Parameters:
expectedStatus-- Returns:
-
verbosity
public JCurl.Builder verbosity(int level)
Output verbosity. Currently 4 levels are recognised:
0 (default): only displays response content
1: adds request and response details
2: adds certificate details.
3: turns on SSL debugging.- Parameters:
level-- Returns:
-
keystore
public JCurl.Builder keystore(String store)
The keystore containing the certificate to use for authentication.- Parameters:
store-- Returns:
-
storetype
public JCurl.Builder storetype(String type)
The keystore type. Supported values: jks, jceks, pkcs11, pkcs12, bks, dks, windows-my.- Parameters:
type-- Returns:
-
storepass
public JCurl.Builder storepass(String pass)
The keystore password.
-
truststore
public JCurl.Builder truststore(String store)
The truststore containing the server certificate. If unspecified, the default Java truststore (cacerts) is used.- Parameters:
store-- Returns:
-
trusttype
public JCurl.Builder trusttype(String type)
The truststore type. Supported values: jks, jceks, pkcs11, pkcs12, bks, dks, windows-my.- Parameters:
type-- Returns:
-
trustpass
public JCurl.Builder trustpass(String pass)
The truststore password.- Parameters:
pass-- Returns:
-
proxy
public JCurl.Builder proxy(String proxy) throws MalformedURLException
Proxy the request through the specified URL. Applies to all protocols unless excluded with "-noproxy".
Example:proxy("https://my.proxy.com:8080")- Parameters:
proxy-- Returns:
- Throws:
MalformedURLException
-
nonProxyHosts
public JCurl.Builder nonProxyHosts(String hosts)
Bypass the proxy (if defined) for the specified list of |-separated hosts. Supports wildcards. Example:nonProxyHosts("my.host.org|*.otherhost.net").- Parameters:
hosts-- Returns:
-
insecure
public JCurl.Builder insecure(boolean disableChecks)
Disable checks for an HTTPS request. CombinestrustAllHostnames(true)andtrustAllCertificates(true).- Parameters:
disableChecks-- Returns:
-
trustAllHostnames
public JCurl.Builder trustAllHostnames(boolean disableChecks)
Disable SSL hostname verification.- Parameters:
disableChecks-- Returns:
-
trustAllCertificates
public JCurl.Builder trustAllCertificates(boolean disableChecks)
Disable SSL certificate verification.- Parameters:
disableChecks-- Returns:
-
connectTimeout
public JCurl.Builder connectTimeout(int milliseconds)
How long to wait for a connection to the remote resource.- Parameters:
milliseconds-- Returns:
-
readTimeout
public JCurl.Builder readTimeout(int milliseconds)
How long to wait for a response from the remote resource.- Parameters:
milliseconds-- Returns:
-
url
public JCurl.Builder url(String url)
The URL to connect to.- Parameters:
url-- Returns:
-
-