From 428b365995b02b39e6b61d5061be76817d3bf51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Ruiz?= Date: Wed, 23 Oct 2024 19:25:02 +0200 Subject: [PATCH] Commments --- .../rest/RestPostCommandAction.java | 3 -- .../utils/httpclient/HttpRestClientDemo.java | 44 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/plugins/command-manager/src/main/java/com/wazuh/commandmanager/rest/RestPostCommandAction.java b/plugins/command-manager/src/main/java/com/wazuh/commandmanager/rest/RestPostCommandAction.java index c9ec1c2..f0a8034 100644 --- a/plugins/command-manager/src/main/java/com/wazuh/commandmanager/rest/RestPostCommandAction.java +++ b/plugins/command-manager/src/main/java/com/wazuh/commandmanager/rest/RestPostCommandAction.java @@ -115,9 +115,6 @@ private RestChannelConsumer handlePost(RestRequest request) throws IOException { .toString(); SimpleHttpResponse response = HttpRestClientDemo.runWithResponse(receiverURI, payload, document.getId()); - - // SimpleHttpResponse response = httpClient.post(receiverURI, payload, - // document.getId()); log.info("Received response to POST request with code [{}]", response.getCode()); log.info("Raw response:\n{}", response.getBodyText()); } catch (Exception e) { diff --git a/plugins/command-manager/src/main/java/com/wazuh/commandmanager/utils/httpclient/HttpRestClientDemo.java b/plugins/command-manager/src/main/java/com/wazuh/commandmanager/utils/httpclient/HttpRestClientDemo.java index 036121b..f8cde0e 100644 --- a/plugins/command-manager/src/main/java/com/wazuh/commandmanager/utils/httpclient/HttpRestClientDemo.java +++ b/plugins/command-manager/src/main/java/com/wazuh/commandmanager/utils/httpclient/HttpRestClientDemo.java @@ -29,28 +29,28 @@ public class HttpRestClientDemo { * @param endpoint POST's requests endpoint as a well-formed URI * @param body POST's request body as a JSON string. */ - // public static void run(String endpoint, String body) { - // log.info("Executing POST request"); - // AccessController.doPrivileged( - // (PrivilegedAction) - // () -> { - // HttpRestClient httpClient = HttpRestClient.getInstance(); - // try { - // URI host = new URIBuilder(endpoint).build(); - // SimpleHttpResponse response = - // httpClient.post(host, body, "randomId"); - // log.info( - // "Received response to POST request with code {}", - // response.getCode()); - // log.info("Raw response:\n{}", response.getBodyText()); - // } catch (URISyntaxException e) { - // log.error("Bad URI:{}", e.getMessage()); - // } catch (Exception e) { - // log.error("Error reading response: {}", e.getMessage()); - // } - // return null; - // }); - // } + public static void run(String endpoint, String body) { + log.info("Executing POST request"); + AccessController.doPrivileged( + (PrivilegedAction) + () -> { + HttpRestClient httpClient = HttpRestClient.getInstance(); + try { + URI host = new URIBuilder(endpoint).build(); + SimpleHttpResponse response = + httpClient.post(host, body, "randomId"); + log.info( + "Received response to POST request with code {}", + response.getCode()); + log.info("Raw response:\n{}", response.getBodyText()); + } catch (URISyntaxException e) { + log.error("Bad URI:{}", e.getMessage()); + } catch (Exception e) { + log.error("Error reading response: {}", e.getMessage()); + } + return null; + }); + } /** * Demo method to test the {@link HttpRestClient} class.