|
23 | 23 |
|
24 | 24 | import lombok.experimental.UtilityClass;
|
25 | 25 |
|
| 26 | +/** |
| 27 | + * This class provides utility methods for handling HTTP request mappings. |
| 28 | + */ |
| 29 | + |
26 | 30 | @UtilityClass
|
27 | 31 | public class RequestMapping {
|
28 | 32 |
|
| 33 | + /** |
| 34 | + * Performs a POST mapping for a specific URL. |
| 35 | + * |
| 36 | + * @param value the URL pattern to match |
| 37 | + * @param httpExchange the exchange containing the request from the client and used to send the response |
| 38 | + * @return {@code true} if the URL pattern matches and the HTTP method is POST, {@code false} otherwise |
| 39 | + */ |
29 | 40 | public boolean postMapping(String value, HttpExchange httpExchange) {
|
30 | 41 | return isUrlMatch(value, httpExchange, HttpMethod.POST.name());
|
31 | 42 | }
|
32 | 43 |
|
| 44 | + /** |
| 45 | + * Performs a GET mapping for a specific URL. |
| 46 | + * |
| 47 | + * @param value the URL pattern to match |
| 48 | + * @param httpExchange the exchange containing the request from the client and used to send the response |
| 49 | + * @return {@code true} if the URL pattern matches and the HTTP method is GET, {@code false} otherwise |
| 50 | + */ |
33 | 51 | public boolean getMapping(String value, HttpExchange httpExchange) {
|
34 | 52 | return isUrlMatch(value, httpExchange, HttpMethod.GET.name());
|
35 | 53 | }
|
36 | 54 |
|
| 55 | + /** |
| 56 | + * Performs a PUT mapping for a specific URL. |
| 57 | + * |
| 58 | + * @param value the URL pattern to match |
| 59 | + * @param httpExchange the exchange containing the request from the client and used to send the response |
| 60 | + * @return {@code true} if the URL pattern matches and the HTTP method is PUT, {@code false} otherwise |
| 61 | + */ |
37 | 62 | public boolean putMapping(String value, HttpExchange httpExchange) {
|
38 | 63 | return isUrlMatch(value, httpExchange, HttpMethod.PUT.name());
|
39 | 64 | }
|
40 | 65 |
|
| 66 | + /** |
| 67 | + * Performs a DELETE mapping for a specific URL. |
| 68 | + * |
| 69 | + * @param value the URL pattern to match |
| 70 | + * @param httpExchange the exchange containing the request from the client and used to send the response |
| 71 | + * @return {@code true} if the URL pattern matches and the HTTP method is DELETE, {@code false} otherwise |
| 72 | + */ |
41 | 73 | public boolean deleteMapping(String value, HttpExchange httpExchange) {
|
42 | 74 | return isUrlMatch(value, httpExchange, HttpMethod.DELETE.name());
|
43 | 75 | }
|
44 | 76 |
|
| 77 | + /** |
| 78 | + * Checks if the URL pattern matches the request URI and the HTTP method is the specified method type. |
| 79 | + * |
| 80 | + * @param value the URL pattern to match |
| 81 | + * @param httpExchange the exchange containing the request from the client and used to send the response |
| 82 | + * @param methodType the HTTP method type to check against |
| 83 | + * @return {@code true} if the URL pattern matches and the HTTP method is the specified method type, {@code false} otherwise |
| 84 | + */ |
45 | 85 | private boolean isUrlMatch(String value, HttpExchange httpExchange, String methodType) {
|
46 | 86 | if (methodType.equalsIgnoreCase(httpExchange.getRequestMethod())) {
|
47 | 87 | String requestUri = httpExchange.getRequestURI().getPath();
|
|
0 commit comments