-
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단계] 헙크(정현승) 미션 제출합니다. (#421)
* refactor: 클래스 네이밍 수정 * refactor: Controller 구조 도입 * feat: Thread 학습테스트 작성 * feat: 동시성 확장 * test: IndexControllerTest 테스트 케이스 작성 * test: LoginControllerTest 테스트 케이스 작성 * test: RegisterControllerTest 테스트 케이스 작성 * test: UnAuthorizedControllerTest 테스트 케이스 작성 * test: RootControllerTest 테스트 케이스 작성 * refactor: byte로 값을 가져오록 수정 * refactor: 피드백 반영 * refactor: Controller 인터페이스 수정 * refactor: Controller의 canHandle 제거 및 RequestMapping 리팩터링 * refactor: RequestBody 정팩메 반환 타입 수정 및 기본 자원 반환 로직 수정 * fix: 테스트 케이스 수정
- Loading branch information
1 parent
aea21d0
commit a666458
Showing
37 changed files
with
996 additions
and
247 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
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
114 changes: 0 additions & 114 deletions
114
tomcat/src/main/java/org/apache/coyote/http11/Handler.java
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
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
public enum HttpMethod { | ||
GET, | ||
POST | ||
POST, | ||
DELETE, | ||
} |
35 changes: 35 additions & 0 deletions
35
tomcat/src/main/java/org/apache/coyote/http11/RequestMapping.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 org.apache.coyote.http11; | ||
|
||
import org.apache.coyote.http11.controller.Controller; | ||
import org.apache.coyote.http11.controller.DefaultController; | ||
import org.apache.coyote.http11.controller.IndexController; | ||
import org.apache.coyote.http11.controller.LoginController; | ||
import org.apache.coyote.http11.controller.RegisterController; | ||
import org.apache.coyote.http11.controller.RootController; | ||
import org.apache.coyote.http11.controller.UnAuthorizedController; | ||
import org.apache.coyote.http11.controller.Uri; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
|
||
public class RequestMapping { | ||
private final Map<Uri, Controller> controllerMap; | ||
|
||
public RequestMapping() { | ||
this.controllerMap = new EnumMap<>(Uri.class); | ||
controllerMap.put(Uri.ROOT, new RootController()); | ||
controllerMap.put(Uri.INDEX, new IndexController()); | ||
controllerMap.put(Uri.LOGIN, new LoginController()); | ||
controllerMap.put(Uri.UNAUTHORIZED, new UnAuthorizedController()); | ||
controllerMap.put(Uri.REGISTER, new RegisterController()); | ||
controllerMap.put(Uri.DEFAULT, new DefaultController()); | ||
} | ||
|
||
public Controller getController(final HttpRequest httpRequest) { | ||
final String path = httpRequest.getRequestLine().getPath(); | ||
final Uri uri = Uri.from(path); | ||
return controllerMap.get(uri); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tomcat/src/main/java/org/apache/coyote/http11/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,30 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import org.apache.coyote.http11.HttpMethod; | ||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public abstract class AbstractController implements Controller { | ||
|
||
@Override | ||
public void service(HttpRequest request, HttpResponse response) throws Exception { | ||
final HttpMethod httpMethod = request.getRequestLine().getHttpMethod(); | ||
if (httpMethod == HttpMethod.GET) { | ||
doGet(request, response); | ||
return; | ||
} | ||
if (httpMethod == HttpMethod.POST) { | ||
doPost(request, response); | ||
return; | ||
} | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
protected void doGet(HttpRequest request, HttpResponse response) throws Exception { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
protected void doPost(HttpRequest request, HttpResponse response) throws Exception { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tomcat/src/main/java/org/apache/coyote/http11/controller/Controller.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,8 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
|
||
public interface Controller { | ||
void service(HttpRequest request, HttpResponse response) throws Exception; | ||
} |
20 changes: 20 additions & 0 deletions
20
tomcat/src/main/java/org/apache/coyote/http11/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,20 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
import org.apache.coyote.http11.response.HttpStatus; | ||
import org.apache.coyote.http11.response.ResponseBody; | ||
import org.apache.coyote.http11.response.StaticResource; | ||
|
||
public class DefaultController extends AbstractController { | ||
|
||
@Override | ||
protected void doGet(HttpRequest request, HttpResponse response) throws Exception { | ||
final String path = request.getRequestLine().getPath(); | ||
final StaticResource staticResource = StaticResource.from(path); | ||
final ResponseBody responseBody = ResponseBody.from(staticResource); | ||
|
||
response.setHttpStatus(HttpStatus.OK); | ||
response.setResponseBody(responseBody); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tomcat/src/main/java/org/apache/coyote/http11/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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.apache.coyote.http11.controller; | ||
|
||
import org.apache.coyote.http11.request.HttpRequest; | ||
import org.apache.coyote.http11.response.HttpResponse; | ||
import org.apache.coyote.http11.response.HttpStatus; | ||
import org.apache.coyote.http11.response.ResponseBody; | ||
import org.apache.coyote.http11.response.StaticResource; | ||
|
||
public class IndexController extends AbstractController { | ||
|
||
@Override | ||
protected void doGet(HttpRequest request, HttpResponse response) throws Exception { | ||
final StaticResource staticResource = StaticResource.from(Uri.INDEX.getFullPath()); | ||
final ResponseBody responseBody = ResponseBody.from(staticResource); | ||
response.setHttpStatus(HttpStatus.OK); | ||
response.setResponseBody(responseBody); | ||
response.setResponseHeaders(responseBody); | ||
} | ||
} |
Oops, something went wrong.