-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] HttpUrlConnection -> WebClient로 변경
- Loading branch information
1 parent
28983fd
commit e1ab548
Showing
2 changed files
with
25 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 20 additions & 21 deletions
41
...olmateServer/src/main/java/com/nonsoolmate/nonsoolmateServer/global/util/ApiCallUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
package com.nonsoolmate.nonsoolmateServer.global.util; | ||
|
||
import com.nonsoolmate.nonsoolmateServer.external.discord.model.JsonObject; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.URL; | ||
import javax.net.ssl.HttpsURLConnection; | ||
|
||
import io.jsonwebtoken.io.IOException; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Slf4j | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ApiCallUtil { | ||
|
||
public static void callDiscordAppenderPostAPI(String urlString, JsonObject json) throws IOException { | ||
URL url = new URL(urlString); | ||
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection(); | ||
connection.addRequestProperty("Content-Type", "application/json"); | ||
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); | ||
connection.setDoOutput(true); | ||
connection.setRequestMethod("POST"); | ||
|
||
try (OutputStream stream = connection.getOutputStream()) { | ||
stream.write(json.toString().getBytes()); | ||
stream.flush(); | ||
|
||
connection.getInputStream().close(); | ||
connection.disconnect(); | ||
|
||
} catch (IOException ioException) { | ||
throw ioException; | ||
public static void callDiscordAppenderPostAPI(String urlString, JsonObject json) { | ||
WebClient webClient = WebClient.create(); | ||
try { | ||
webClient.post() | ||
.uri(urlString) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("User-Agent", "Java-DiscordWebhook-BY-Gelox_") | ||
.body(Mono.just(json.toString()), String.class) | ||
.retrieve() | ||
.bodyToMono(Void.class) | ||
.block(); | ||
} catch (IOException e) { | ||
log.error("Discord Appender API 호출 실패", e.getMessage()); | ||
throw e; | ||
} | ||
} | ||
} | ||
|