Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : x-forward 필터로 인한 ContentCachingRequestWrapper 캐스팅 오류 해결 #267

Merged
merged 5 commits into from
Feb 2, 2023

Conversation

ImNM
Copy link
Member

@ImNM ImNM commented Feb 1, 2023

개요

작업사항

  • 500 번대 오류시 슬랙 알림이 서버에서 안오더라고요?
  • 보니깐 proxy 로 nginx 달려있으니 x-Forward 헤더 가 넘어오는데
  • 이때 ForwardedHeaderFilter가 동작해 버리더라고요
  • 위 필터가 거의 뒤에서 2번째로 동작해서 ( ContentCachingRequestWrapper는 마지막에서 세번째 )
  • ForwardedHeaderExtractingRequest로 래핑되어서 넘어오니
  • ContentCachingRequestWrapper 로 캐싱 못하는 상황이 발생해서
  • ContentCachingRequestWrapper 로 request 정보가져옴
  • 알다시피 body한번까면 더이상 못까기때문에 로깅할려면 이렇게 캐싱해서 써야함
    @ExceptionHandler(Exception.class)
    protected ResponseEntity<ErrorResponse> handleException(Exception e, HttpServletRequest request)
            throws IOException {
        final ContentCachingRequestWrapper cachingRequest = (ContentCachingRequestWrapper) request; // 캐스팅 오류
// ForwardedHeaderExtractingRequest 타입이 request 로 넘어와서 발생
//ForwardedHeaderFilter
HttpServletRequest wrappedRequest = new ForwardedHeaderExtractingRequest(request);

변경로직

  • 내용을 적어주세요.

@ImNM ImNM added the Type: Errors/Bugs [이슈 목적] 버그, 애러 수정 label Feb 1, 2023
@ImNM ImNM self-assigned this Feb 1, 2023
Copy link
Member

@gengminy gengminy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필터 체인 순서 변경 확인입니다 👍

@ImNM ImNM merged commit 8274a5a into dev Feb 2, 2023
@ImNM ImNM deleted the fix/266-servlet-filter-order branch February 2, 2023 04:06
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 279 Code Smells

15.8% 15.8% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Errors/Bugs [이슈 목적] 버그, 애러 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛[BUG] 필터 순서로인한 ContentCachingRequestWrapper 캐스팅 오류 ( 500번대 오류시 )
3 participants