瀏覽代碼

HPCC-9749 Support workunit resource access URLs in WsECL

Also extend the URL format to allow access via target/queryname, as well
as wuid.

Signed-off-by: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Anthony Fishbeck 11 年之前
父節點
當前提交
4ce54e931d

+ 2 - 0
common/wuwebview/wuweberror.hpp

@@ -26,5 +26,7 @@
 #define WUWEBERR_ManifestNotFound               5501
 #define WUWEBERR_ViewResourceNotFound           5502
 #define WUWEBERR_UnknownViewType                5503
+#define WUWEBERR_TargetNotFound                 5504
+#define WUWEBERR_QueryNotFound                  5505
 
 #endif

+ 66 - 0
common/wuwebview/wuwebview.cpp

@@ -830,3 +830,69 @@ extern WUWEBVIEW_API IWuWebView *createWuWebView(const char *wuid, const char *q
     return NULL;
 }
 
+const char *mimeTypeFromFileExt(const char *ext)
+{
+    if (!ext)
+        return "application/octet-stream";
+    if (*ext=='.')
+        ext++;
+    if (strieq(ext, "html") || strieq(ext, "htm"))
+        return "text/html";
+    if (strieq(ext, "xml") || strieq(ext, "xsl") || strieq(ext, "xslt"))
+       return "application/xml";
+    if (strieq(ext, "js"))
+       return "text/javascript";
+    if (strieq(ext, "css"))
+       return "text/css";
+    if (strieq(ext, "jpeg") || strieq(ext, "jpg"))
+       return "image/jpeg";
+    if (strieq(ext, "gif"))
+       return "image/gif";
+    if (strieq(ext, "png"))
+       return "image/png";
+    if (strieq(ext, "svg"))
+       return "image/svg+xml";
+    if (strieq(ext, "txt") || strieq(ext, "text"))
+       return "text/plain";
+    if (strieq(ext, "zip"))
+       return "application/zip";
+    if (strieq(ext, "pdf"))
+       return "application/pdf";
+    if (strieq(ext, "xpi"))
+       return "application/x-xpinstall";
+    if (strieq(ext, "exe") || strieq(ext, "class"))
+       return "application/octet-stream";
+    return "application/octet-stream";
+}
+
+extern WUWEBVIEW_API void getWuResourceByPath(const char *path, MemoryBuffer &mb, StringBuffer &mimetype)
+{
+    StringBuffer s, wuid, queryname;
+    nextPathNode(path, s);
+    if (strieq(s, "res"))
+        nextPathNode(path, s.clear());
+    if (strieq(s, "query"))
+    {
+        StringBuffer target;
+        nextPathNode(path, target);
+        if (!target.length())
+            throw MakeStringException(WUWEBERR_TargetNotFound, "Target cluster required");
+        nextPathNode(path, queryname);
+        Owned<IPropertyTree> query = resolveQueryAlias(target, queryname, true);
+        if (!query)
+            throw MakeStringException(WUWEBERR_QueryNotFound, "Query not found");
+        wuid.set(query->queryProp("@wuid"));
+    }
+    else
+    {
+        wuid.swapWith(s);
+        queryname.set(wuid);
+    }
+
+    Owned<IWuWebView> web = createWuWebView(wuid, queryname, NULL, true);
+    if (!web)
+        throw MakeStringException(WUWEBERR_WorkUnitNotFound, "Cannot open workunit");
+    mimetype.append(mimeTypeFromFileExt(strrchr(path, '.')));
+    if (!web->getResourceByPath(path, mb))
+        throw MakeStringException(WUWEBERR_ViewResourceNotFound, "Cannot open resource");
+}

+ 2 - 0
common/wuwebview/wuwebview.hpp

@@ -61,6 +61,8 @@ interface IWuWebView : extends IInterface
 extern WUWEBVIEW_API IWuWebView *createWuWebView(IConstWorkUnit &wu, const char *queryname, const char*dir, bool mapEspDir);
 extern WUWEBVIEW_API IWuWebView *createWuWebView(const char *wuid, const char *queryname, const char*dir, bool mapEspDir);
 
+extern WUWEBVIEW_API void getWuResourceByPath(const char *path, MemoryBuffer &mb, StringBuffer &mimetype);
+
 static inline bool isPathSeparator(char sep)
 {
     return (sep=='\\')||(sep=='/');

+ 12 - 0
esp/services/ws_ecl/ws_ecl_service.cpp

@@ -2683,6 +2683,18 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
             methodName.set("submit");
         }
 
+        if(strieq(methodName.str(), "res"))
+        {
+           MemoryBuffer mb;
+           StringBuffer mimetype;
+           getWuResourceByPath(thepath, mb, mimetype);
+
+           response->setContent(mb.length(), mb.toByteArray());
+           response->setContentType(mimetype.str());
+           response->setStatus(HTTP_STATUS_OK);
+           response->send();
+           return 0;
+        }
         if (!stricmp(methodName.str(), "tabview"))
         {
             return getWsEcl2TabView(request, response, thepath);

+ 4 - 9
esp/services/ws_workunits/ws_workunitsAuditLogs.cpp

@@ -1388,18 +1388,13 @@ int CWsWorkunitsSoapBindingEx::onGet(CHttpRequest* request, CHttpResponse* respo
          if(!strnicmp(path.str(), "/WsWorkunits/res/", strlen("/WsWorkunits/res/")))
          {
             const char *pos = path.str();
-            StringBuffer wuid;
-            nextPathNode(pos, wuid, 2);
-            Owned<IWuWebView> web = createWuWebView(wuid, wuid, getCFD(), true);
-            if (!web)
-                throw MakeStringException(ECLWATCH_CANNOT_OPEN_WORKUNIT, "Cannot open workunit");
+            skipPathNodes(pos, 1);
             MemoryBuffer mb;
-            StringAttr mimetype(mimeTypeFromFileExt(strrchr(pos, '.')));
-            if (!web->getResourceByPath(pos, mb))
-                throw MakeStringException(ECLWATCH_RESOURCE_NOT_FOUND, "Cannot open resource");
+            StringBuffer mimetype;
+            getWuResourceByPath(pos, mb, mimetype);
 
             response->setContent(mb.length(), mb.toByteArray());
-            response->setContentType(mimetype.get());
+            response->setContentType(mimetype.str());
             response->setStatus(HTTP_STATUS_OK);
             response->send();
             return 0;