src/jdk.management.rest/share/classes/jdk/internal/management/remote/rest/http/RestResource.java
branchjmx-rest-api
changeset 56026 bd531f08d7c7
equal deleted inserted replaced
56007:d6cbabcaf518 56026:bd531f08d7c7
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package jdk.internal.management.remote.rest.http;
       
    27 
       
    28 import com.sun.net.httpserver.HttpExchange;
       
    29 import com.sun.net.httpserver.HttpHandler;
       
    30 
       
    31 import java.io.IOException;
       
    32 
       
    33 /**
       
    34  *
       
    35  * @author harsha
       
    36  */
       
    37 public interface RestResource extends HttpHandler {
       
    38     @Override
       
    39     public default void handle(HttpExchange exchange) throws IOException {
       
    40         HttpResponse httpResponse = HttpResponse.METHOD_NOT_ALLOWED;
       
    41         switch (exchange.getRequestMethod()) {
       
    42             case "GET":
       
    43                 httpResponse = doGet(exchange);
       
    44                 break;
       
    45             case "POST":
       
    46                 httpResponse = doPost(exchange);
       
    47                 break;
       
    48             case "PUT":
       
    49                 httpResponse = doPut(exchange);
       
    50                 break;
       
    51             case "DELETE":
       
    52                 httpResponse = doDelete(exchange);
       
    53                 break;
       
    54             case "HEAD":
       
    55                 httpResponse = doHead(exchange);
       
    56                 break;
       
    57             case "PATCH":
       
    58                 httpResponse = doPatch(exchange);
       
    59                 break;
       
    60             case "CONNET":
       
    61                 httpResponse = doConnect(exchange);
       
    62                 break;
       
    63             case "TRACE":
       
    64                 httpResponse = doTrace(exchange);
       
    65                 break;
       
    66             case "OPTIONS":
       
    67                 httpResponse = doOptions(exchange);
       
    68                 break;
       
    69         }
       
    70         HttpUtil.sendResponse(exchange, httpResponse);
       
    71     }
       
    72 
       
    73     public default HttpResponse doGet(HttpExchange exchange) {
       
    74         return HttpResponse.METHOD_NOT_ALLOWED;
       
    75     }
       
    76 
       
    77     public default HttpResponse doPut(HttpExchange exchange) {
       
    78         return HttpResponse.METHOD_NOT_ALLOWED;
       
    79     }
       
    80 
       
    81     public default HttpResponse doPost(HttpExchange exchange) {
       
    82         return HttpResponse.METHOD_NOT_ALLOWED;
       
    83     }
       
    84 
       
    85     public default HttpResponse doDelete(HttpExchange exchange) {
       
    86         return HttpResponse.METHOD_NOT_ALLOWED;
       
    87     }
       
    88 
       
    89     public default HttpResponse doHead(HttpExchange exchange) {
       
    90         return HttpResponse.METHOD_NOT_ALLOWED;
       
    91     }
       
    92 
       
    93     public default HttpResponse doConnect(HttpExchange exchange) {
       
    94         return HttpResponse.METHOD_NOT_ALLOWED;
       
    95     }
       
    96 
       
    97     public default HttpResponse doOptions(HttpExchange exchange) {
       
    98         return HttpResponse.METHOD_NOT_ALLOWED;
       
    99     }
       
   100 
       
   101     public default HttpResponse doTrace(HttpExchange exchange) {
       
   102         return HttpResponse.METHOD_NOT_ALLOWED;
       
   103     }
       
   104 
       
   105     public default HttpResponse doPatch(HttpExchange exchange) {
       
   106         return HttpResponse.METHOD_NOT_ALLOWED;
       
   107     }
       
   108 }