Class RestClientUtil

java.lang.Object
org.apache.directory.scim.client.rest.RestClientUtil

public final class RestClientUtil extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    checkForFourOhFour(jakarta.ws.rs.client.WebTarget target, jakarta.ws.rs.core.Response response)
     
    static void
    checkForSuccess(jakarta.ws.rs.core.Response response)
     
    static void
    close(jakarta.ws.rs.core.Response response)
    Closes response and suppresses any known/expected exceptions from closing it.
    static void
    close(jakarta.ws.rs.core.Response response, Consumer<Throwable> consumer)
    Closes response and passes any known/expected exceptions from closing it to consumer (e.g.
    extractIdFromLocationTag(jakarta.ws.rs.core.Response response)
     
    static boolean
    isSuccessful(jakarta.ws.rs.core.Response response)
     
    static <T> Optional<T>
    readEntity(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> entityType)
    Read an entity from the response if it was found.
    static <T> Optional<T>
    readEntity(jakarta.ws.rs.core.Response response, Class<T> entityType)
    Read an entity from the response if it was found.
    <T> Optional<T>
    tryReadEntity(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> entityType)
    Read an entity from the response if it was found and returned.
    <T> Optional<T>
    tryReadEntity(jakarta.ws.rs.core.Response response, Class<T> entityType)
    Read an entity from the response if it was found and returned.
    static void
    verifyNotFourOhFour(jakarta.ws.rs.client.WebTarget target, jakarta.ws.rs.core.Response response)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • checkForSuccess

      public static void checkForSuccess(jakarta.ws.rs.core.Response response) throws RestException
      Throws:
      RestException
    • checkForFourOhFour

      public static boolean checkForFourOhFour(jakarta.ws.rs.client.WebTarget target, jakarta.ws.rs.core.Response response)
    • verifyNotFourOhFour

      public static void verifyNotFourOhFour(jakarta.ws.rs.client.WebTarget target, jakarta.ws.rs.core.Response response) throws RestException
      Throws:
      RestException
    • isSuccessful

      public static boolean isSuccessful(jakarta.ws.rs.core.Response response)
    • close

      public static void close(jakarta.ws.rs.core.Response response)
      Closes response and suppresses any known/expected exceptions from closing it.
      Parameters:
      response -
    • close

      public static void close(jakarta.ws.rs.core.Response response, Consumer<Throwable> consumer)
      Closes response and passes any known/expected exceptions from closing it to consumer (e.g. for logging).
      Parameters:
      response -
      consumer -
    • tryReadEntity

      public <T> Optional<T> tryReadEntity(jakarta.ws.rs.core.Response response, Class<T> entityType) throws RestException, jakarta.ws.rs.ProcessingException, IllegalStateException
      Read an entity from the response if it was found and returned.
      Parameters:
      response - the Response to read from
      entityType - the type of entity
      Returns:
      Optional.empty() if Not Found or empty response, otherwise Optional.ofNullable(T)
      Throws:
      RestException - if response is an error response other than 404 Not Found
      jakarta.ws.rs.ProcessingException - see Response.readEntity(Class)
      IllegalStateException - see Response.readEntity(Class)
      RestException
    • tryReadEntity

      public <T> Optional<T> tryReadEntity(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> entityType) throws RestException, jakarta.ws.rs.ProcessingException, IllegalStateException
      Read an entity from the response if it was found and returned.
      Parameters:
      response - the Response to read from
      entityType - the type of entity
      Returns:
      Optional.empty() if Not Found or empty response, otherwise Optional.ofNullable(T)
      Throws:
      RestException - if response is an error response other than 404 Not Found
      jakarta.ws.rs.ProcessingException - see Response.readEntity(GenericType)
      IllegalStateException - see Response.readEntity(GenericType)
      RestException
    • readEntity

      public static <T> Optional<T> readEntity(jakarta.ws.rs.core.Response response, Class<T> entityType) throws RestException, jakarta.ws.rs.ProcessingException, IllegalStateException

      Read an entity from the response if it was found.

      Useful for REST endpoints that MUST return an entity.

      Parameters:
      response - the Response to read from
      entityType - the type of entity
      Returns:
      Optional.empty() if Not Found, otherwise Optional.of(T)
      Throws:
      RestException - if response is an error response other than 404 Not Found
      jakarta.ws.rs.ProcessingException - see Response.readEntity(Class)
      IllegalStateException - see Response.readEntity(Class)
      RestException
    • readEntity

      public static <T> Optional<T> readEntity(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> entityType) throws RestException, jakarta.ws.rs.ProcessingException, IllegalStateException

      Read an entity from the response if it was found.

      Useful for REST endpoints that MUST return an entity.

      Parameters:
      response - the Response to read from
      entityType - the type of entity
      Returns:
      Optional.empty() if Not Found, otherwise Optional.of(T)
      Throws:
      RestException - if response is an error response other than 404 Not Found
      jakarta.ws.rs.ProcessingException - see Response.readEntity(GenericType)
      IllegalStateException - see Response.readEntity(GenericType)
      RestException
    • extractIdFromLocationTag

      public static Optional<String> extractIdFromLocationTag(jakarta.ws.rs.core.Response response)