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

[톰캣 구현하기 3, 4단계] 블랙캣(송우석) 미션 제출합니다. #477

Merged
merged 16 commits into from
Sep 12, 2023

Conversation

Songusika
Copy link

@Songusika Songusika commented Sep 11, 2023

안녕하세요 제이!

이번에 리팩터링하면서 기능적 변경사항이 몇가지 생겼습니다!

1. 각 요청 처리 시 예외 발생 시 리다이렉트가 아닌 에러 페이지에러 코드와 함께 같이 반환

아무래도 클라이언트 측면에서 한번 더 요청을 안보내도 되며, 에러 코드를 통해서 바로 알 수 있도록 하였습니다!

2. 로그인 요청 - 로그인 페이지 요청, 회원가입 요청 - 회원가입 페이지 요청 컨트롤러를 통합

미션에서 요구하는 Controller, AbstractController 구조를 적용하면서 하나의 클래스로 합쳤습니다.

3. isSupported()를 통한 논리적 null 체크를 제거.

미션 1,2 에서는 회원가입 POST 요청 시 isSupported() 메서드를 통해서 account, password 를 가진 request 만 들어오기 때문에
실제 service() 단에서 해당 body값들을 가져올 때 별도의 null 체킹을 하지 않았는데요,
이번에 리팩터링하면서 요청 url 로만 검사를 하게 하였고, 실제로 body값을 가져올 때 해당 값이 없다면 예외를 터트리는 구조로 변경하였습니다.

이번 리뷰도 감사합니다! 🙇‍♂️

Copy link

@sosow0212 sosow0212 left a comment

Choose a reason for hiding this comment

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

블랙캣 안녕하세요!
이번에도 깔끔한 코드로 개선해주셨네요 ㅎㅎ

1,2 단계 때 워낙 잘해주셔서 구조적으로는 오히려 제가 배우면서 리뷰 많이 했습니다.
이번 단계에서 패키지에 대한 고민도 하셨던 것 같습니다!

요청을 처리하면서, 예외를 발생하는 구조도 인상깊게 잘 봤습니다.
몇 가지 컨벤션이 맞지 않아서 이 부분만 수정해주세요 ㅎㅎ
수정하시고 머지하셔도 될 것 같습니다.

그리고 추가적으로 질문에 블랙캣의 생각을 듣고 싶습니다!

이번 미션도 수고 많으셨습니다 :)

private final AuthService authService = new AuthService();

@Override
protected void doGet(final HttpRequest request, final HttpResponse response) {

Choose a reason for hiding this comment

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

요구사항대로 HttpResponse에 set을 잘해주셨네요!

@Override
protected void doPost(final HttpRequest request, final HttpResponse response) {
try {
final String account = request.getBodyValueOf(ACCOUNT_QUERY_KEY);

Choose a reason for hiding this comment

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

param이 잘못 넘어오게 된다면 어떻게 될까요?

Copy link
Author

Choose a reason for hiding this comment

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

현재 아래와 같이 HttpResponse 객체에서 없는 값에 대해선 예외를 터트리고
해당 컨트롤러에서 잡은 후 400 Bad Request 를 던지고 있는 구조입니다!

public String getBodyValueOf(final String body) {
    return Optional.ofNullable(this.body.getValue(body))
            .orElseThrow(NoSuchBodyValueException::new);
}
try {
    final String account = request.getBodyValueOf(ACCOUNT_QUERY_KEY);
    final String password = request.getBodyValueOf(PASSWORD_QUERY_KEY);
    ...나머지 로직들...
} catch (NoSuchBodyValueException e) {
    setResponse(response, HttpStatus.BAD_REQUEST, "/400.html");
}

Choose a reason for hiding this comment

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

아~ 그렇군요! 그렇다면 패스하셔도 됩니다 ㅎㅎ

this.serverSocket = createServerSocket(port, acceptCount);
this.executor = Executors.newFixedThreadPool(maxThreads);

Choose a reason for hiding this comment

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

블랙캣은 newFixedThreadPool를 사용하신 이유는 무엇인가요?!

}
}

protected void doGet(HttpRequest request, HttpResponse response) {

Choose a reason for hiding this comment

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

doGet, doPost 매개변수에 final 키워드가 누락되어있습니다!


public class SessionManager {

private static final Map<String, Session> SESSIONS = new HashMap<>();
private static final Map<String, Session> SESSIONS = new ConcurrentHashMap<>();

Choose a reason for hiding this comment

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

동시성 고려까지 잘 해주셨네요 👍

@@ -0,0 +1,54 @@
<!DOCTYPE html>

Choose a reason for hiding this comment

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

400 페이지 센스 굿~~

Comment on lines 15 to 18
public static Controller getSupportedServlet(final HttpRequest request) {
return servlets.stream().filter(it -> it.isSupported(request))
.findFirst()
.orElseThrow(NotSupportedRequestException::new);

Choose a reason for hiding this comment

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

Suggested change
public static Controller getSupportedServlet(final HttpRequest request) {
return servlets.stream().filter(it -> it.isSupported(request))
.findFirst()
.orElseThrow(NotSupportedRequestException::new);
public static Controller getSupportedServlet(final HttpRequest request) {
return servlets.stream()
.filter(it -> it.isSupported(request))
.findFirst()
.orElseThrow(NotSupportedRequestException::new);

ㅎㅎ 컨벤션 다 확인해보는 건 항상 힘든 것 같아요 저도 그렇고 ㅠㅠ
블랙캣의 더 완성도 있는 코드가 되길 바라며 제안해봅니다 👍

setResponse(response, HttpStatus.OK, "/login.html");
}

private boolean AuthenticationUser(final HttpRequest request) {

Choose a reason for hiding this comment

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

메서드 명이 대문자와 명사로 시작해서 조금 어색한 것 같아요~
authenticateUser는 어떨까요?

@sonarcloud
Copy link

sonarcloud bot commented Sep 11, 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 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.20.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@sosow0212 sosow0212 merged commit b381530 into woowacourse:songusika Sep 12, 2023
2 checks passed
@Songusika Songusika deleted the step3-4 branch September 23, 2023 18:18
@Songusika Songusika restored the step3-4 branch September 23, 2023 18:18
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