All Downloads are FREE. Search and download functionalities are using the official Maven repository.

le-annen.javaserver.0.1.source-code.RequestHandler Maven / Gradle / Ivy

Go to download

A minimal java http server which fulfills small portions of the http specifications. This is not a full fledged or secure server. It should only be used for learning purposes and contains no guarantees of any king.

The newest version!
import java.io.IOException;
import java.net.Socket;

public class RequestHandler implements Runnable {
  private String directoryPath;
  private Socket socket;
  private LoggerInterface logger;
  private RouterInterface router;
  private SendInterface sendInterface;
  private ReadInterface readInterface;

  RequestHandler(String directoryPath,
                 Socket socket,
                 Logger logger,
                 RouterInterface router,
                 SendInterface sendInterface,
                 ReadInterface readInterface) {
    this.directoryPath = directoryPath;
    this.socket = socket;
    this.logger = logger;
    this.router = router;
    this.sendInterface = sendInterface;
    this.readInterface = readInterface;
  }

  public void run() {
    try {
      RequestParameters requestParams =
              this.readInterface.getRequest(this.socket, this.directoryPath);
      ResponseParameters responseParams =
              this.router.route(requestParams);

      this.sendInterface.send(responseParams, this.socket);
    } catch (IOException e) {
      logger.log(e.toString());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy