|
@@ -1744,19 +1744,16 @@ void CWsEclBinding::getWsEcl2XmlRequest(StringBuffer& soapmsg, IEspContext &cont
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-StringBuffer &appendJSONException(StringBuffer &s, IException *e, const char *objname="Exceptions", const char *arrayName = "Exception")
|
|
|
+StringBuffer &appendJSONExceptionItem(StringBuffer &s, int code, const char *msg, const char *objname="Exceptions", const char *arrayName = "Exception")
|
|
|
{
|
|
|
- if (!e)
|
|
|
- return s;
|
|
|
if (objname && *objname)
|
|
|
appendJSONName(s, objname).append('{');
|
|
|
if (arrayName && *arrayName)
|
|
|
appendJSONName(s, arrayName).append('[');
|
|
|
delimitJSON(s);
|
|
|
s.append('{');
|
|
|
- appendJSONValue(s, "Code", e->errorCode());
|
|
|
- StringBuffer temp;
|
|
|
- appendJSONValue(s, "Message", e->errorMessage(temp).str());
|
|
|
+ appendJSONValue(s, "Code", code);
|
|
|
+ appendJSONValue(s, "Message", msg);
|
|
|
s.append('}');
|
|
|
if (arrayName && *arrayName)
|
|
|
s.append(']');
|
|
@@ -1765,6 +1762,14 @@ StringBuffer &appendJSONException(StringBuffer &s, IException *e, const char *ob
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
+StringBuffer &appendJSONException(StringBuffer &s, IException *e, const char *objname="Exceptions", const char *arrayName = "Exception")
|
|
|
+{
|
|
|
+ if (!e)
|
|
|
+ return s;
|
|
|
+ StringBuffer temp;
|
|
|
+ return appendJSONExceptionItem(s, e->errorCode(), e->errorMessage(temp).str(), objname, arrayName);
|
|
|
+}
|
|
|
+
|
|
|
StringBuffer &appendJSONExceptions(StringBuffer &s, IMultiException *e, const char *objname="Exceptions", const char *arrayName = "Exception")
|
|
|
{
|
|
|
if (!e)
|
|
@@ -1830,29 +1835,29 @@ void CWsEclBinding::getWsEclJsonResponse(StringBuffer& jsonmsg, IEspContext &con
|
|
|
element.append(wsinfo.queryname.sget());
|
|
|
element.append("Response");
|
|
|
|
|
|
- VStringBuffer xpath("Body/%s/Results/Result/Exception", element.str());
|
|
|
- Owned<IPropertyTreeIterator> exceptions = parmtree->getElements(xpath.str());
|
|
|
+ IPropertyTree *node = parmtree;
|
|
|
+ if (node->hasProp("Body"))
|
|
|
+ node = node->queryPropTree("Body");
|
|
|
+ if (node->hasProp(element))
|
|
|
+ node = node->queryPropTree(element);
|
|
|
+ if (node->hasProp("Results"))
|
|
|
+ node = node->queryPropTree("Results");
|
|
|
+ if (node->hasProp("Result"))
|
|
|
+ node = node->queryPropTree("Result");
|
|
|
|
|
|
jsonmsg.appendf("{\n \"%s\": {\n \"Results\": {\n", element.str());
|
|
|
|
|
|
+ Owned<IPropertyTreeIterator> exceptions = node->getElements("Exception");
|
|
|
if (exceptions && exceptions->first())
|
|
|
{
|
|
|
- jsonmsg.append(" \"Exceptions\": {\n \"Exception\": [\n");
|
|
|
- bool first=true;
|
|
|
+ appendJSONName(jsonmsg.pad(3), "Exceptions").append("{\n");
|
|
|
+ appendJSONName(jsonmsg.pad(4), "Exception").append("[\n");
|
|
|
ForEach(*exceptions)
|
|
|
- {
|
|
|
- if (first)
|
|
|
- first=false;
|
|
|
- else
|
|
|
- jsonmsg.append(",\n");
|
|
|
- jsonmsg.appendf(" {\n \"Code\": %d,\n \"Message\": \"%s\"\n }", exceptions->query().getPropInt("Code"), exceptions->query().queryProp("Message"));
|
|
|
- }
|
|
|
- jsonmsg.append("\n ]\n }\n");
|
|
|
+ appendJSONExceptionItem(jsonmsg.pad(2), exceptions->query().getPropInt("Code"), exceptions->query().queryProp("Message"), NULL, NULL);
|
|
|
+ jsonmsg.append("\n ]\n }\n");
|
|
|
}
|
|
|
|
|
|
- xpath.clear().append("Body/*[1]/Results/Result/Dataset");
|
|
|
- Owned<IPropertyTreeIterator> datasets = parmtree->getElements(xpath.str());
|
|
|
-
|
|
|
+ Owned<IPropertyTreeIterator> datasets = node->getElements("Dataset");
|
|
|
ForEach(*datasets)
|
|
|
{
|
|
|
IPropertyTree &ds = datasets->query();
|
|
@@ -1878,7 +1883,6 @@ void CWsEclBinding::getWsEclJsonResponse(StringBuffer& jsonmsg, IEspContext &con
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
jsonmsg.append(" }\n }\n}");
|
|
|
}
|
|
|
catch (IException *e)
|
|
@@ -2382,8 +2386,10 @@ void CWsEclBinding::sendRoxieRequest(const char *target, StringBuffer &req, Stri
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int CWsEclBinding::onSubmitQueryOutputXML(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, const char *format)
|
|
|
+int CWsEclBinding::onSubmitQueryOutput(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, const char *format)
|
|
|
{
|
|
|
+ bool outputJSON = !format ? false : strieq(format, "json");
|
|
|
+
|
|
|
StringBuffer soapmsg;
|
|
|
|
|
|
getSoapMessage(soapmsg, context, request, wsinfo, REQXML_TRIM|REQXML_ROOT);
|
|
@@ -2407,17 +2413,28 @@ int CWsEclBinding::onSubmitQueryOutputXML(IEspContext &context, CHttpRequest* re
|
|
|
StringBuffer roxieresp;
|
|
|
sendRoxieRequest(wsinfo.qsetname.get(), soapmsg, roxieresp, status, wsinfo.queryname);
|
|
|
|
|
|
- Owned<IWuWebView> web = createWuWebView(*wsinfo.wu, wsinfo.queryname.get(), getCFD(), true);
|
|
|
- if (web.get())
|
|
|
- web->expandResults(roxieresp.str(), output, xmlflags);
|
|
|
+ if (outputJSON)
|
|
|
+ getWsEclJsonResponse(output, context, request, roxieresp.str(), wsinfo);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Owned<IWuWebView> web = createWuWebView(*wsinfo.wu, wsinfo.queryname.get(), getCFD(), true);
|
|
|
+ if (web.get())
|
|
|
+ web->expandResults(roxieresp.str(), output, xmlflags);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
submitWsEclWorkunit(context, wsinfo, soapmsg.str(), output, xmlflags);
|
|
|
+ if (outputJSON)
|
|
|
+ {
|
|
|
+ StringBuffer jsonresp;
|
|
|
+ getWsEclJsonResponse(jsonresp, context, request, output.str(), wsinfo);
|
|
|
+ output.swapWith(jsonresp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
response->setContent(output.str());
|
|
|
- response->setContentType(HTTP_TYPE_APPLICATION_XML);
|
|
|
+ response->setContentType(outputJSON ? "application/json" : "application/xml");
|
|
|
response->setStatus("200 OK");
|
|
|
response->send();
|
|
|
|
|
@@ -2725,7 +2742,7 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
|
|
|
nextPathNode(thepath, format);
|
|
|
|
|
|
WsEclWuInfo wsinfo(wuid.str(), qs.str(), qid.str(), context->queryUserId(), context->queryPassword());
|
|
|
- return onSubmitQueryOutputXML(*context, request, response, wsinfo, format.str());
|
|
|
+ return onSubmitQueryOutput(*context, request, response, wsinfo, format.str());
|
|
|
}
|
|
|
else if (!stricmp(methodName.str(), "xslt"))
|
|
|
{
|