-
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단계] 우르(김현우) 미션 제출합니다. (#481)
* feat : 학습 테스트 * feat : Cookie 클래스 생성 * feat : Session 클래스 생성 * feat : HTTP 요청을 파싱하는 유틸리티 클래스 생성 * feat : HttpRequestLine 클래스 추가 * feat : RequestBody 클래스 추가 * feat : QueryString 클래스 추가 * refactor : queryString, body, cookie, httpRequestLine 추가 * feat : 회원 가입 및 로그인 기능 추가 * refactor : path -> uri 로 변수 변경 * feat : handler 추가 * refactor : handle 반환값 void 로 변경 * refactor : handler composite 반환값 변경 * feat : Http 응답 관련 header, body, status line 객체 추가 * feat : Handler 반환값을 void로 변경하여 response에 값을 넣도록 수정 * feat : HttpRequest, HttpResponse 공통적으로 Cookie 사용하도록 수정 * feat : 매 요청마다 세션이 있으면 세션 매니저에 넣어주고, 없으면 생성하여 넣어주기 * feat : 로그인 관련 로직 수정 * refactor : 세션 추가할 때 기존 세션이 가지고 있는 id로 저장 * refactor : LoginPageHandler는 정적 Handler 로 수정 * refactor : Http11Processor의 HandlerComposite 타입을 Handler 인터페이스로 수정 * refactor : 동시성 보장을 위한 ConcurrentHashMap 사용 * refactor : max thread 설정 * test : 테스트를 위한 getter 추가 * feat : 학습 테스트 * refactor : 공백 추가 * refactor : 코드 스멜 제거 * refactor : redirect URL 상대 경로로 설정 * refactor : HttpResponse에 redirect 행위 캡술화 * refactor : 핸들러가 존재하지 않을 때 exception 추가
- Loading branch information
1 parent
f8050ff
commit 92f744a
Showing
39 changed files
with
1,092 additions
and
285 deletions.
There are no files selected for viewing
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); | ||
} | ||
} |
25 changes: 21 additions & 4 deletions
25
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,29 @@ | ||
package cache.com.example.etag; | ||
|
||
import static cache.com.example.version.CacheBustingWebConfig.PREFIX_STATIC_RESOURCES; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.servlet.Filter; | ||
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> bean = new FilterRegistrationBean<>(); | ||
final ShallowEtagHeaderFilter filter = new ShallowEtagHeaderFilter(); | ||
bean.setFilter(filter); | ||
bean.setUrlPatterns(List.of( | ||
"/etag", | ||
PREFIX_STATIC_RESOURCES + "/*" | ||
)); | ||
|
||
return bean; | ||
} | ||
} |
30 changes: 19 additions & 11 deletions
30
study/src/main/java/cache/com/example/version/CacheBustingWebConfig.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,25 +1,33 @@ | ||
package cache.com.example.version; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
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.http.CacheControl; | ||
import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CacheBustingWebConfig implements WebMvcConfigurer { | ||
|
||
public static final String PREFIX_STATIC_RESOURCES = "/resources"; | ||
public static final String PREFIX_STATIC_RESOURCES = "/resources"; | ||
|
||
private final ResourceVersion version; | ||
private final ResourceVersion version; | ||
|
||
@Autowired | ||
public CacheBustingWebConfig(ResourceVersion version) { | ||
this.version = version; | ||
} | ||
@Autowired | ||
public CacheBustingWebConfig(ResourceVersion version) { | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public void addResourceHandlers(final ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler(PREFIX_STATIC_RESOURCES + "/" + version.getVersion() + "/**") | ||
.addResourceLocations("classpath:/static/"); | ||
} | ||
@Override | ||
public void addResourceHandlers(final ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler(PREFIX_STATIC_RESOURCES + "/" + version.getVersion() + "/**") | ||
.addResourceLocations("classpath:/static/") | ||
.setUseLastModified(true) | ||
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)).cachePublic()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,66 +1,62 @@ | ||
package thread.stage0; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* 스레드 풀은 무엇이고 어떻게 동작할까? | ||
* 테스트를 통과시키고 왜 해당 결과가 나왔는지 생각해보자. | ||
* | ||
* Thread Pools | ||
* https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html | ||
* | ||
* Introduction to Thread Pools in Java | ||
* https://www.baeldung.com/thread-pool-java-and-guava | ||
* 스레드 풀은 무엇이고 어떻게 동작할까? 테스트를 통과시키고 왜 해당 결과가 나왔는지 생각해보자. | ||
* <p> | ||
* Thread Pools https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html | ||
* <p> | ||
* Introduction to Thread Pools in Java https://www.baeldung.com/thread-pool-java-and-guava | ||
*/ | ||
class ThreadPoolsTest { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ThreadPoolsTest.class); | ||
|
||
@Test | ||
void testNewFixedThreadPool() { | ||
final var executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(2); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
|
||
// 올바른 값으로 바꿔서 테스트를 통과시키자. | ||
final int expectedPoolSize = 0; | ||
final int expectedQueueSize = 0; | ||
|
||
assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize()); | ||
assertThat(expectedQueueSize).isEqualTo(executor.getQueue().size()); | ||
} | ||
|
||
@Test | ||
void testNewCachedThreadPool() { | ||
final var executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
|
||
// 올바른 값으로 바꿔서 테스트를 통과시키자. | ||
final int expectedPoolSize = 0; | ||
final int expectedQueueSize = 0; | ||
|
||
assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize()); | ||
assertThat(expectedQueueSize).isEqualTo(executor.getQueue().size()); | ||
} | ||
|
||
private Runnable logWithSleep(final String message) { | ||
return () -> { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
log.info(message); | ||
}; | ||
} | ||
private static final Logger log = LoggerFactory.getLogger(ThreadPoolsTest.class); | ||
|
||
@Test | ||
void testNewFixedThreadPool() { | ||
final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(2); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
executor.submit(logWithSleep("hello fixed thread pools")); | ||
|
||
// 올바른 값으로 바꿔서 테스트를 통과시키자. | ||
final int expectedPoolSize = 2; | ||
final int expectedQueueSize = 1; | ||
|
||
assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize()); | ||
assertThat(expectedQueueSize).isEqualTo(executor.getQueue().size()); | ||
} | ||
|
||
@Test | ||
void testNewCachedThreadPool() { | ||
final var executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
executor.submit(logWithSleep("hello cached thread pools")); | ||
|
||
// 올바른 값으로 바꿔서 테스트를 통과시키자. | ||
final int expectedPoolSize = 3; | ||
final int expectedQueueSize = 0; | ||
|
||
assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize()); | ||
assertThat(expectedQueueSize).isEqualTo(executor.getQueue().size()); | ||
} | ||
|
||
private Runnable logWithSleep(final String message) { | ||
return () -> { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
log.info(message); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.