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

le-annen.javaserver.0.1.source-code.Routes 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.util.HashMap;
import java.util.Set;

public class Routes {
  private HashMap routes;

  Routes() { this.routes = new HashMap<>(); }

  public void add(String path, ControllerInterface controller) { this.routes.put(path, controller); }

  public ControllerInterface get(String path) { return this.routes.get(path); }

  Set getRoutePaths() { return this.routes.keySet(); }

  Boolean routeExists(String route) { return this.routes.keySet().contains(route); }

  public ResponseParameters getResponse(RequestParameters requestParameters) throws IOException {
    String path = requestParameters.getRequestPath();
    Boolean routeExists = this.routes.keySet().contains(path);
    if (routeExists) {
      return this.routes.get(path).getResponse(requestParameters);
    } else {
      return new ControllerFourOhFour().getResponse(requestParameters);
    }
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy