diff --git a/tomcat/src/main/java/nextstep/jwp/controller/AbstractController.java b/tomcat/src/main/java/nextstep/jwp/controller/AbstractController.java index 4fc2c9b0dc..d5bbb2a27e 100644 --- a/tomcat/src/main/java/nextstep/jwp/controller/AbstractController.java +++ b/tomcat/src/main/java/nextstep/jwp/controller/AbstractController.java @@ -19,19 +19,19 @@ public abstract class AbstractController implements Controller { protected static final String HTTP_METHOD_EXCEPTION_MESSAGE = "올바르지 않은 HTTP Method 입니다."; @Override - public void service(final HttpRequest request, final HttpResponse response) throws IOException { - if (request.getRequestLine().getMethod().equals("POST")) { - doPost(request, response); + public void service(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { + if (httpRequest.getRequestLine().getMethod().equals("POST")) { + doPost(httpRequest, httpResponse); return; } - if (request.getRequestLine().getMethod().equals("GET")) { - doGet(request, response); + if (httpRequest.getRequestLine().getMethod().equals("GET")) { + doGet(httpRequest, httpResponse); return; } throw new HttpRequestException(HTTP_METHOD_EXCEPTION_MESSAGE); } - protected abstract void doPost(final HttpRequest request, final HttpResponse response) throws IOException; + protected abstract void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException; - protected abstract void doGet(final HttpRequest request, final HttpResponse response) throws IOException; + protected abstract void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException; } diff --git a/tomcat/src/main/java/nextstep/jwp/controller/HomeController.java b/tomcat/src/main/java/nextstep/jwp/controller/HomeController.java index 1a91d2cda9..c193a90348 100644 --- a/tomcat/src/main/java/nextstep/jwp/controller/HomeController.java +++ b/tomcat/src/main/java/nextstep/jwp/controller/HomeController.java @@ -9,18 +9,18 @@ public class HomeController extends AbstractController { @Override - protected void doPost(final HttpRequest request, final HttpResponse response) { - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.METHOD_NOT_ALLOWED); - response.setStatusLine(statusLine); + protected void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.METHOD_NOT_ALLOWED); + httpResponse.setStatusLine(statusLine); } @Override - protected void doGet(final HttpRequest request, final HttpResponse response) { - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.OK); + protected void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.OK); final var responseBody = ResponseBody.fromText("Hello world!"); - response.setStatusLine(statusLine); - response.addResponseHeader("Content-Type", TEXT_HTML); - response.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); - response.setResponseBody(responseBody); + httpResponse.setStatusLine(statusLine); + httpResponse.addResponseHeader("Content-Type", TEXT_HTML); + httpResponse.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); + httpResponse.setResponseBody(responseBody); } } diff --git a/tomcat/src/main/java/nextstep/jwp/controller/LoginController.java b/tomcat/src/main/java/nextstep/jwp/controller/LoginController.java index c5ff722ddf..8550fb3f19 100644 --- a/tomcat/src/main/java/nextstep/jwp/controller/LoginController.java +++ b/tomcat/src/main/java/nextstep/jwp/controller/LoginController.java @@ -20,44 +20,44 @@ public class LoginController extends AbstractController { private static final SessionManager SESSION_MANAGER = new SessionManager(); @Override - protected void doPost(final HttpRequest request, final HttpResponse response) { - final HttpCookie cookie = request.getCookie(); + protected void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final HttpCookie cookie = httpRequest.getCookie(); final User user = findUserBySessionId(cookie.getJSessionId()); - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.FOUND); - response.setStatusLine(statusLine); + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.FOUND); + httpResponse.setStatusLine(statusLine); if (user == null) { - handleFirstLogin(request, response); + handleFirstLogin(httpRequest, httpResponse); return; } - response.addResponseHeader(HEADER_LOCATION, INDEX_PAGE); + httpResponse.addResponseHeader(HEADER_LOCATION, INDEX_PAGE); } - private void handleFirstLogin(final HttpRequest request, final HttpResponse response) { - final Map requestBodyValues = request.getRequestParameters(); + private void handleFirstLogin(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final Map requestBodyValues = httpRequest.getRequestParameters(); final Optional user = InMemoryUserRepository.findByAccount(requestBodyValues.get("account")); if (user.isEmpty() || !user.get().checkPassword(requestBodyValues.get("password"))) { - response.addResponseHeader(HEADER_LOCATION, UNAUTHORIZED_PAGE); + httpResponse.addResponseHeader(HEADER_LOCATION, UNAUTHORIZED_PAGE); return; } final String sessionId = addSession(user.get()); - response.addResponseHeader(HEADER_LOCATION, INDEX_PAGE); - response.addResponseHeader(HEADER_SET_COOKIE, "JSESSIONID=" + sessionId); + httpResponse.addResponseHeader(HEADER_LOCATION, INDEX_PAGE); + httpResponse.addResponseHeader(HEADER_SET_COOKIE, "JSESSIONID=" + sessionId); } @Override - protected void doGet(final HttpRequest request, final HttpResponse response) throws IOException { - final HttpCookie cookie = request.getCookie(); + protected void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { + final HttpCookie cookie = httpRequest.getCookie(); final User user = findUserBySessionId(cookie.getJSessionId()); if (user != null) { - doPost(request, response); + doPost(httpRequest, httpResponse); return; } - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.OK); + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.OK); final var responseBody = ResponseBody.fromUri("/login.html"); - response.setStatusLine(statusLine); - response.addResponseHeader(HEADER_CONTENT_TYPE, TEXT_HTML); - response.addResponseHeader(HEADER_CONTENT_LENGTH, String.valueOf(responseBody.getBody().getBytes().length)); - response.setResponseBody(responseBody); + httpResponse.setStatusLine(statusLine); + httpResponse.addResponseHeader(HEADER_CONTENT_TYPE, TEXT_HTML); + httpResponse.addResponseHeader(HEADER_CONTENT_LENGTH, String.valueOf(responseBody.getBody().getBytes().length)); + httpResponse.setResponseBody(responseBody); } private User findUserBySessionId(final String sessionId) { diff --git a/tomcat/src/main/java/nextstep/jwp/controller/RegisterController.java b/tomcat/src/main/java/nextstep/jwp/controller/RegisterController.java index 0790a49fbe..bdc32dc7c7 100644 --- a/tomcat/src/main/java/nextstep/jwp/controller/RegisterController.java +++ b/tomcat/src/main/java/nextstep/jwp/controller/RegisterController.java @@ -14,24 +14,24 @@ public class RegisterController extends AbstractController { @Override - protected void doPost(final HttpRequest request, final HttpResponse response) { - final Map requestBodyValues = request.getRequestParameters(); + protected void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final Map requestBodyValues = httpRequest.getRequestParameters(); final var user = new User(requestBodyValues.get("account"), requestBodyValues.get("password"), requestBodyValues.get("email")); InMemoryUserRepository.save(user); - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.FOUND); - response.setStatusLine(statusLine); - response.addResponseHeader("Location", INDEX_PAGE); + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.FOUND); + httpResponse.setStatusLine(statusLine); + httpResponse.addResponseHeader("Location", INDEX_PAGE); } @Override - protected void doGet(final HttpRequest request, final HttpResponse response) throws IOException { - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.OK); + protected void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.OK); final var responseBody = ResponseBody.fromUri("/register.html"); - response.setStatusLine(statusLine); - response.addResponseHeader("Content-Type", TEXT_HTML); - response.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); - response.setResponseBody(responseBody); + httpResponse.setStatusLine(statusLine); + httpResponse.addResponseHeader("Content-Type", TEXT_HTML); + httpResponse.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); + httpResponse.setResponseBody(responseBody); } } diff --git a/tomcat/src/main/java/nextstep/jwp/controller/ResourceController.java b/tomcat/src/main/java/nextstep/jwp/controller/ResourceController.java index 39b50a2a29..c58a0d5ef6 100644 --- a/tomcat/src/main/java/nextstep/jwp/controller/ResourceController.java +++ b/tomcat/src/main/java/nextstep/jwp/controller/ResourceController.java @@ -11,20 +11,20 @@ public class ResourceController extends AbstractController { @Override - protected void doPost(final HttpRequest request, final HttpResponse response) { - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.METHOD_NOT_ALLOWED); - response.setStatusLine(statusLine); + protected void doPost(final HttpRequest httpRequest, final HttpResponse httpResponse) { + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.METHOD_NOT_ALLOWED); + httpResponse.setStatusLine(statusLine); } @Override - protected void doGet(final HttpRequest request, final HttpResponse response) throws IOException { - final var statusLine = StatusLine.of(request.getRequestLine().getProtocol(), HttpStatus.OK); - final String uri = request.getRequestLine().getPath().split("\\?")[0]; + protected void doGet(final HttpRequest httpRequest, final HttpResponse httpResponse) throws IOException { + final var statusLine = StatusLine.of(httpRequest.getRequestLine().getProtocol(), HttpStatus.OK); + final String uri = httpRequest.getRequestLine().getPath().split("\\?")[0]; final var responseBody = ResponseBody.fromUri(uri); - response.setStatusLine(statusLine); - response.addResponseHeader("Content-Type", getContentType(uri)); - response.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); - response.setResponseBody(responseBody); + httpResponse.setStatusLine(statusLine); + httpResponse.addResponseHeader("Content-Type", getContentType(uri)); + httpResponse.addResponseHeader("Content-Length", String.valueOf(responseBody.getBody().getBytes().length)); + httpResponse.setResponseBody(responseBody); } private String getContentType(final String uri) {