Skip to content

fix: reactive 예외 핸들러 JSON 응답 UTF-8 인코딩 명시#256

Open
z3rotig4r wants to merge 1 commit into
eGovFramework:mainfrom
z3rotig4r:fix/reactive-exception-charset
Open

fix: reactive 예외 핸들러 JSON 응답 UTF-8 인코딩 명시#256
z3rotig4r wants to merge 1 commit into
eGovFramework:mainfrom
z3rotig4r:fix/reactive-exception-charset

Conversation

@z3rotig4r

@z3rotig4r z3rotig4r commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

변경 이유

reactive 모듈 전역 예외 핸들러(EgovExceptionHandler)가 JSON 에러 응답 본문을 플랫폼 기본 charset으로 직렬화합니다.

  • handlerResponse(EgovExceptionHandler.java:88)는 JSONObject.toJSONString(...).getBytes()로 본문을 인코딩합니다. 인자 없는 getBytes()는 JVM 기본 charset(file.encoding)을 사용하므로, 기본값이 UTF-8이 아닌 환경(예: MS949 한글 Windows 서버)에서는 응답 바이트가 깨집니다.
  • 응답 Content-Type은 application/json(L81)으로 charset이 명시되지 않습니다. JSON은 RFC 8259상 UTF-8이어야 합니다.
  • 핸들러는 EgovServiceException.getMessage()를 그대로 본문에 담습니다. 애플리케이션이 한글 예외 메시지를 던지면 클라이언트가 받는 에러 메시지가 깨질 수 있습니다.

변경 내용

EgovExceptionHandler.handlerResponse만 수정했습니다.

  • 응답 Content-Type을 application/json;charset=UTF-8로 명시(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8)).
  • 본문 직렬화를 getBytes(StandardCharsets.UTF_8)로 변경.

기존 로직과 메서드 시그니처는 그대로 두었습니다.

테스트 방법

EgovExceptionHandlerTest에 회귀 테스트를 추가했습니다.

  • 기존 테스트에 응답 Content-Type이 application/json;charset=UTF-8인지 단정을 추가. 이 단정은 수정 전(charset 미명시)에는 실패하고 수정 후 통과하므로, 플랫폼 기본 charset과 무관하게 결정적으로 검증됩니다.
  • 한글 메시지를 담은 EgovServiceException 경로를 추가해 응답 본문을 UTF-8로 디코딩했을 때 한글이 보존되는지 단정.
mvn -pl Presentation/org.egovframe.rte.ptl.reactive -am test -Dtest=EgovExceptionHandlerTest -Dsurefire.failIfNoSpecifiedTests=false

테스트 2건 통과(실패 0).

영향 범위

  • reactive 모듈 에러 응답 경로에 한정되며, 정상 응답 경로는 영향이 없습니다.
  • 응답 charset이 UTF-8로 고정되므로 기존에 우연히 기본 charset이 UTF-8이던 환경에서는 동작이 그대로입니다. UTF-8이 아니던 환경에서는 한글 등 비ASCII 에러 메시지가 정상 표기됩니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant