Skip to content

Commit

Permalink
#1784 Used latest Apache HttpClient 5 explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
vrudas committed Aug 1, 2024
1 parent e782770 commit 3fc4ddd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@
<version>1.7.6</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
</dependency>

<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/ai/elimu/util/DiscordHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import ai.elimu.web.context.EnvironmentContextLoaderListener;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;

/**
* Helper class for posting notifications in Discord.
* <p />
Expand All @@ -22,7 +23,7 @@
public class DiscordHelper {

private static Logger logger = LogManager.getLogger();

public static void sendChannelMessage(
String content,
String embedTitle,
Expand All @@ -31,7 +32,7 @@ public static void sendChannelMessage(
String embedThumbnailUrl
) {
logger.info("sendChannelMessage");

// Prepare the JSON body
JsonObject jsonBody = new JsonObject();
jsonBody.addProperty("content", content);
Expand Down Expand Up @@ -59,7 +60,7 @@ public static void sendChannelMessage(
jsonBody.add("embeds", embedsJsonArray);
}
logger.info("jsonBody: " + jsonBody);

if (EnvironmentContextLoaderListener.env == Environment.PROD) {
// Send the message to Discord
CloseableHttpClient client = HttpClients.createDefault();
Expand All @@ -71,7 +72,7 @@ public static void sendChannelMessage(
httpPost.setEntity(entity);
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = client.execute(httpPost);
logger.info("httpResponse.getStatusLine(): " + httpResponse.getStatusLine());
logger.info("httpResponse.getStatusLine(): " + httpResponse);
client.close();
} catch (IOException e) {
logger.error(e);
Expand Down

0 comments on commit 3fc4ddd

Please sign in to comment.