Class RestUtils

java.lang.Object
com.redhat.parodos.utils.RestUtils

public abstract class RestUtils extends Object
RestUtils is a utility class. All its methods must be declared as static so they can't be overridden.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.springframework.http.ResponseEntity<String>
    executeGet(String urlString)
    Execute the GET HTTP method to the given URL
    static org.springframework.http.ResponseEntity<String>
    executePost(String urlString, String payload)
    Create a new resource by POSTing the given payload to the URL, and returns the response as ResponseEntity.
    static org.springframework.http.ResponseEntity<String>
    executePost(String urlString, org.springframework.http.HttpEntity<?> requestEntity)
    Create a new resource by POSTing the given requestEntity to the URL, and returns the response as String.
    static <T, E> org.springframework.http.ResponseEntity<E>
    executePost(String urlString, T requestDto, String username, String password, Class<E> responseType)
     
    static String
    getBase64Creds(String username, String password)
    Generates a Base64 encoding of username:password string
    static org.springframework.http.HttpEntity<String>
    getRequestWithHeaders(String username, String password)
    Creates a new HttpHeader and set the Authorization object according to @see getBase64Creds
    static <T> org.springframework.http.HttpEntity<T>
    getRequestWithHeaders(T request, String username, String password)
    Creates a new HttpHeader with request and set the Authorization object according to @see getBase64Creds
    static org.springframework.http.ResponseEntity<String>
    restExchange(String urlString, String username, String password)
    Execute the GET HTTP method to the given URL, writing the given request entity to the request, and returns the response as ResponseEntity.
    static <E> org.springframework.http.ResponseEntity<E>
    restExchange(String urlString, String username, String password, Class<E> responseType)
     

    Methods inherited from class java.lang.Object

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

    • executePost

      public static org.springframework.http.ResponseEntity<String> executePost(String urlString, String payload)
      Create a new resource by POSTing the given payload to the URL, and returns the response as ResponseEntity.
      Parameters:
      urlString - the URL
      payload - object to post
      Returns:
      See Also:
      • RestTemplate.postForEntity(URI, Object, Class)
      • ResponseEntity
    • executePost

      public static org.springframework.http.ResponseEntity<String> executePost(String urlString, org.springframework.http.HttpEntity<?> requestEntity)
      Create a new resource by POSTing the given requestEntity to the URL, and returns the response as String.
      Parameters:
      urlString - the URL
      requestEntity - object to post
      Returns:
      the response as string
      See Also:
      • RestTemplate.postForEntity(URI, Object, Class)
    • executePost

      public static <T, E> org.springframework.http.ResponseEntity<E> executePost(String urlString, T requestDto, String username, String password, Class<E> responseType)
    • executeGet

      public static org.springframework.http.ResponseEntity<String> executeGet(String urlString)
      Execute the GET HTTP method to the given URL
      Parameters:
      urlString - the URL
      Returns:
      HTTP response as string
    • restExchange

      public static org.springframework.http.ResponseEntity<String> restExchange(String urlString, String username, String password)
      Execute the GET HTTP method to the given URL, writing the given request entity to the request, and returns the response as ResponseEntity.
      Parameters:
      urlString - the URL
      username - the username
      password - the password
      Returns:
      See Also:
      • RestTemplate.exchange(String, HttpMethod, HttpEntity, Class, Object...)
      • ResponseEntity
    • restExchange

      public static <E> org.springframework.http.ResponseEntity<E> restExchange(String urlString, String username, String password, Class<E> responseType)
    • getRequestWithHeaders

      public static org.springframework.http.HttpEntity<String> getRequestWithHeaders(String username, String password)
      Creates a new HttpHeader and set the Authorization object according to @see getBase64Creds
      Parameters:
      username - the username
      password - the password
      Returns:
      the @see org.springframework.http.HttpEntity
    • getRequestWithHeaders

      public static <T> org.springframework.http.HttpEntity<T> getRequestWithHeaders(T request, String username, String password)
      Creates a new HttpHeader with request and set the Authorization object according to @see getBase64Creds
      Parameters:
      username - the username
      password - the password
      Returns:
      the @see org.springframework.http.HttpEntity
    • getBase64Creds

      public static String getBase64Creds(String username, String password)
      Generates a Base64 encoding of username:password string
      Parameters:
      username - the username
      password - the password
      Returns:
      the Base64 encoded string