src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/http/RestResource.java
equal
deleted
inserted
replaced
|
1 /* |
|
2 * To change this license header, choose License Headers in Project Properties. |
|
3 * To change this template file, choose Tools | Templates |
|
4 * and open the template in the editor. |
|
5 */ |
|
6 package com.oracle.jmx.remote.rest.http; |
|
7 |
|
8 import com.sun.net.httpserver.HttpExchange; |
|
9 import com.sun.net.httpserver.HttpHandler; |
|
10 import java.io.IOException; |
|
11 |
|
12 /** |
|
13 * |
|
14 * @author harsha |
|
15 */ |
|
16 public interface RestResource extends HttpHandler { |
|
17 @Override |
|
18 public default void handle (HttpExchange exchange) throws IOException { |
|
19 HttpResponse httpResponse = HttpResponse.METHOD_NOT_ALLOWED; |
|
20 switch (exchange.getRequestMethod()) { |
|
21 case "GET": |
|
22 httpResponse = doGet(exchange); |
|
23 break; |
|
24 case "POST": |
|
25 httpResponse = doPost(exchange); |
|
26 break; |
|
27 case "PUT": |
|
28 httpResponse = doPut(exchange); |
|
29 break; |
|
30 case "DELETE": |
|
31 httpResponse = doDelete(exchange); |
|
32 break; |
|
33 case "HEAD": |
|
34 httpResponse = doHead(exchange); |
|
35 break; |
|
36 } |
|
37 HttpUtil.sendResponse(exchange,httpResponse); |
|
38 } |
|
39 |
|
40 public HttpResponse doGet(HttpExchange exchange); |
|
41 public HttpResponse doPut(HttpExchange exchange); |
|
42 public HttpResponse doPost(HttpExchange exchange); |
|
43 public HttpResponse doDelete(HttpExchange exchange); |
|
44 public HttpResponse doHead(HttpExchange exchange); |
|
45 } |