forked from slipp/web-application-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractController.java
More file actions
30 lines (24 loc) · 1.02 KB
/
AbstractController.java
File metadata and controls
30 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package controller;
import webserver.model.HttpRequest;
import webserver.model.HttpResponse;
import model.HttpMethod;
import java.io.IOException;
public abstract class AbstractController implements Controller {
public final HttpResponse process(HttpRequest httpRequest) throws IOException, IllegalAccessException {
final HttpMethod method = HttpMethod.valueOf(httpRequest.getMethod());
switch (method) {
case GET:
return doGet(httpRequest);
case POST:
return doPost(httpRequest);
default:
throw new IllegalArgumentException("Illegal Http Method");
}
}
protected HttpResponse doGet(HttpRequest httpRequest) throws IOException, IllegalAccessException {
throw new IllegalAccessException("doGet() is not overridden.");
}
protected HttpResponse doPost(HttpRequest httpRequest) throws IOException, IllegalAccessException {
throw new IllegalAccessException("doPost() is not overridden.");
}
}