Package org.kissweb
Class RestClient
java.lang.Object
org.kissweb.RestClient
Provides the ability to act as a client to an external REST server.
Supports text, XML, and JSON communications.
Author: Blake McBride
Date: 2/21/21
Author: Blake McBride
Date: 2/21/21
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.json.JSONObjectbasicAuthenticationHeader(String user, String pw) The following builds a JSON header that implements HTTP basic authentication.intThe HTTP response codeReturns the response string.org.json.JSONObjectCall a REST service sending nothing and returning a JSON object.org.json.JSONObjectCall a REST service sending a string and returning a JSON object.org.json.JSONObjectCall a REST service sending a JSON array and returning a JSON object.org.json.JSONObjectCall a REST service sending a JSON object and returning a JSON object.intperformService(String method, String urlStr, String outStr, org.json.JSONObject headers) Performs the web service call.setDebugFileName(String fname) Set a file for debug output.Set a TLS key.Call a REST service sending nothing and returning an XML document.Call a REST service sending a String but returning an XML document.
-
Constructor Details
-
RestClient
public RestClient()
-
-
Method Details
-
setProxy
-
setTLSKey
public RestClient setTLSKey(String clientKeystoreType, String clientKeystorePath, String clientKeystorePassword) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException Set a TLS key.- Parameters:
clientKeystoreType-clientKeystorePath-clientKeystorePassword-- Returns:
- Throws:
KeyStoreExceptionIOExceptionCertificateExceptionNoSuchAlgorithmExceptionUnrecoverableKeyExceptionKeyManagementException
-
jsonCall
public org.json.JSONObject jsonCall(String method, String urlStr, org.json.JSONObject out, org.json.JSONObject headers) throws IOException Call a REST service sending a JSON object and returning a JSON object.- Parameters:
method- POST / GET / etc.urlStr- URL endpointout- what is sent to the serviceheaders- representing all the headers- Returns:
- what is returned from the service
- Throws:
IOException- if error
-
jsonCall
public org.json.JSONObject jsonCall(String method, String urlStr, org.json.JSONArray out, org.json.JSONObject headers) throws IOException Call a REST service sending a JSON array and returning a JSON object.- Parameters:
method- POST / GET / etc.urlStr- URL endpointout- what is sent to the serviceheaders- representing all the headers- Returns:
- what is returned from the service
- Throws:
IOException- if error
-
jsonCall
Call a REST service sending nothing and returning a JSON object.- Parameters:
method-urlStr-- Returns:
- Throws:
IOException
-
xmlCall
public Document xmlCall(String method, String urlStr, String outStr, org.json.JSONObject headers) throws IOException, ParserConfigurationException, SAXException Call a REST service sending a String but returning an XML document.- Parameters:
method- POST / GET / etc.urlStr- URL endpointoutStr- what is sent to the serviceheaders- representing all of the headers- Returns:
- what is returned from the service
- Throws:
IOException- if errorParserConfigurationException- if errorSAXException- if error
-
xmlCall
public Document xmlCall(String method, String urlStr) throws IOException, ParserConfigurationException, SAXException Call a REST service sending nothing and returning an XML document.- Parameters:
method-urlStr-- Returns:
- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
jsonCall
public org.json.JSONObject jsonCall(String method, String urlStr, String outStr, org.json.JSONObject headers) throws IOException Call a REST service sending a string and returning a JSON object.
'headers' is a JSON object. Each element is a header / value combination. These are sent as the header of the REST call.- Parameters:
method- POST / GET / etc.urlStr- URL endpointoutStr- what is sent to the serviceheaders- representing all of the headers- Returns:
- the JSON return from the call
- Throws:
IOException- if the communication fail, an exception is thrown
-
performService
public int performService(String method, String urlStr, String outStr, org.json.JSONObject headers) throws IOException Performs the web service call. Sends and returns raw strings.
'headers' is a JSON object. Each element is a header / value combination. These are sent as the header of the REST call.- Parameters:
method- POST / GET / etc.urlStr- the URL endpointoutStr- what is sent to the serviceheaders- representing all of the headers- Returns:
- the HTTP return code
- Throws:
IOException- if the communication fail, an exception is thrown
-
basicAuthenticationHeader
The following builds a JSON header that implements HTTP basic authentication. Additional items may be added to the returned header object.- Parameters:
user-pw-- Returns:
- a new JSON header object containing the basic authentication
-
getResponseCode
public int getResponseCode()The HTTP response code- Returns:
-
getResponseString
Returns the response string.- Returns:
-
setDebugFileName
Set a file for debug output.- Parameters:
fname-- Returns:
-