-
Notifications
You must be signed in to change notification settings - Fork 310
[1단계 - Tomcat 구현하기] 낙낙(이낙헌) 미션 제출합니다. #561
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fed02f6
fix: remove implementation logback-classic on gradle (#501)
geoje 7e91356
fix: add threads min-spare configuration on properties (#502)
geoje a8707e9
feat: Http 요청/응답 객체 구현
nak-honest 5063922
feat: Http 요청을 read하고 응답을 wirte 하는 기능 구현
nak-honest dcb726e
feat: Http 요청으로부터 응답을 내는 기능 구현
nak-honest cb8d8e4
feat: 로그인을 하면 유저 정보를 찾는 기능 구현
nak-honest 9275770
feat: 클라이언트로부터 HTTP 요청을 받아 응답을 하는 기능 구현
nak-honest 1877ccd
refactor: 각 클라이언트의 요청을 처리하는 스레드를 데몬 스레드로 변경
nak-honest 94a6f54
feat: 학습 테스트 1 구현
nak-honest c9dd251
feat: 학습 테스트 2 구현
nak-honest b9a6d5a
merge 충돌 해결
nak-honest 013d6a6
refactor: query parameter 들을 일급 컬렉션으로 래핑
nak-honest 4cfcf08
refactor: static class 의 생성자 접근제어자를 private 으로 변경
nak-honest 064a916
style: 코드 스타일 통일성이 맞도록 수정
nak-honest 18211e1
refactor: 변수명 변경
nak-honest 160869d
refactor: 지역 변수로 받지 않고 바로 return하도록 변경
nak-honest cdec028
fix: 학습 테스트 2 4번에서 ETag 가 포함되지 않는 문제 해결
nak-honest e37693b
fix: 브라우저에서 versoning이 적용되도록 수정
nak-honest 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 hidden or 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
study/src/main/java/cache/com/example/cachecontrol/CacheWebConfig.java
This file contains hidden or 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,34 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import cache.com.example.version.ResourceVersion; | ||
import java.time.Duration; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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 { | ||
|
||
private final ResourceVersion version; | ||
|
||
@Autowired | ||
public CacheWebConfig(ResourceVersion version) { | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public void addInterceptors(final InterceptorRegistry registry) { | ||
WebContentInterceptor noCacheInterceptor = new WebContentInterceptor(); | ||
noCacheInterceptor.addCacheMapping(CacheControl.noCache().cachePrivate(), "/**"); | ||
registry.addInterceptor(noCacheInterceptor); | ||
|
||
WebContentInterceptor cacheInterceptor = new WebContentInterceptor(); | ||
cacheInterceptor.addCacheMapping(CacheControl.maxAge(Duration.ofDays(365L)), "/etag"); | ||
cacheInterceptor.addCacheMapping(CacheControl.maxAge(Duration.ofDays(365L)).cachePublic(), | ||
"/resources/" + version.getVersion() + "/**"); | ||
registry.addInterceptor(cacheInterceptor); | ||
} | ||
} |
25 changes: 21 additions & 4 deletions
25
study/src/main/java/cache/com/example/etag/EtagFilterConfiguration.java
This file contains hidden or 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,29 @@ | ||
package cache.com.example.etag; | ||
|
||
import cache.com.example.version.ResourceVersion; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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; | ||
// } | ||
private final ResourceVersion version; | ||
|
||
@Autowired | ||
public EtagFilterConfiguration(ResourceVersion version) { | ||
this.version = version; | ||
} | ||
|
||
|
||
@Bean | ||
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
FilterRegistrationBean<ShallowEtagHeaderFilter> registrationBean = new FilterRegistrationBean<>(); | ||
registrationBean.setFilter(new ShallowEtagHeaderFilter()); | ||
registrationBean.addUrlPatterns("/etag"); | ||
registrationBean.addUrlPatterns("/resources/" + version.getVersion() + "/*"); | ||
return registrationBean; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
study/src/main/java/cache/com/example/version/HandlebarsConfig.java
This file contains hidden or 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,26 @@ | ||
package cache.com.example.version; | ||
|
||
import com.github.jknack.handlebars.springmvc.HandlebarsViewResolver; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.ViewResolver; | ||
|
||
@Configuration | ||
public class HandlebarsConfig { | ||
|
||
private final VersionHandlebarsHelper versionHandlebarsHelper; | ||
|
||
public HandlebarsConfig(VersionHandlebarsHelper versionHandlebarsHelper) { | ||
this.versionHandlebarsHelper = versionHandlebarsHelper; | ||
} | ||
|
||
@Bean | ||
public ViewResolver handlebarsViewResolver() { | ||
HandlebarsViewResolver viewResolver = new HandlebarsViewResolver(); | ||
viewResolver.registerHelper("staticUrls", versionHandlebarsHelper); | ||
viewResolver.setPrefix("classpath:/templates/"); | ||
viewResolver.setSuffix(".html"); | ||
|
||
return viewResolver; | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
study/src/main/java/cache/com/example/version/ResourceVersion.java
This file contains hidden or 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 hidden or 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,14 @@ | ||
package cache.com.example.version; | ||
|
||
import com.github.jknack.handlebars.Helper; | ||
import com.github.jknack.handlebars.Options; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import pl.allegro.tech.boot.autoconfigure.handlebars.HandlebarsHelper; | ||
import org.springframework.stereotype.Component; | ||
|
||
@HandlebarsHelper | ||
public class VersionHandlebarsHelper { | ||
@Component | ||
public class VersionHandlebarsHelper implements Helper<Object> { | ||
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. 기존 Handlebars가 작동하지 않아, 어떻게 해결해야하는지 궁금했는데 배워갑니다ㅎㅎ 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. 해당 부분은 #520 에서 참고했습니다!! |
||
|
||
private static final Logger log = LoggerFactory.getLogger(VersionHandlebarsHelper.class); | ||
|
||
|
@@ -22,4 +23,9 @@ public String staticUrls(String path, Options options) { | |
log.debug("static url : {}", path); | ||
return String.format("/resources/%s%s", version.getVersion(), path); | ||
} | ||
|
||
@Override | ||
public Object apply(Object context, Options options) { | ||
return staticUrls(context.toString(), options); | ||
} | ||
} |
This file contains hidden or 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,9 +1,10 @@ | ||
handlebars: | ||
suffix: .html | ||
|
||
server: | ||
tomcat: | ||
accept-count: 1 | ||
max-connections: 1 | ||
threads: | ||
min-spare: 2 | ||
max: 2 | ||
compression: | ||
enabled: true | ||
min-response-size: 10 |
This file contains hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
tomcat/src/main/java/com/techcourse/controller/LoginController.java
This file contains hidden or 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,38 @@ | ||
package com.techcourse.controller; | ||
|
||
import com.techcourse.model.User; | ||
import com.techcourse.service.UserService; | ||
import java.io.IOException; | ||
import org.apache.coyote.http11.handler.HttpHandler; | ||
import org.apache.coyote.http11.handler.ViewHttpHandler; | ||
import org.apache.coyote.http11.message.request.HttpRequest; | ||
import org.apache.coyote.http11.message.request.QueryParameters; | ||
import org.apache.coyote.http11.message.response.HttpResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LoginController implements HttpHandler { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoginController.class); | ||
|
||
private final UserService service; | ||
private final ViewHttpHandler viewHttpHandler; | ||
|
||
public LoginController(UserService service) { | ||
this.service = service; | ||
this.viewHttpHandler = new ViewHttpHandler("login"); | ||
} | ||
|
||
@Override | ||
public HttpResponse handle(HttpRequest request) throws IOException { | ||
QueryParameters queryParameters = request.getQueryParameters(); | ||
|
||
String account = queryParameters.getSingleValueByKey("account"); | ||
String password = queryParameters.getSingleValueByKey("password"); | ||
|
||
User user = service.findUserByAccountAndPassword(account, password); | ||
log.info("user: {}", user); | ||
|
||
return viewHttpHandler.handle(request); | ||
} | ||
} |
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.
미리 구현된 인터셉터를 활용하셨군요👍🏿