src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/http/MBeanResource.java
branchjmx-rest-api
changeset 56006 352a4f213fc6
parent 56001 95c0323f0c1a
child 56007 d6cbabcaf518
--- a/src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/http/MBeanResource.java	Tue Jan 02 15:03:52 2018 +0530
+++ b/src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/http/MBeanResource.java	Thu Jan 04 14:39:04 2018 +0530
@@ -31,6 +31,7 @@
 import com.oracle.jmx.remote.rest.json.JSONPrimitive;
 import com.oracle.jmx.remote.rest.json.parser.JSONParser;
 import com.oracle.jmx.remote.rest.json.parser.ParseException;
+import com.oracle.jmx.remote.rest.json.parser.TokenMgrError;
 import com.oracle.jmx.remote.rest.mapper.JSONDataException;
 import com.oracle.jmx.remote.rest.mapper.JSONMapper;
 import com.oracle.jmx.remote.rest.mapper.JSONMappingException;
@@ -44,6 +45,8 @@
 import javax.management.remote.rest.PlatformRestAdapter;
 import java.io.IOException;
 import java.net.HttpURLConnection;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -79,7 +82,7 @@
 
     @Override
     public void handle(HttpExchange exchange) throws IOException {
-        String path = exchange.getRequestURI().getPath();
+        String path = URLDecoder.decode(exchange.getRequestURI().getPath(),StandardCharsets.UTF_8.displayName());
         if (path.matches(pathPrefix + "/?$")) {
             RestResource.super.handle(exchange);
         } else if (path.matches(pathPrefix + "/info$")
@@ -98,16 +101,17 @@
         String path = PlatformRestAdapter.getDomain() +
                 exchange.getRequestURI().getPath().replaceAll("/$", "");
 
-        if (path.endsWith("info")) {
-            return doMBeanInfo();
-        }
+        try {
+            path = URLDecoder.decode(path, StandardCharsets.UTF_8.displayName());
+            if (path.endsWith("info")) {
+                return doMBeanInfo();
+            }
 
-        String infoPath = path + "/info";
+            String infoPath = path + "/info";
 
-        try {
             Map<String, Object> allAttributes = getAllAttributes();
             Map<String, String> _links = new LinkedHashMap<>();
-            _links.put("info", HttpUtil.escapeUrl(infoPath));
+            //_links.put("info", HttpUtil.escapeUrl(infoPath));
 
             MBeanOperationInfo[] opInfo = mBeanServer.getMBeanInfo(objectName).getOperations();
             JSONArray jarr = new JSONArray();
@@ -136,7 +140,6 @@
                 JSONObject jobj = new JSONObject();
                 jobj.put("attributes", jsonElement1);
                 jobj.put("operations", jarr);
-                jobj.put("_links", jsonElement2);
                 return new HttpResponse(jobj.toJsonString());
             } else {
                 return HttpResponse.SERVER_ERROR;
@@ -222,7 +225,7 @@
             }
         } catch (InstanceNotFoundException e) {
             // Should never happen
-        } catch (JSONDataException | ParseException e) {
+        } catch (JSONDataException | ParseException | TokenMgrError e) {
             return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, "Invalid JSON : " + reqBody, e.getMessage());
         } catch (IntrospectionException | JSONMappingException | MBeanException | ReflectionException | IOException e) {
             return new HttpResponse(HttpResponse.SERVER_ERROR, HttpResponse.getErrorMessage(e));
@@ -354,7 +357,7 @@
         return result;
     }
 
-    private JSONObject getMBeanInfo(MBeanServer mbeanServer, ObjectName mbean)
+    JSONObject getMBeanInfo(MBeanServer mbeanServer, ObjectName mbean)
             throws InstanceNotFoundException, IntrospectionException, ReflectionException {
 
         JSONObject jobj = new JSONObject();