Skip to content
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단계] 저문(유정훈) 미션 제출합니다. #459

Merged
merged 15 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tomcat/src/main/java/org/apache/catalina/Manager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.apache.catalina;

import org.apache.coyote.http11.Session;
import org.apache.coyote.http11.auth.Session;

/**
* A <b>Manager</b> manages the pool of Sessions that are associated with a particular Container. Different Manager
Expand Down
18 changes: 11 additions & 7 deletions tomcat/src/main/java/org/apache/catalina/connector/Connector.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package org.apache.catalina.connector;

import org.apache.coyote.http11.Http11Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.coyote.http11.Http11Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Connector implements Runnable {

private static final Logger log = LoggerFactory.getLogger(Connector.class);

private static final int DEFAULT_PORT = 8080;
private static final int DEFAULT_ACCEPT_COUNT = 100;
private static final int DEFAULT_THREAD_COUNT = 250;

private final ServerSocket serverSocket;
private final ExecutorService executorService;
private boolean stopped;

public Connector() {
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT);
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT, DEFAULT_THREAD_COUNT);
}

public Connector(final int port, final int acceptCount) {
public Connector(final int port, final int acceptCount, final int maxThreads) {
this.serverSocket = createServerSocket(port, acceptCount);
this.executorService = Executors.newFixedThreadPool(maxThreads);
this.stopped = false;
}

Expand Down Expand Up @@ -67,7 +71,7 @@ private void process(final Socket connection) {
return;
}
var processor = new Http11Processor(connection);
new Thread(processor).start();
executorService.execute(processor);
}

public void stop() {
Expand Down
20 changes: 13 additions & 7 deletions tomcat/src/main/java/org/apache/coyote/http11/Http11Processor.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.apache.coyote.http11;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import nextstep.jwp.exception.UncheckedServletException;
import org.apache.coyote.Processor;
import org.apache.coyote.http11.auth.SessionManager;
import org.apache.coyote.http11.controller.Controller;
import org.apache.coyote.http11.controller.RequestMapping;
import org.apache.coyote.http11.request.HttpRequest;
import org.apache.coyote.http11.response.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Http11Processor implements Runnable, Processor {

public static final SessionManager SESSION_MANAGER = new SessionManager();
private static final Logger log = LoggerFactory.getLogger(Http11Processor.class);

private final Socket connection;
Expand All @@ -33,13 +37,15 @@ public void process(final Socket connection) {
final BufferedReader bufferedReader = new BufferedReader(inputStreamReader)
) {
final HttpRequest request = HttpRequest.from(bufferedReader);
final HttpRequestHandler requestHandler = new HttpRequestHandler(request);
final HttpResponseEntity responseEntity = requestHandler.handle();
final String response = HttpResponse.getResponse(responseEntity);
final HttpResponse response = new HttpResponse();

outputStream.write(response.getBytes());
final RequestMapping requestMapping = new RequestMapping();
final Controller controller = requestMapping.getController(request);
controller.service(request, response);

outputStream.write(response.get().getBytes());
outputStream.flush();
} catch (IOException | UncheckedServletException e) {
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Expand Down
7 changes: 5 additions & 2 deletions tomcat/src/main/java/org/apache/coyote/http11/HttpCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

public class HttpCookie {

private static final String COOKIE_DELIMITER = "; ";
private static final String COOKIE_SEPARATOR = "=";

private final Map<String, String> values;

public static HttpCookie ofJSessionId(final String jSessionId) {
Expand All @@ -19,10 +22,10 @@ public HttpCookie(final Map<String, String> values) {
this.values = values;
}

public String getValues() {
public String printValues() {
return values.keySet()
.stream()
.map(key -> key + "=" + values.get(key) + "; ")
.map(key -> key + COOKIE_SEPARATOR + values.get(key) + COOKIE_DELIMITER)
.collect(Collectors.joining());
}

Expand Down
38 changes: 0 additions & 38 deletions tomcat/src/main/java/org/apache/coyote/http11/HttpPath.java

This file was deleted.

64 changes: 0 additions & 64 deletions tomcat/src/main/java/org/apache/coyote/http11/HttpRequest.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading