java.lang.Object
com.ssgllc.fish.service.util.published.ApiUtil

@Component public final class ApiUtil extends Object
  • Constructor Details

    • ApiUtil

      public ApiUtil()
  • Method Details

    • downloadFile

      public static byte[] downloadFile(String urlPath)
      Downloads the contents of a file from a specified URL as a byte array.
      Parameters:
      urlPath - The URL of the file to be downloaded.
      Returns:
      A byte array containing the file's contents, or null if an error occurs during download.

      Example:
      return apiUtil.downloadFile("https://resources.casetivity.com/images/SsgLogo.png")

      Returns:
      A byte array representing the contents of the downloaded file.
      Note: If an exception occurs during the download, the method returns null.
    • getRequest

      public static org.springframework.http.ResponseEntity<Map<String,Object>> getRequest(String url, Map<String,String> headers)
      Sends an HTTP GET request to the specified URL with optional headers and returns the response.
      Parameters:
      url - The URL to send the GET request to.
      headers - A map of headers to include in the request, where each key is a header name and each value is the corresponding header value.
      Returns:
      A ResponseEntity containing a map of the response data, where the response body is represented as a Map<String, Object>.

      Example:
      def headers = ["Authorization": "Bearer token123"]
      return apiUtil.getRequest("https://snapshot.core.casetivity.com/app/api/global-alerts", headers)

      Returns:
      A ResponseEntity with a map representing the JSON response data from the URL.
      Note: The headers parameter can be null if no headers are needed for the request.
    • postRequest

      public static org.springframework.http.ResponseEntity<Map<String,Object>> postRequest(String url, String body, Map<String,String> headers)
      Sends an HTTP POST request to the specified URL with a JSON body and optional headers, then returns the response.
      Parameters:
      url - The URL to send the POST request to.
      body - The JSON-formatted string to include in the request body.
      headers - A map of headers to include in the request, where each key is a header name and each value is the corresponding header value.
      Returns:
      A ResponseEntity containing a map of the response data, where the response body is represented as a Map<String, Object>.

      Example:
      def headers = ["Content-Type": "application/json", "Authorization": "Bearer token123"]
      def body = '{"firstName": "John", "lastName": "Doe", "birthDate": "2000-01-01"}'
      return apiUtil.postRequest("https://snapshot.core.casetivity.com/app/api/people", body, headers)

      Returns:
      A ResponseEntity with a map representing the JSON response data from the URL.
      Note: The headers parameter can be null if no headers are needed for the request.