You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2020/08/20 12:10:52 UTC

[jackrabbit-filevault] branch master updated: JCRVLT-470 expose meta information about ReST endpoint (#97)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b3c4cb  JCRVLT-470 expose meta information about ReST endpoint (#97)
0b3c4cb is described below

commit 0b3c4cb5a99d14e3d0ae881d7864806ed950c622
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Aug 20 14:07:53 2020 +0200

    JCRVLT-470 expose meta information about ReST endpoint (#97)
---
 vault-doc/src/site/markdown/rcp.md                 | 19 +++++++
 .../jackrabbit/vault/rcp/impl/RcpServlet.java      | 66 +++++++++++++++-------
 2 files changed, 65 insertions(+), 20 deletions(-)

diff --git a/vault-doc/src/site/markdown/rcp.md b/vault-doc/src/site/markdown/rcp.md
index 844abb3..e7c87ad 100644
--- a/vault-doc/src/site/markdown/rcp.md
+++ b/vault-doc/src/site/markdown/rcp.md
@@ -78,9 +78,28 @@ The vault rcp server bundle provides a very simple vault remote copy task manage
 ### Usage
 The vault rcp server maintains a list of _remote copy tasks_ that can be controlled via the http interface at `/system/jackrabbit/filevault/rcp`. The request and responses are JSON formatted.
 
+#### Get Info (GET)
+Exposes information about the RCP ReST endpoint. Is triggered with selector `info` and extension `json`: `/system/jackrabbit/filevault/rcp.info.json`
+
+##### Example
+
+    GET /system/jackrabbit/filevault/rcp.info.json HTTP/1.1
+    Host: localhost:4502
+    
+    HTTP/1.1 200 OK
+    Content-Type: application/json;charset=utf-8
+    
+    {
+        "Bundle-SymbolicName": "org.apache.jackrabbit.vault.rcp",
+        "Bundle-Version": "3.4.7.SNAPSHOT",
+        "Bundle-Vendor": "The Apache Software Foundation"
+    }
+
 #### List Tasks (GET)
 Simply lists all available tasks. In addition to listing the parameters that were passed when the task was created, it also list some information about the current state of the task.
 
+Optionally you can limit the information to one specific task only by giving its task id as suffix in the form `/system/jackrabbit/filevault/rcp.json/<taskid>`.
+
 | Property | Comment |
 | -------- | ------- |
 | state    | Current state of the task. One of `NEW` , `RUNNING`, `ENDED`, `STOPPED` |
diff --git a/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpServlet.java b/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpServlet.java
index 4a64d88..21e06a9 100644
--- a/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpServlet.java
+++ b/vault-rcp/src/main/java/org/apache/jackrabbit/vault/rcp/impl/RcpServlet.java
@@ -18,6 +18,7 @@
 package org.apache.jackrabbit.vault.rcp.impl;
 
 import java.io.IOException;
+import java.io.Writer;
 import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.LinkedList;
@@ -44,6 +45,11 @@ import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
 import org.apache.sling.commons.json.io.JSONWriter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -97,6 +103,13 @@ public class RcpServlet extends SlingAllMethodsServlet {
 
     @Reference
     private RcpTaskManager taskMgr;
+    
+    private Bundle bundle;
+
+    @Activate
+    protected void activate(BundleContext context){
+        bundle = context.getBundle();
+    }
 
     @Override
     protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
@@ -105,34 +118,47 @@ public class RcpServlet extends SlingAllMethodsServlet {
         response.setContentType("application/json");
         response.setCharacterEncoding("utf-8");
 
-        String taskId = request.getRequestPathInfo().getSuffix();
         try {
-            JSONWriter w = new JSONWriter(response.getWriter());
-            w.setTidy(true);
-
-            if (taskId != null) {
-                taskId = taskId.substring(1);
-                RcpTask task = taskMgr.getTask(taskId);
-
-                if (task != null) {
-                    write(w, task);
-                } else {
-                    // return empty object
-                    w.object().endObject();
-                }
+            if ("json".equals(request.getRequestPathInfo().getExtension()) && "info".equals(request.getRequestPathInfo().getSelectorString())) {
+                writeInfoJson(response.getWriter());
             } else {
-                w.object();
-                w.key("tasks").array();
-                for (RcpTask task: taskMgr.getTasks().values()) {
-                    write(w, task);
+                String taskId = request.getRequestPathInfo().getSuffix();
+                JSONWriter w = new JSONWriter(response.getWriter());
+                w.setTidy(true);
+    
+                if (taskId != null) {
+                    taskId = taskId.substring(1);
+                    RcpTask task = taskMgr.getTask(taskId);
+    
+                    if (task != null) {
+                        write(w, task);
+                    } else {
+                        // return empty object
+                        w.object().endObject();
+                    }
+                } else {
+                    w.object();
+                    w.key("tasks").array();
+                    for (RcpTask task: taskMgr.getTasks().values()) {
+                        write(w, task);
+                    }
+                    w.endArray();
+                    w.endObject();
                 }
-                w.endArray();
-                w.endObject();
             }
         } catch (JSONException e) {
             throw new IOException(e.toString());
         }
+    }
 
+    private void writeInfoJson(Writer writer) throws JSONException {
+        JSONWriter w = new JSONWriter(writer);
+        w.setTidy(true);
+        w.object();
+        w.key(Constants.BUNDLE_SYMBOLICNAME).value(bundle.getSymbolicName());
+        w.key(Constants.BUNDLE_VERSION).value(bundle.getVersion().toString());
+        w.key(Constants.BUNDLE_VENDOR).value(bundle.getHeaders().get(Constants.BUNDLE_VENDOR));
+        w.endObject();
     }
 
     @Override