Class JsonRestClient

java.lang.Object
com.sap.cds.integration.cloudsdk.rest.client.JsonRestClient

public class JsonRestClient extends Object
Implementation of a simple JSON REST client.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.fasterxml.jackson.databind.ObjectMapper
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options)
    Creates the json rest client.
    JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options, CdsProperties.ConnectionPool connectionPool)
    Creates the json rest client.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.fasterxml.jackson.databind.JsonNode
    Performs a HTTP DELETE request and returns the JSON response.
    com.fasterxml.jackson.databind.JsonNode
    Performs a HTTP GET request and returns the JSON response.
    int
    Performs a HTTP GET request and returns the response code only.
    com.fasterxml.jackson.databind.JsonNode
    postRequest(String path, com.fasterxml.jackson.databind.JsonNode data)
    Performs a HTTP POST request and returns the JSON response.
    com.fasterxml.jackson.databind.JsonNode
    postRequest(String path, String data, Map<String,Object> headers)
    Performs a HTTP POST request and returns the JSON response.
    com.fasterxml.jackson.databind.JsonNode
    putRequest(String path, com.fasterxml.jackson.databind.JsonNode data)
    Performs a HTTP PUT request and returns the JSON response.
    int
    putRequestWithOnlyResponseCode(String path, com.fasterxml.jackson.databind.JsonNode data)
    Performs a HTTP PUT request and returns the response code only.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 - the ServiceBindingDestinationOptions
    • JsonRestClient

      public JsonRestClient(com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions options, CdsProperties.ConnectionPool connectionPool)
      Creates the json rest client.
      Parameters:
      options - the ServiceBindingDestinationOptions
      connectionPool - the CdsProperties.ConnectionPool settings
  • Method Details

    • getRequest

      public com.fasterxml.jackson.databind.JsonNode getRequest(String path) throws IOException
      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 aborted
      JsonRestClientResponseException - in case when the response HTTP is not 2xx
    • getRequestWithOnlyResponseCode

      public int getRequestWithOnlyResponseCode(String path) throws IOException
      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

      public com.fasterxml.jackson.databind.JsonNode deleteRequest(String path) throws IOException
      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 aborted
      JsonRestClientResponseException - 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 path
      data - JSON request body
      Throws:
      IOException - in case of a problem or the connection was aborted
      JsonRestClientResponseException - 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 path
      data - JSON request body
      Returns:
      JSON response
      Throws:
      IOException - in case of a problem or the connection was aborted
      JsonRestClientResponseException - 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 path
      data - JSON request body
      Returns:
      JSON response
      Throws:
      IOException - in case of a problem or the connection was aborted
      JsonRestClientResponseException - 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 IOException
      Performs a HTTP POST request and returns the JSON response.
      Parameters:
      path - destination URL path
      data - plain string request body
      headers - additional request headers
      Returns:
      JSON response
      Throws:
      IOException - in case of a problem or the connection was aborted
      JsonRestClientResponseException - in case when the response HTTP is not 2xx