java.lang.Object
org.diabetestechnology.drh.service.http.Helpers

public class Helpers extends Object
  • Constructor Details

    • Helpers

      public Helpers()
  • Method Details

    • getBaseUrl

      public static String getBaseUrl(jakarta.servlet.http.HttpServletRequest request)
    • findFirstHeaderValue

      public static String findFirstHeaderValue(jakarta.servlet.http.HttpServletRequest request, String... headerNames)
      Finds the first non-null and non-empty header value from the given header names.
      Parameters:
      request - the HttpServletRequest object
      headerNames - the array of header names to check
      Returns:
      the first non-null and non-empty header value, or null if none found
    • textFromURL

      public static String textFromURL(String requestURL) throws IOException, InterruptedException
      Retrieves the content of the specified URL as a String.

      This method sends an HTTP GET request to the provided URL and returns the response body as a String. The content is read using UTF-8 encoding.

      Usage example:

       
       String content = textFromURL("http://example.com");
       System.out.println(content);
       
       
      Parameters:
      requestURL - the URL from which to retrieve the content
      Returns:
      the content of the URL as a String
      Throws:
      IOException - if an I/O error occurs while sending or receiving the HTTP request
      InterruptedException - if the operation is interrupted