You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/11 18:56:25 UTC

[3/6] camel git commit: CAMEL-8044: Camel commands useable for remote JVMs using jolokia

CAMEL-8044: Camel commands useable for remote JVMs using jolokia


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7f5e278f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7f5e278f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7f5e278f

Branch: refs/heads/master
Commit: 7f5e278f650ebc08e44ff3018047852d6351bef9
Parents: 3636e30
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Dec 11 17:43:49 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Dec 11 18:56:10 2014 +0100

----------------------------------------------------------------------
 .../jolokia/JolokiaCamelController.java         | 60 ++++++++++++--------
 1 file changed, 35 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7f5e278f/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java b/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java
index 730c913..bb87e81 100644
--- a/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java
+++ b/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/JolokiaCamelController.java
@@ -431,35 +431,37 @@ public class JolokiaCamelController extends AbstractCamelController implements R
 
             J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "listRestServices()"));
             if (response != null) {
-                JSONObject data = response.asJSONObject();
-                // TODO: parse the open data type
-            }
+                JSONObject data = response.getValue();
+                for (Object obj : data.values()) {
+                    JSONObject data2 = (JSONObject) obj;
+                    JSONObject service = (JSONObject) data2.values().iterator().next();
 
-            /*
-                List<RestRegistry.RestService> services = new ArrayList<RestRegistry.RestService>(context.getRestRegistry().listAllRestServices());
-                Collections.sort(services, new Comparator<RestRegistry.RestService>() {
-                    @Override
-                    public int compare(RestRegistry.RestService o1, RestRegistry.RestService o2) {
-                        return o1.getUrl().compareTo(o2.getUrl());
-                    }
-                });
-                for (RestRegistry.RestService service : services) {
                     Map<String, String> row = new LinkedHashMap<String, String>();
-                    row.put("basePath", service.getBasePath());
-                    row.put("baseUrl", service.getBaseUrl());
-                    row.put("consumes", service.getConsumes());
-                    row.put("description", service.getDescription());
-                    row.put("inType", service.getInType());
-                    row.put("method", service.getMethod());
-                    row.put("outType", service.getOutType());
-                    row.put("produces", service.getProduces());
-                    row.put("routeId", service.getRouteId());
-                    row.put("state", service.getState());
-                    row.put("uriTemplate", service.getUriTemplate());
-                    row.put("url", service.getUrl());
+                    row.put("basePath", asString(service.get("basePath")));
+                    row.put("baseUrl", asString(service.get("baseUrl")));
+                    row.put("consumes", asString(service.get("consumes")));
+                    row.put("description", asString(service.get("description")));
+                    row.put("inType", asString(service.get("inType")));
+                    row.put("method", asString(service.get("method")));
+                    row.put("outType", asString(service.get("outType")));
+                    row.put("produces", asString(service.get("produces")));
+                    row.put("routeId", asString(service.get("routeId")));
+                    row.put("state", asString(service.get("state")));
+                    row.put("uriTemplate", asString(service.get("uriTemplate")));
+                    row.put("url", asString(service.get("url")));
                     answer.add(row);
                 }
-            }   */
+            }
+
+            // sort the list
+            Collections.sort(answer, new Comparator<Map<String, String>>() {
+                @Override
+                public int compare(Map<String, String> service1, Map<String, String> service2) {
+                    String url1 = service1.get("url");
+                    String url2 = service2.get("url");
+                    return url1.compareTo(url2);
+                }
+            });
         }
 
         return answer;
@@ -499,4 +501,12 @@ public class JolokiaCamelController extends AbstractCamelController implements R
         return ch + attributeKey.substring(1);
     }
 
+    private static String asString(Object basePath) {
+        if (basePath == null) {
+            return null;
+        } else {
+            return basePath.toString();
+        }
+    }
+
 }