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

[MVC 구현하기 - 3단계] 엔초(권예진) 미션 제출합니다. #575

Merged
merged 11 commits into from
Sep 26, 2023

Conversation

kwonyj1022
Copy link

@kwonyj1022 kwonyj1022 commented Sep 24, 2023

안녕하세요 아코! 2단계 때 정성스러운 리뷰 정말 감사합니다.
질문 남겨주신 부분에 대해 답변 남겨놨습니다~ 2단계 pr

총 8개의 커밋 중 앞의 4개(범위)는 2단계에서 리뷰해 주신 내용 적용한 것과 간단한 리팩토링(HandlerExecutor 추가 및 DispatcherServletInitializer에서 핸들러 매핑과 핸들러 어댑터를 추가하도록 변경)에 해당하는 부분이고,

뒤에 있는 4개의 커밋(범위)이 3단계 구현에 해당합니다.

이번 리뷰도 잘 부탁드립니다!

@kwonyj1022 kwonyj1022 self-assigned this Sep 24, 2023
Copy link

@seokhwan-an seokhwan-an left a comment

Choose a reason for hiding this comment

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

안녕하세요 엔초!
3단계 엄청 빠르게 구현해주셨네요! 👍
코드가 전반적으로 간결하고 큰 흐름이 잘 읽혀서 리뷰하기 수월했습니다!👍
간단하게 의견을 물어보는 것과 수정할 부분에 대해서 리뷰남겼는데 확인바랍니다!

Comment on lines 27 to 37
public void init() {
handlerMappingRegistry.addHandlerMapping(new ManualHandlerMapping());
handlerMappingRegistry.addHandlerMapping(new AnnotationHandlerMapping(Application.class.getPackageName() + ".*"));
handlerAdapterRegistry.addHandlerAdapter(new ControllerHandlerAdapter());
handlerAdapterRegistry.addHandlerAdapter(new HandlerExecutionHandlerAdapter());
handlerExecutor = new HandlerExecutor(handlerAdapterRegistry);
}

public void addHandlerMapping(final HandlerMapping handlerMapping) {
handlerMappingRegistry.addHandlerMapping(handlerMapping);
}

public void addHandlerAdapter(final HandlerAdapter handlerAdapter) {
handlerAdapterRegistry.addHandlerAdapter(handlerAdapter);
}

Choose a reason for hiding this comment

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

현재 이 부분을 보면 HandlerExecutor의 경우 DispatcherServlet init()메소드에서 초기화가 되는데
HandlerMappingHandlerAdapter의 경우에는 DispatcherServletInitializer에서 값을 추가하는 방식으로 구현을 해주셨어요. 이 부분을 분리해서 값을 추가해주신 이유가 있을까요?
혹시 AnnotationHandler의 basePackage 설정을 위함일까요?
엔초의 생각흐름이 궁금합니다!☺️

Copy link
Author

Choose a reason for hiding this comment

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

addHandlerMappingaddHandlerAdapterDispatcherServletInitializeronStartUp()에서 직접 호출하고 있고, DispatcherServletinit()onStartUp()이 끝난 후에 호출이 되고 있습니다.

HandlerExecutorHandlerAdapterRegistry를 사용하기 때문에 HandlerAdapterRegistry에 대한 설정이 끝난 이후에 사용되어야 한다고 생각했습니다. init() 메서드가 HandlerAdapterRegistry를 설정해주는 onStartUp()이 끝난 후에 호출되기 때문에 이렇게 분리하면 더 명확하다고 생각했습니다.

Choose a reason for hiding this comment

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

넵 이해 완료했습니다! 자세하게 답변해주셔서 감사합니다!

Comment on lines 44 to 56
final Optional<Object> nullableHandler = handlerMappingRegistry.getHandler(request);

if (nullableHandler.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
render(new ModelAndView(new JspView("404.jsp")), request, response);
return;
}

final Object handler = nullableHandler.get();
try {
final HandlerAdapter handlerAdapter = handlerAdapterRegistry.getHandlerAdapter(handler);
final ModelAndView modelAndView = handlerAdapter.handle(request, response, handler);
final ModelAndView modelAndView = handlerExecutor.handle(request, response, handler);
render(modelAndView, request, response);
} catch (Exception e) {
throw new RuntimeException(e);

Choose a reason for hiding this comment

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

이번에 HandlerExecutor를 이번에 도입해주셨는데 HandlerExecutor 내부에 HanderMappingResitry를 가지고 있고 handler를 찾아와서 실행시켜주는 것 같습니다. 하지만 현재 코드를 보면 404.jsp를 나타낼 때에는 handlerMappingResitry에서 직접꺼내와서 작업을 진행하는 것도 작업이 있는데 이 부분도 HandlerExecutor 내부에서 처리하는 방식으로 수정하면 좋을 것 같습니다!☺️

Copy link
Author

Choose a reason for hiding this comment

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

handleNotFound 메서드를 추가해서 404 ModelAndView를 반환하도록 수정했습니다!

Choose a reason for hiding this comment

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

확인했습니다!

Comment on lines 21 to 23
final String body = objectMapper.writeValueAsString(model);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.getWriter().write(body);

Choose a reason for hiding this comment

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

model에 데이터가 1개면 값을 그대로 반환하고 2개 이상이면 Map 형태 그대로 JSON으로 변환해서 반환한다.
힌트에 위와 같이 요구조건이 있는데 그 부분이 지켜지지 않은 것 같습니다. 물론 결과는 지금과 같게 나오기는 합니다!
그래도 수정 한번 부탁드립니다!☺️

Copy link
Author

Choose a reason for hiding this comment

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

아 맞다.. 나중에 하기로 하고 까먹었네요ㅠ

final String requestURI = request.getRequestURI();
log.debug("Method : {}, Request URI : {}", request.getMethod(), requestURI);

final Optional<Object> nullableHandler = handlerMappingRegistry.getHandler(request);

if (nullableHandler.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
render(new ModelAndView(new JspView("404.jsp")), request, response);

Choose a reason for hiding this comment

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

👍👍

Copy link

@seokhwan-an seokhwan-an left a comment

Choose a reason for hiding this comment

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

안녕하세요 엔초!
리뷰도 빠르게 반영해주셨군요!👍👍

이번 리뷰를 진행하면서 엔초의 생각을 들어볼 수 있는 시간이 되어서 저도 많이 배울 수 있었습니다!
더이상 고칠 부분이 없다고 생각이 들어서 approve 드립니다!
이번 미션도 고생하셨습니다.
다음 미션도 화이팅입니다!

@seokhwan-an seokhwan-an merged commit a6efd67 into woowacourse:kwonyj1022 Sep 26, 2023
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.

2 participants