diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandler.java b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandler.java index f644f044..5e920689 100755 --- a/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandler.java +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/main/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandler.java @@ -25,6 +25,7 @@ import org.springframework.web.server.WebExceptionHandler; import reactor.core.publisher.Mono; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -78,14 +79,14 @@ private Mono getExceptionResponse(ServerHttpResponse response, EgovErrorCo private Mono handlerResponse(ServerHttpResponse response, String timestamp, int status, String code, String message) { response.setStatusCode(HttpStatus.valueOf(status)); - response.getHeaders().setContentType(MediaType.APPLICATION_JSON); + response.getHeaders().setContentType(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8)); Map map = new HashMap<>(); map.put("timestamp", timestamp); map.put("status", HttpStatus.valueOf(status)); map.put("code", code); map.put("message", message); JSONObject jsonObject = new JSONObject(map); - DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(jsonObject).getBytes()); + DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(jsonObject).getBytes(StandardCharsets.UTF_8)); return response.writeWith(Mono.just(dataBuffer)); } diff --git a/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandlerTest.java b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandlerTest.java index b7dcb4cc..0b70ddc0 100755 --- a/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandlerTest.java +++ b/Presentation/org.egovframe.rte.ptl.reactive/src/test/java/org/egovframe/rte/ptl/reactive/exception/EgovExceptionHandlerTest.java @@ -1,11 +1,18 @@ package org.egovframe.rte.ptl.reactive.exception; +import org.egovframe.rte.ptl.reactive.annotation.EgovController; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.http.MediaType; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.web.bind.annotation.GetMapping; +import reactor.core.publisher.Mono; + +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(SpringExtension.class) public class EgovExceptionHandlerTest { @@ -14,7 +21,7 @@ public class EgovExceptionHandlerTest { @BeforeEach public void setUp() { - this.webTestClient = WebTestClient.bindToController(new SampleController()) + this.webTestClient = WebTestClient.bindToController(new SampleController(), new KoreanMessageController()) .controllerAdvice(new EgovExceptionHandler()) .build(); } @@ -25,7 +32,30 @@ public void exceptionHandlerTest() { .uri("/test") .accept(MediaType.APPLICATION_JSON) .exchange() - .expectStatus().isNotFound(); + .expectStatus().isNotFound() + .expectHeader().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")); + } + + @Test + public void koreanMessageTest() { + this.webTestClient.get() + .uri("/korean-message") + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus().is5xxServerError() + .expectBody() + .consumeWith(result -> assertTrue(new String(result.getResponseBody(), StandardCharsets.UTF_8) + .contains("\"message\":\"서비스 예외 메시지\""))); + } + + @EgovController + private static class KoreanMessageController { + + @GetMapping("/korean-message") + public Mono koreanMessage() { + return Mono.error(new EgovServiceException("서비스 예외 메시지")); + } + } }