Class JsonRestClient
java.lang.Object
com.sap.cds.integration.cloudsdk.rest.client.JsonRestClient
Implementation of a simple JSON REST client.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
ConstructorsConstructorDescriptionJsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options) Creates the json rest client.JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options, com.sap.cds.services.environment.CdsProperties.ConnectionPool connectionPool) Creates the json rest client.JsonRestClient(String destinationName, String retrievalStrategy) Creates the json rest client. -
Method Summary
Modifier and TypeMethodDescriptioncom.fasterxml.jackson.databind.JsonNodedeleteRequest(String path) Performs a HTTP DELETE request and returns the JSON response.com.fasterxml.jackson.databind.JsonNodegetRequest(String path) Performs a HTTP GET request and returns the JSON response.intPerforms a HTTP GET request and returns the response code only.intpatchRequestWithOnlyResponseCode(String path, com.fasterxml.jackson.databind.JsonNode data) Performs a HTTP PUT request and returns the response code only.com.fasterxml.jackson.databind.JsonNodepostRequest(String path, com.fasterxml.jackson.databind.JsonNode data) Performs a HTTP POST request and returns the JSON response.com.fasterxml.jackson.databind.JsonNodePerforms a HTTP POST request and returns the JSON response.com.fasterxml.jackson.databind.JsonNodeputRequest(String path, com.fasterxml.jackson.databind.JsonNode data) Performs a HTTP PUT request and returns the JSON response.intputRequestWithOnlyResponseCode(String path, com.fasterxml.jackson.databind.JsonNode data) Performs a HTTP PUT request and returns the response code only.
-
Field Details
-
mapper
protected final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Constructor Details
-
JsonRestClient
public JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options) Creates the json rest client.- Parameters:
options- theServiceBindingDestinationOptions
-
JsonRestClient
public JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options, com.sap.cds.services.environment.CdsProperties.ConnectionPool connectionPool) Creates the json rest client.- Parameters:
options- theServiceBindingDestinationOptionsconnectionPool- theCdsProperties.ConnectionPoolsettings
-
JsonRestClient
Creates the json rest client.- Parameters:
destinationName- the name of the destination that should be used
-
-
Method Details
-
getRequest
Performs a HTTP GET request and returns the JSON response.- Parameters:
path- destination URL path- Returns:
- JSON response
- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
getRequestWithOnlyResponseCode
Performs a HTTP GET request and returns the response code only.- Parameters:
path- destination URL path- Returns:
- response code
- Throws:
IOException- in case of a problem or the connection was aborted
-
deleteRequest
Performs a HTTP DELETE request and returns the JSON response.- Parameters:
path- destination URL path- Returns:
- JSON response
- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
putRequestWithOnlyResponseCode
public int putRequestWithOnlyResponseCode(String path, com.fasterxml.jackson.databind.JsonNode data) throws IOException Performs a HTTP PUT request and returns the response code only. This is useful for requests that do not return a JSON response.- Parameters:
path- destination URL pathdata- JSON request body- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
putRequest
public com.fasterxml.jackson.databind.JsonNode putRequest(String path, com.fasterxml.jackson.databind.JsonNode data) throws IOException Performs a HTTP PUT request and returns the JSON response.- Parameters:
path- destination URL pathdata- JSON request body- Returns:
- JSON response
- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
postRequest
public com.fasterxml.jackson.databind.JsonNode postRequest(String path, com.fasterxml.jackson.databind.JsonNode data) throws IOException Performs a HTTP POST request and returns the JSON response.- Parameters:
path- destination URL pathdata- JSON request body- Returns:
- JSON response
- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
postRequest
public com.fasterxml.jackson.databind.JsonNode postRequest(String path, String data, Map<String, Object> headers) throws IOExceptionPerforms a HTTP POST request and returns the JSON response.- Parameters:
path- destination URL pathdata- plain string request bodyheaders- additional request headers- Returns:
- JSON response
- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-
patchRequestWithOnlyResponseCode
public int patchRequestWithOnlyResponseCode(String path, com.fasterxml.jackson.databind.JsonNode data) throws IOException Performs a HTTP PUT request and returns the response code only. This is useful for requests that do not return a JSON response.- Parameters:
path- destination URL pathdata- JSON request body- Throws:
IOException- in case of a problem or the connection was abortedJsonRestClientResponseException- in case when the response HTTP is not 2xx
-