Class Helpers
java.lang.Object
org.diabetestechnology.drh.service.http.Helpers
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
findFirstHeaderValue
(jakarta.servlet.http.HttpServletRequest request, String... headerNames) Finds the first non-null and non-empty header value from the given header names.static String
getBaseUrl
(jakarta.servlet.http.HttpServletRequest request) static String
textFromURL
(String requestURL) Retrieves the content of the specified URL as a String.
-
Constructor Details
-
Helpers
public Helpers()
-
-
Method Details
-
getBaseUrl
-
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 objectheaderNames
- the array of header names to check- Returns:
- the first non-null and non-empty header value, or null if none found
-
textFromURL
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 requestInterruptedException
- if the operation is interrupted
-