Class ODataRequestGeneric

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.client.request.ODataRequestGeneric
All Implemented Interfaces:
ODataRequestExecutable
Direct Known Subclasses:
ODataRequestAction, ODataRequestBatch, ODataRequestCreate, ODataRequestDelete, ODataRequestFunction, ODataRequestRead, ODataRequestReadByKey, ODataRequestUpdate

public abstract class ODataRequestGeneric extends Object implements ODataRequestExecutable
Generic OData request class to provide default features for service requests.
  • Field Details

    • servicePath

      @Nonnull protected final String servicePath
      The service path of the targeted OData service. E.g. sap/opu/odata/sap/API_BUSINESS_PARTNER
    • resourcePath

      @Nonnull protected final ODataResourcePath resourcePath
      The ODataResourcePath that identifies the OData resource to operate on. E.g. /BusinessPartner('123')/BusinessPartnerAddress(456).
    • csrfTokenRetriever

      @Nullable protected CsrfTokenRetriever csrfTokenRetriever
      The CSRF token retriever.
  • Method Details

    • getRelativeUri

      @Nonnull public abstract URI getRelativeUri(@Nonnull UriEncodingStrategy uriEncodingStrategy)
      Get the static request URI of the OData resource.
      Parameters:
      uriEncodingStrategy - URI encoding strategy.
      Returns:
      The String representation of the request URI.
    • getRelativeUri

      @Nonnull public URI getRelativeUri()
      Get the static request URI of the OData resource.
      Returns:
      The String representation of the request URI.
    • getRequestQuery

      @Nonnull public String getRequestQuery()
      Use all OData query information to construct a HTTP request query String.
      Returns:
      The request query.
    • addListener

      public void addListener(@Nonnull ODataRequestListener listener)
      Attach a listener to the request process.
      Parameters:
      listener - The listener to react on OData request actions.
    • setHeader

      public void setHeader(@Nonnull String key, @Nullable String value)
      Replace a header in the OData HTTP request.
      Parameters:
      key - The header name.
      value - The header value.
    • setHeader

      public void setHeader(@Nonnull String key, @Nonnull Collection<String> values)
      Replace a header with multiple values in the OData HTTP request.
      Parameters:
      key - The header name.
      values - The header values.
      Since:
      4.27.0
    • addHeader

      public void addHeader(@Nonnull String key, @Nullable String value)
      Add a header to the OData HTTP request.
      Parameters:
      key - The header name.
      value - The header value.
    • addHeaderIfAbsent

      public void addHeaderIfAbsent(@Nonnull String key, @Nullable String value)
      Add a header to the OData HTTP request, if it is not included already.
      Parameters:
      key - The header name.
      value - The header value.
    • addQueryParameter

      public void addQueryParameter(@Nonnull String key, @Nullable String value)
      Add a query parameter to the HTTP request. The value must be encoded.
      Parameters:
      key - The parameter key.
      value - The encoded parameters value.
    • tryExecute

      @Nonnull protected io.vavr.control.Try<ODataRequestResultGeneric> tryExecute(@Nonnull Supplier<org.apache.http.HttpResponse> httpOperation, @Nonnull org.apache.http.client.HttpClient httpClient)
      Internal execute method. It will perform the given httpOperation on the given request and ensure a healthy HTTP response code. Failures will always be a subtype of ODataException
      Parameters:
      httpOperation - The HTTP operation to perform, e.g. ODataHttpRequest.requestGet()
      httpClient - The HTTP client instance that is being used to perform the operation.
      Returns:
      A Try containing either a successful ODataRequestResultGeneric or an ODataException.
    • tryExecuteWithCsrfToken

      @Nonnull protected io.vavr.control.Try<ODataRequestResultGeneric> tryExecuteWithCsrfToken(@Nonnull org.apache.http.client.HttpClient httpClient, @Nonnull Supplier<org.apache.http.HttpResponse> httpOperation)
      Internal execute method. It will attempt to retrieve a CSRF token before issuing the actual request via tryExecute(Supplier, HttpClient).

      CSRF token retrieval is skipped, if a token is already present. The actual request is performed regardless whether or not a CSRF token was retrieved.

      Parameters:
      httpClient - An HttpClient to execute the CSRF token retrieval.
      httpOperation - The HTTP operation to perform, e.g. ODataHttpRequest.requestGet()
      Returns:
      A Try containing either a successful ODataRequestResultGeneric or an ODataException.
    • getHeaders

      @Nonnull public Map<String,Collection<String>> getHeaders()
      Get the list of headers that will be sent with this request. To add headers, please use addHeader and addHeaderIfAbsent
      Returns:
      The list of headers.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(@Nullable Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getServicePath

      @Nonnull public String getServicePath()
      The service path of the targeted OData service. E.g. sap/opu/odata/sap/API_BUSINESS_PARTNER
    • getResourcePath

      @Nonnull protected ODataResourcePath getResourcePath()
      The ODataResourcePath that identifies the OData resource to operate on. E.g. /BusinessPartner('123')/BusinessPartnerAddress(456).
    • getProtocol

      public ODataProtocol getProtocol()
      The OData protocol version of this request.
    • getListeners

      protected List<ODataRequestListener> getListeners()
      List of listeners to observe and react on OData actions.
    • getQueryParameters

      protected Map<String,String> getQueryParameters()
      Map of additional generic HTTP query parameters.
    • setCsrfTokenRetriever

      public void setCsrfTokenRetriever(@Nullable CsrfTokenRetriever csrfTokenRetriever)
      The CSRF token retriever.