-
Notifications
You must be signed in to change notification settings - Fork 309
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단계] 썬샷(오진택) 미션 제출합니다. #479
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2ceb3b4
refactor: ResponseHeader가 출력 순서를 보장하도록 수정
Ohjintaek 97b8a82
refactor: HttpResponse 구조 리팩토링
Ohjintaek 730c324
feat: 웹 요청 분기 처리를 Controller 인터페이스를 상속하도록 구현
Ohjintaek 8859566
feat: 올바른 컨트롤러 매핑
Ohjintaek c70952c
refactor: 웹 응답 포매팅 리팩터링
Ohjintaek 24e135e
feat: ThreadPool 생성
Ohjintaek 62644dd
feat: SessionManager에서 스레드 안정성을 위해 ConcurrentHashMap 사용
Ohjintaek ec51e20
teat: 캐시 학습 테스트
Ohjintaek 6114aa7
teat: 스레드 학습 테스트
Ohjintaek e5e8416
refactor: jwp와 tomcat 간 패키지 분리 리팩토링
Ohjintaek 628ccf8
refactor: Controller를 자바 Servlet과 비슷한 구조로 수정
Ohjintaek b7d7d29
feat: HTTP 헤더 enum으로 관리
Ohjintaek 0bb3470
refactor: 상수화 및 메서드 분리
Ohjintaek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 11 additions & 4 deletions
15
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,19 @@ | ||
package cache.com.example.etag; | ||
|
||
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", "/resources/*"); | ||
filterRegistrationBean.setName("etagFilter"); | ||
return filterRegistrationBean; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
study/src/main/java/cache/com/example/interceptor/NocacheInterceptor.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 cache.com.example.interceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
public class NocacheInterceptor implements HandlerInterceptor { | ||
|
||
@Override | ||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, | ||
ModelAndView modelAndView) throws Exception { | ||
response.addHeader("Cache-Control", "no-cache, private"); | ||
} | ||
} |
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
159 changes: 0 additions & 159 deletions
159
tomcat/src/main/java/nextstep/jwp/RequestProcessor.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
tomcat/src/main/java/nextstep/jwp/controller/AbstractController.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,42 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import org.apache.catalina.Controller; | ||
import org.apache.coyote.common.HttpMethod; | ||
import org.apache.coyote.request.HttpRequest; | ||
import org.apache.coyote.response.HttpResponse; | ||
|
||
abstract class AbstractController implements Controller { | ||
|
||
protected static final String DEFAULT_FILE_LOCATION = "static/"; | ||
|
||
public abstract boolean canHandle(HttpRequest request); | ||
|
||
@Override | ||
public void service(HttpRequest request, HttpResponse response) throws Exception { | ||
if (request.getHttpMethod().equals(HttpMethod.GET)) { | ||
doGet(request, response); | ||
} | ||
if (request.getHttpMethod().equals(HttpMethod.POST)) { | ||
doPost(request, response); | ||
} | ||
} | ||
|
||
protected void doPost(HttpRequest request, HttpResponse response) throws Exception { /* NOOP */ } | ||
protected void doGet(HttpRequest request, HttpResponse response) throws Exception { /* NOOP */ } | ||
|
||
protected String readResponseBody(final String requestUri) throws IOException, URISyntaxException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공통적으로 사용할 수 있게 만들기 위해서 추상 클래스에 만들어뒀군요! |
||
final URL url = getClass().getClassLoader().getResource(DEFAULT_FILE_LOCATION + requestUri); | ||
if (url == null) { | ||
URL notFoundUrl = getClass().getClassLoader().getResource(DEFAULT_FILE_LOCATION + "404.html"); | ||
final var path = Paths.get(notFoundUrl.toURI()); | ||
return Files.readString(path); | ||
} | ||
final var path = Paths.get(url.toURI()); | ||
return Files.readString(path); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tomcat/src/main/java/nextstep/jwp/controller/ErrorPageController.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,24 @@ | ||
package nextstep.jwp.controller; | ||
|
||
import org.apache.coyote.common.ContentType; | ||
import org.apache.coyote.common.HttpHeader; | ||
import org.apache.coyote.common.HttpStatus; | ||
import org.apache.coyote.request.HttpRequest; | ||
import org.apache.coyote.response.HttpResponse; | ||
import org.apache.coyote.response.StatusLine; | ||
|
||
public class ErrorPageController extends AbstractController { | ||
|
||
@Override | ||
public boolean canHandle(HttpRequest request) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpRequest request, HttpResponse response) throws Exception { | ||
response.setStatusLine(StatusLine.of(request.getHttpVersion(), HttpStatus.NOT_FOUND)); | ||
response.addHeader(HttpHeader.CONTENT_TYPE.getName(), ContentType.HTML.getType()); | ||
final String content = readResponseBody("500.html"); | ||
response.setResponseBody(content); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 추상 클래스는
HttpServlet
과 비슷한 것 같아요.명세에 가깝게 느껴져서 패키지 위치가 웹앱 쪽이 맞을 지 의문입니다!