annotate src/goodjava/webserver/Status.java @ 1474:13cbce740e1e

LowercaseAnalyzer
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 17 Apr 2020 21:53:09 -0600
parents 27efb1fcbcb5
children 8a7519dee55c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1402
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1347
diff changeset
1 package goodjava.webserver;
1137
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
1155
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
3 import java.util.Map;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
4 import java.util.HashMap;
1402
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1347
diff changeset
5 import goodjava.logging.Logger;
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1347
diff changeset
6 import goodjava.logging.LoggerFactory;
1155
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
7
1137
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 public class Status {
1155
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
10 private static final Logger logger = LoggerFactory.getLogger(Status.class);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
11
1137
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 public final int code;
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 public final String reason;
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 public Status(int code,String reason) {
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 this.code = code;
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 this.reason = reason;
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 }
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
1155
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
20 private static final Map<Integer,Status> map = new HashMap<Integer,Status>();
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
21
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
22 protected static Status newStatus(int code,String reason) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
23 Status status = new Status(code,reason);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
24 map.put(code,status);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
25 return status;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
26 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
27
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
28 public static Status getStatus(int code) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
29 Status status = map.get(code);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
30 if( status == null ) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
31 logger.warn("missing status "+code);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
32 status = new Status(code,"");
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
33 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
34 return status;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
35 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
36
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
37 public static final Status OK = newStatus(200,"OK");
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
38 public static final Status MOVED_PERMANENTLY = newStatus(301,"Moved Permanently");
1160
4beabb087be6 add http/impl
Franklin Schmidt <fschmidt@gmail.com>
parents: 1155
diff changeset
39 public static final Status FOUND = newStatus(302,"Found");
1194
bd0420fb3dd0 handle ParseException in webserver
Franklin Schmidt <fschmidt@gmail.com>
parents: 1160
diff changeset
40 public static final Status BAD_REQUEST = newStatus(400,"Bad Request");
1155
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
41 public static final Status NOT_FOUND = newStatus(404,"Not Found");
Franklin Schmidt <fschmidt@gmail.com>
parents: 1137
diff changeset
42 public static final Status INTERNAL_SERVER_ERROR = newStatus(500,"Internal Server Error");
1137
c123ee15f99b add webserver
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 }