Mercurial Hosting > luan
annotate src/goodjava/webserver/Status.java @ 1579:dd881eb03d87
yourkit link
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 10 Feb 2021 22:49:47 -0700 |
parents | 27efb1fcbcb5 |
children | 8a7519dee55c |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
1 package goodjava.webserver; |
1137 | 2 |
1155 | 3 import java.util.Map; |
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 | 7 |
1137 | 8 |
9 public class Status { | |
1155 | 10 private static final Logger logger = LoggerFactory.getLogger(Status.class); |
11 | |
1137 | 12 public final int code; |
13 public final String reason; | |
14 | |
15 public Status(int code,String reason) { | |
16 this.code = code; | |
17 this.reason = reason; | |
18 } | |
19 | |
1155 | 20 private static final Map<Integer,Status> map = new HashMap<Integer,Status>(); |
21 | |
22 protected static Status newStatus(int code,String reason) { | |
23 Status status = new Status(code,reason); | |
24 map.put(code,status); | |
25 return status; | |
26 } | |
27 | |
28 public static Status getStatus(int code) { | |
29 Status status = map.get(code); | |
30 if( status == null ) { | |
31 logger.warn("missing status "+code); | |
32 status = new Status(code,""); | |
33 } | |
34 return status; | |
35 } | |
36 | |
37 public static final Status OK = newStatus(200,"OK"); | |
38 public static final Status MOVED_PERMANENTLY = newStatus(301,"Moved Permanently"); | |
1160 | 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 | 41 public static final Status NOT_FOUND = newStatus(404,"Not Found"); |
42 public static final Status INTERNAL_SERVER_ERROR = newStatus(500,"Internal Server Error"); | |
1137 | 43 } |