| 9 | import java.net.http.HttpResponse; |
| 10 | |
| 11 | public class CDGClient { |
| 12 | |
| 13 | /** |
| 14 | * makeRequestAndOutputResponse |
| 15 | * |
| 16 | * Make a GET request to the given URL and output the response per the config |
| 17 | * |
| 18 | * The authentication parameters are automatically added. |
| 19 | * |
| 20 | * @param url the parameterless url to call |
| 21 | * |
| 22 | */ |
| 23 | public static void makeRequestAndOutputResponse(String url) { |
| 24 | |
| 25 | // Show where we're making the call to |
| 26 | Utils.outputMessage("Making call to " + url); |
| 27 | |
| 28 | // Make the call and get the response |
| 29 | HttpResponse<String> response = makeRequestGetResponse(url); |
| 30 | |
| 31 | // Output the response |
| 32 | outputHttpResponse(response, url); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * makeRequestGetResponse |
| 37 | * |
| 38 | * Make a request to the given url and return the response |
| 39 | * |
| 40 | * The authentication parameters are automatically added. |
| 41 | * |
| 42 | * @param url the parameterless url to call |
| 43 | * @return HttpResponse |
| 44 | */ |
| 45 | public static HttpResponse<String> makeRequestGetResponse(String url) { |
| 46 | |
| 47 | // Build the client and request |
| 48 | HttpClient client = HttpClient.newHttpClient(); |
| 49 | HttpRequest request = HttpRequest.newBuilder() |
| 50 | .uri(URI.create(appendParameters(url))) |
| 51 | .build(); |
| 52 | |
| 53 | // Make the call & get a response |
| 54 | HttpResponse<String> response = null; |
| 55 | try { |
| 56 | response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
| 57 | } catch (IOException | InterruptedException ex) { |
| 58 | Utils.outputMessage("Something went wrong with the call to " + url); |
| 59 | Utils.outputMessageAndBail(ex.getMessage()); |
| 60 | } |
| 61 | |
| 62 | // If our response is null, something wasn't right |
| 63 | if (response == null || response.body() == null) { |
| 64 | Utils.outputMessageAndBail("Something went wrong, we didn't get a response from " + url); |
| 65 | } |
| 66 | |
| 67 | return response; |
| 68 | } |
nothing calls this directly
no outgoing calls
no test coverage detected