src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/http/MBeanServerCollectionResource.java
branchjmx-rest-api
changeset 56006 352a4f213fc6
parent 55998 54779691e11f
equal deleted inserted replaced
56005:90cff2ac77b8 56006:352a4f213fc6
    31 import com.sun.net.httpserver.HttpServer;
    31 import com.sun.net.httpserver.HttpServer;
    32 
    32 
    33 import javax.management.remote.rest.PlatformRestAdapter;
    33 import javax.management.remote.rest.PlatformRestAdapter;
    34 import java.io.UnsupportedEncodingException;
    34 import java.io.UnsupportedEncodingException;
    35 import java.net.HttpURLConnection;
    35 import java.net.HttpURLConnection;
       
    36 import java.net.URLDecoder;
       
    37 import java.nio.charset.StandardCharsets;
    36 import java.util.List;
    38 import java.util.List;
    37 
    39 
    38 /**
    40 /**
    39  * This class handles all the HTTP requests for the base URL
    41  * This class handles all the HTTP requests for the base URL
    40  * for REST adapter.
    42  * for REST adapter.
    55             JSONObject _links = HttpUtil.getPaginationLinks(exchange, restAdapters, pageSize);
    57             JSONObject _links = HttpUtil.getPaginationLinks(exchange, restAdapters, pageSize);
    56             List<MBeanServerResource> filteredList = HttpUtil.filterByPage(exchange, restAdapters, pageSize);
    58             List<MBeanServerResource> filteredList = HttpUtil.filterByPage(exchange, restAdapters, pageSize);
    57             if (filteredList == null) {
    59             if (filteredList == null) {
    58                 return HttpResponse.OK;
    60                 return HttpResponse.OK;
    59             }
    61             }
    60 
    62             String query = exchange.getRequestURI().getQuery();
    61             final String path = PlatformRestAdapter.getDomain() +
    63             if (query != null) {
    62                     exchange.getRequestURI().getPath().replaceAll("/$", "");
    64                 return HttpResponse.BAD_REQUEST;
       
    65             }
       
    66             String exchangePath = URLDecoder.decode(exchange.getRequestURI().getPath(), StandardCharsets.UTF_8.displayName())
       
    67                     .replaceAll("/$", "");
       
    68             if (!exchangePath.equalsIgnoreCase("/jmx/servers")) {
       
    69                 return HttpResponse.REQUEST_NOT_FOUND;
       
    70             }
       
    71             final String path = PlatformRestAdapter.getDomain() + exchangePath;
    63 
    72 
    64             JSONObject root = new JSONObject();
    73             JSONObject root = new JSONObject();
    65             if (_links != null && !_links.isEmpty()) {
    74             if (_links != null && !_links.isEmpty()) {
    66                 root.put("_links", _links);
    75                 root.put("_links", _links);
    67             }
    76             }