-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[톰캣 구현하기 - 3, 4단계] 준팍(박준현) 미션 제출합니다. (#407)
* test: IOStreamTest 완료 * test: FileTest 완료 * test: FileTest path에서 getResource로 방법 변경 * docs : 요구사항 정리 * feat: GET /index.html 응답 기능 구현 * feat: css 지원 기능 구현 * refactor: 클래스 분리 * feat: QueryString 파싱 기능 구현 * refactor: FileExtension 클래스 분리 * refactor: HttpStatus 클래스 분리 * refactor: RequestHandler 클래스 분리 * refactor: RequestHandler Path 로직 수정 * feat: favicon 추가 * feat: HTTP 302 기능 구현 * refactor: 개행 문자 lineSeparator() * refactor: 클래스 분리 * feat: Post method 기능 구현 * feat: 회원 가입 후 리다이렉트 완료 * refacotr: lineSeperator() "\r\n"로 수정 * test: cache 학습테스트 완료 * test: cache 학습테스트 완료 * refactor: 피드백 반영 * refactor: QueryStrings 일급 컬렉션 구현 * feat: HttpCookie 구현 * refactor: 네이밍 변경 * chore: 패키지 분리 * feat: RequestHeaders에 HttpCookie 추가 * refactor: 메서드 분리 * refactor: HandlerMapping 상수화 * feat: 쿠키 값을 스트링으로 반환하는 메서드 구현 * refactor: 메서드 이동 * refactor: 클래스별 역할과 책임 재분배 * refactor: Handler 추가 * feat: Cookie에 JSESSIONID 값 저장 기능 구현 * feat: Session 및 SessionManager 객체 구현 * feat: Session 기능 구현 완료 * feat: User ID AutoIncrement 기능 구현 * fix: 로그인 실패시 401.html 리다이렉트 * refactor: SessionManager 싱글턴 적용 * fix: 401 리다이렉트 오류 수정 * refactor: SessionManager Enum Singleton 적용 * chore: 코드 커버리지 확인을 위한 build.yml 수정 * refactor: 네이밍 변경, 싱글턴 적용, collection 변경 * fix: GET 요청 시 Login 및 Register 기능 삭제 * refactor: 불필요 메서드 삭제 * refactor: statusCode 타입 변경 * refactor: 불필요 객체 삭제 * refactor: ResponseEntity 빌더패턴 적용 * feat: 동시성 확장하기 * test: 학습테스트 Thread 학습 테스트 완료 * feat: Connector Thread pool 적용 * chore: 코드 커버리지 체크 제거 * refactor: ResponseEntity 제거 및 Controller 인터페이스 service 메서드 void 적용, 싱글턴 제거 * feat: HttpResponseParser 객체 구현 * refactor: 코드 스멜 제거 * refactor: 피드백 반영 * refactor: 피드백 반영 * fix: 파일을 찾을 수 없을 시 NotFound 연결
- Loading branch information
1 parent
3453b3d
commit 94761d0
Showing
51 changed files
with
667 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
# 톰캣 구현하기 | ||
|
||
## 1단계 - HTTP 서버 구현하기 | ||
- [x] GET /index.html 응답하기 | ||
- [x] CSS 지원하기 | ||
- [x] Query String 파싱 | ||
## 3단계 - 리팩터링 | ||
- [x] HttpRequest 클래스 구현하기 | ||
- [x] HttpResponse 클래스 구현하기 | ||
- [x] Controller 인터페이스 추가하기 | ||
- [x] AbstractController를 상속한 구현체 만들기 | ||
|
||
## 2단계 - 로그인 구현하기 | ||
- [x] HTTP Status Code 302 | ||
- [x] 로그인 성공 시, 응답 헤더에 http status code를 302로 반환하고 `/index.html`로 리다이렉트 | ||
- [x] 로그인 실패 시, `401.html`로 리다이렉트 | ||
- [x] POST 방식으로 회원가입 | ||
- [x] `http://localhost:8080/register` 으로 접속하면 회원가입 페이지(`register.html`)를 보여준다. | ||
- [x] 회원가입 페이지를 보여줄 때는 GET을 사용한다. | ||
- [x] 회원가입을 버튼을 누르면 HTTP method를 GET이 아닌 POST를 사용한다. | ||
- [x] 회원가입을 완료하면 `index.html`로 리다이렉트한다. | ||
- [x] 로그인 페이지도 버튼을 눌렀을 때 GET 방식에서 POST 방식으로 전송하도록 변경하자. | ||
- [x] Cookie에 JSESSIONID 값 저장하기 | ||
- [x] 서버에서 HTTP 응답을 전달할 때 응답 헤더에 `Set-Cookie`를 추가하고 `JSESSIONID=656cef62-e3c4-40bc-a8df-94732920ed46` 형태로 값을 전달하면 | ||
클라이언트 요청 헤더의 `Cookie` 필드에 값이 추가된다. | ||
- [x] Cookie 클래스를 추가하고 HTTP Request Header의 Cookie에 `JSESSIONID`가 없으면 HTTP Response Header에 `Set-Cookie`를 반환해주는 기능을 | ||
구현한다. | ||
- [x] Session 구현하기 | ||
- [x] 쿠키에서 전달 받은 JSESSIONID의 값으로 로그인 여부를 체크할 수 있어야 한다. | ||
- [x] 로그인에 성공하면 Session 객체의 값으로 User 객체를 저장해보자. | ||
- [x] 로그인 상태에서 `/login` 페이지에 HTTP GET method로 접근하면 `index.html` 페이지로 리다이렉트 처리한다 | ||
## 4단계 - 동시성 확장하기 | ||
- [x] Executors로 Thread Pool 적용하기 | ||
- [x] Connector 클래스에서 Executors 클래스를 사용해서 ExecutorService 객체 생성하기 | ||
- [x] maxThreads라는 변수로 스레드 갯수 지정하기 | ||
- [x] 동시성 컬렉션 사용하기 | ||
- [x] SessionManager 클래스에서 Session 컬렉션에 동시성 컬렉션 적용하기 |
10 changes: 10 additions & 0 deletions
10
study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.mvc.WebContentInterceptor; | ||
|
||
@Configuration | ||
public class CacheWebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addInterceptors(final InterceptorRegistry registry) { | ||
CacheControl cacheControl = CacheControl | ||
.noCache() | ||
.cachePrivate(); | ||
|
||
WebContentInterceptor webContentInterceptor = new WebContentInterceptor(); | ||
webContentInterceptor.addCacheMapping(cacheControl, "/"); | ||
|
||
registry.addInterceptor(webContentInterceptor); | ||
} | ||
} |
19 changes: 15 additions & 4 deletions
19
study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package cache.com.example.etag; | ||
|
||
import cache.com.example.version.CacheBustingWebConfig; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
|
||
@Configuration | ||
public class EtagFilterConfiguration { | ||
|
||
// @Bean | ||
// public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
// return null; | ||
// } | ||
@Bean | ||
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<>( | ||
new ShallowEtagHeaderFilter()); | ||
filterRegistrationBean.addUrlPatterns( | ||
"/etag", | ||
CacheBustingWebConfig.PREFIX_STATIC_RESOURCES + "/*" | ||
); | ||
|
||
return filterRegistrationBean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tomcat/src/main/java/nextstep/jwp/controller/DefaultController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import org.apache.coyote.http11.common.HttpStatus; | ||
import org.apache.coyote.http11.controller.Controller; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class DefaultController implements Controller { | ||
|
||
@Override | ||
public void service(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.setHttpStatus(HttpStatus.OK) | ||
.setPath("/default"); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
tomcat/src/main/java/nextstep/jwp/controller/LoginController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import nextstep.jwp.model.User; | ||
import nextstep.jwp.service.UserService; | ||
import org.apache.coyote.http11.common.HttpCookie; | ||
import org.apache.coyote.http11.common.HttpStatus; | ||
import org.apache.coyote.http11.controller.AbstractController; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.request.RequestBody; | ||
import org.apache.coyote.http11.request.RequestLine; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
import org.apache.coyote.http11.session.HttpSession; | ||
|
||
public class LoginController extends AbstractController<UserService> { | ||
|
||
public LoginController(UserService userService) { | ||
super(userService); | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
RequestLine requestLine = httpRequest.getRequestLine(); | ||
HttpSession session = httpRequest.getSession(false); | ||
|
||
if (session != null && session.getAttribute("user") != null) { | ||
httpResponse.setHttpStatus(HttpStatus.FOUND) | ||
.setPath("/index"); | ||
return; | ||
} | ||
|
||
httpResponse.setHttpStatus(HttpStatus.OK) | ||
.setPath(requestLine.getPath()); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
RequestBody requestBody = httpRequest.getRequestBody(); | ||
|
||
String account = requestBody.get("account"); | ||
String password = requestBody.get("password"); | ||
|
||
try { | ||
User user = service.login(account, password); | ||
|
||
HttpSession httpSession = httpRequest.getSession(true); | ||
httpSession.setAttribute("user", user); | ||
|
||
httpRequest.addSession(httpSession); | ||
|
||
HttpCookie httpCookie = HttpCookie.create(); | ||
httpCookie.putJSessionId(httpSession.getId()); | ||
|
||
httpResponse.setHttpStatus(HttpStatus.FOUND) | ||
.setPath("/index") | ||
.setCookie(httpCookie); | ||
} catch (IllegalArgumentException e) { | ||
httpResponse.setHttpStatus(HttpStatus.FOUND) | ||
.setPath("/401"); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
tomcat/src/main/java/nextstep/jwp/controller/NotFoundController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import org.apache.coyote.http11.common.HttpStatus; | ||
import org.apache.coyote.http11.controller.Controller; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class NotFoundController implements Controller { | ||
|
||
@Override | ||
public void service(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.setHttpStatus(HttpStatus.NOT_FOUND) | ||
.setPath("/404"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tomcat/src/main/java/nextstep/jwp/controller/RegisterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import nextstep.jwp.service.UserService; | ||
import org.apache.coyote.http11.common.HttpStatus; | ||
import org.apache.coyote.http11.controller.AbstractController; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.request.RequestBody; | ||
import org.apache.coyote.http11.request.RequestLine; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class RegisterController extends AbstractController<UserService> { | ||
|
||
public RegisterController(UserService userService) { | ||
super(userService); | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
RequestLine requestLine = httpRequest.getRequestLine(); | ||
|
||
httpResponse.setHttpStatus(HttpStatus.OK) | ||
.setPath(requestLine.getPath()); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
RequestBody requestBody = httpRequest.getRequestBody(); | ||
|
||
String account = requestBody.get("account"); | ||
String password = requestBody.get("password"); | ||
String email = requestBody.get("email"); | ||
|
||
service.save(account, password, email); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tomcat/src/main/java/nextstep/jwp/controller/UnauthorizedController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import org.apache.coyote.http11.common.HttpStatus; | ||
import org.apache.coyote.http11.controller.Controller; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public class UnauthorizedController implements Controller { | ||
|
||
@Override | ||
public void service(HttpRequest httpRequest, HttpResponse httpResponse) { | ||
httpResponse.setHttpStatus(HttpStatus.UNAUTHORIZED) | ||
.setPath("/401"); | ||
} | ||
|
||
} |
26 changes: 0 additions & 26 deletions
26
tomcat/src/main/java/nextstep/jwp/controller/UserController.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.