-
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.
[톰캣 구현하기 - 2, 3, 4단계] 밀리(김미성) 미션 제출합니다. (#464)
* feat: cookie, session 구현 * refactor: Http Request 파싱 로직 리팩토링 * refactor: Controller 인터페이스 리팩토링 * refactor: HttpResponseGenerator로 응답 메세지 생성하도록 수정 * refactor: FrontController 도입하여 양방향 의존성 제거 * test: cache 학습 테스트 작성 * test: thread 학습 테스트 작성 * feat: Executors로 Thread Pool 적용 * feat: 동시성 컬렉션으로 변경 * refactor: RequestBody 파싱 타입 변경 * docs: 기능 요구사항 작성 * refactor: content-length 헤더 세팅 컨트롤러에서 하도록 수정 * refactor: 코드 가독성 개선 * refactor: static resource 요청을 처리하는 StaticController 구현 * refactor: 세션 책임 분리 * refactor: FrontController를 RequestMapping으로 변경
- Loading branch information
Showing
36 changed files
with
557 additions
and
269 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
5 changes: 5 additions & 0 deletions
5
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,18 @@ | ||
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) { | ||
final WebContentInterceptor interceptor = new WebContentInterceptor(); | ||
interceptor.addCacheMapping(CacheControl.noCache().cachePrivate(), "/*"); | ||
registry.addInterceptor(interceptor); | ||
} | ||
} |
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 static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; | ||
|
||
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() { | ||
final FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<>( | ||
new ShallowEtagHeaderFilter()); | ||
filterRegistrationBean.addUrlPatterns( | ||
"/etag", | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ server: | |
max-connections: 1 | ||
threads: | ||
max: 2 | ||
compression: | ||
enabled: true | ||
min-response-size: 10 |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 +1,15 @@ | ||
package nextstep; | ||
|
||
import nextstep.jwp.JwpRequestMapping; | ||
import org.apache.catalina.startup.Tomcat; | ||
import org.apache.coyote.handler.RequestMapping; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
final var tomcat = new Tomcat(); | ||
private static final RequestMapping requestMapping = new JwpRequestMapping(); | ||
|
||
public static void main(final String[] args) { | ||
final var tomcat = new Tomcat(requestMapping); | ||
tomcat.start(); | ||
} | ||
} |
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,37 @@ | ||
package nextstep.jwp; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import nextstep.jwp.controller.IndexController; | ||
import nextstep.jwp.controller.LoginController; | ||
import nextstep.jwp.controller.RegisterController; | ||
import nextstep.jwp.controller.StaticController; | ||
import org.apache.coyote.handler.Controller; | ||
import org.apache.coyote.handler.RequestMapping; | ||
|
||
public class JwpRequestMapping implements RequestMapping { | ||
|
||
private static final String STATIC_RESOURCE_KEY = "static"; | ||
private static final String EXTENSION_DELIMITER = "."; | ||
|
||
private final Map<String, Controller> handlerMapping = new HashMap<>(); | ||
|
||
public JwpRequestMapping() { | ||
handlerMapping.put(STATIC_RESOURCE_KEY, new StaticController()); | ||
handlerMapping.put("/", new IndexController()); | ||
handlerMapping.put("/login", new LoginController()); | ||
handlerMapping.put("/register", new RegisterController()); | ||
} | ||
|
||
@Override | ||
public Controller getHandler(final String requestUri) { | ||
if (isFileRequest(requestUri)) { | ||
return handlerMapping.get(STATIC_RESOURCE_KEY); | ||
} | ||
return handlerMapping.get(requestUri); | ||
} | ||
|
||
private boolean isFileRequest(final String requestUri) { | ||
return requestUri.contains(EXTENSION_DELIMITER); | ||
} | ||
} |
13 changes: 8 additions & 5 deletions
13
tomcat/src/main/java/nextstep/jwp/controller/IndexController.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,15 +1,18 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import handler.Controller; | ||
import org.apache.coyote.handler.AbstractController; | ||
import org.apache.coyote.http11.HttpRequest; | ||
import org.apache.coyote.http11.HttpResponse; | ||
import org.apache.coyote.http11.HttpStatusCode; | ||
import org.apache.coyote.http11.ViewResolver; | ||
|
||
public class IndexController implements Controller { | ||
public class IndexController extends AbstractController { | ||
|
||
@Override | ||
public String run(final HttpRequest httpRequest, final HttpResponse httpResponse) { | ||
httpResponse.setStatusCode(HttpStatusCode.OK); | ||
return "/index.html"; | ||
public void doGet(final HttpRequest request, final HttpResponse response) { | ||
final String responseBody = ViewResolver.read("/index.html"); | ||
response.setResponseBody(responseBody); | ||
response.setContentLength(); | ||
response.setStatusCode(HttpStatusCode.OK); | ||
} | ||
} |
Oops, something went wrong.