ソースを参照

Merge pull request #5050 from afishbeck/wsecl_jsonp10276

HPCC-10276 Add jsonp support to WsEcl

Reviewed-By: Gordon Smith <gordon.smith@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 年 前
コミット
f98f5fd49e
1 ファイル変更15 行追加0 行削除
  1. 15 0
      esp/services/ws_ecl/ws_ecl_service.cpp

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

@@ -1839,6 +1839,7 @@ void CWsEclBinding::getWsEclJsonRequest(StringBuffer& jsonmsg, IEspContext &cont
 void CWsEclBinding::getWsEclJsonResponse(StringBuffer& jsonmsg, IEspContext &context, CHttpRequest *request, const char *xml, WsEclWuInfo &wsinfo)
 {
     size32_t start = jsonmsg.length();
+    const char *jsonp = context.queryRequestParameters()->queryProp("jsonp");
     try
     {
         Owned<IPropertyTree> parmtree = createPTreeFromXMLString(xml, ipt_none, (PTreeReaderOptions)(ptr_ignoreWhiteSpace|ptr_ignoreNameSpaces));
@@ -1858,6 +1859,9 @@ void CWsEclBinding::getWsEclJsonResponse(StringBuffer& jsonmsg, IEspContext &con
         if (node->hasProp("Result"))
             node = node->queryPropTree("Result");
 
+        if (jsonp && *jsonp)
+            jsonmsg.append(jsonp).append('(');
+
         jsonmsg.appendf("{\"%s\": {", element.str());
         Owned<IPropertyTreeIterator> exceptions = node->getElements("Exception");
         Owned<IPropertyTreeIterator> datasets = node->getElements("Dataset");
@@ -1905,12 +1909,18 @@ void CWsEclBinding::getWsEclJsonResponse(StringBuffer& jsonmsg, IEspContext &con
             }
         }
         jsonmsg.append("}}}");
+        if (jsonp && *jsonp)
+            jsonmsg.append(");");
     }
     catch (IException *e)
     {
         jsonmsg.setLength(start);
+        if (jsonp && *jsonp)
+            jsonmsg.append(jsonp).append('(');
         appendJSONException(jsonmsg.append('{'), e);
         jsonmsg.append('}');
+        if (jsonp && *jsonp)
+            jsonmsg.append(");");
     }
 }
 
@@ -2890,7 +2900,12 @@ void CWsEclBinding::handleJSONPost(CHttpRequest *request, CHttpResponse *respons
             StringBuffer output;
             if (getEspLogLevel()>LogNormal)
                 DBGLOG("roxie json req: %s", content.str());
+            const char *jsonp = ctx->queryRequestParameters()->queryProp("jsonp");
+            if (jsonp && *jsonp)
+                jsonresp.append(jsonp).append('(');
             sendRoxieRequest(queryset.str(), content, jsonresp, status, queryname.str(), "application/json");
+            if (jsonp && *jsonp)
+                jsonresp.append(");");
             if (getEspLogLevel()>LogNormal)
                 DBGLOG("roxie json resp: %s", jsonresp.str());
         }