Browse Source

HPCC-17508 Automatically add Ping method to all ESP services

- Adds onPing to all static ESP service interface
- Adds handleOnPing to all dynamic ESP engine
- Adds support for ping_min_ver service attribute
- Implements onPing automatically. Returns empty response
- Adds json response support

Signed-off-by: Rodrigo Pastrana <rodrigo.pastrana@lexisnexis.com>
Rodrigo Pastrana 7 years ago
parent
commit
88d25647ed

+ 23 - 5
esp/services/esdl_svc_engine/esdl_binding.cpp

@@ -584,7 +584,13 @@ void EsdlServiceImpl::handleServiceRequest(IEspContext &context,
 
     if(stricmp(mthName, "echotest")==0 || mthdef.hasProp("EchoTest"))
     {
-        handleEchoTest(mthdef.queryName(),req,out,flags);
+        handleEchoTest(mthdef.queryName(),req,out,context.getResponseFormat());
+        return;
+    }
+    else if
+    (stricmp(mthName, "ping")==0 || mthdef.hasProp("Ping"))
+    {
+        handlePingRequest(mthdef.queryName(),out,context.getResponseFormat());
         return;
     }
     else
@@ -897,16 +903,24 @@ void EsdlServiceImpl::handleFinalRequest(IEspContext &context,
 void EsdlServiceImpl::handleEchoTest(const char *mthName,
                                      IPropertyTree *req,
                                      StringBuffer &out,
-                                     unsigned flags)
+                                     ESPSerializationFormat format)
 {
     const char* valueIn = req->queryProp("ValueIn");
 
-    if (flags & ESDL_BINDING_RESPONSE_JSON)
-        out.appendf("\n\t\"%sResponse\":\n{\t\t\"ValueOut\": \"%s\"\n\t\t}\n\t", mthName, valueIn && *valueIn ? valueIn : "");
+    if (format == ESPSerializationJSON)
+        out.appendf("{\n\t\"%sResponse\":\n{\t\t\"ValueOut\": \"%s\"\n\t\t}\n}", mthName, valueIn && *valueIn ? valueIn : "");
     else
         out.appendf("<%sResponse><ValueOut>%s</ValueOut></%sResponse>", mthName, valueIn && *valueIn ? valueIn : "", mthName);
 }
 
+void EsdlServiceImpl::handlePingRequest(const char *mthName,StringBuffer &out,ESPSerializationFormat format)
+{
+    if (format == ESPSerializationJSON)
+        out.appendf("{\"%sPingResponse\": {}}", mthName);
+    else
+        out.appendf("<%sResponse></%sResponse>", mthName, mthName);
+}
+
 void EsdlServiceImpl::generateTargetURL(IEspContext & context,
                                      IPropertyTree *srvinfo,
                                      StringBuffer & url,
@@ -1411,7 +1425,11 @@ int EsdlBindingImpl::onGetInstantQuery(IEspContext &context,
                     m_pESDLService->handleServiceRequest(context, *srvdef, *mthdef, tgtcfg, tgtctx, ns.str(), schemaLocation.str(), req_pt.get(), out, logdata, 0);
 
                     response->setContent(out.str());
-                    response->setContentType(HTTP_TYPE_TEXT_XML_UTF8);
+
+                    if (context.getResponseFormat() == ESPSerializationJSON)
+                        response->setContentType(HTTP_TYPE_APPLICATION_JSON_UTF8);
+                    else
+                      response->setContentType(HTTP_TYPE_TEXT_XML_UTF8);
                     response->setStatus(HTTP_STATUS_OK);
                     response->send();
 

+ 2 - 1
esp/services/esdl_svc_engine/esdl_binding.hpp

@@ -167,7 +167,8 @@ public:
     virtual void processResponse(IEspContext &context, IEsdlDefService &srvdef, IEsdlDefMethod &mthdef, const char *ns, StringBuffer &resp) {};
     virtual void createServersList(IEspContext &context, IEsdlDefService &srvdef, IEsdlDefMethod &mthdef, StringBuffer &servers) {};
     virtual bool handleResultLogging(IEspContext &espcontext, IPropertyTree * reqcontext, IPropertyTree * request,  const char * rawresp, const char * finalresp, const char * logdata);
-    void handleEchoTest(const char *mthName, IPropertyTree *req, StringBuffer &soapResp, unsigned flags=0);
+    void handleEchoTest(const char *mthName, IPropertyTree *req, StringBuffer &soapResp, ESPSerializationFormat format);
+    void handlePingRequest(const char *mthName,StringBuffer &out,ESPSerializationFormat format);
     virtual void handleFinalRequest(IEspContext &context, Owned<IPropertyTree> &tgtcfg, Owned<IPropertyTree> &tgtctx, IEsdlDefService &srvdef, IEsdlDefMethod &mthdef, const char *ns, StringBuffer& req, StringBuffer &out, bool isroxie, bool isproxy);
     void getSoapBody(StringBuffer& out,StringBuffer& soapresp);
     void getSoapError(StringBuffer& out,StringBuffer& soapresp,const char *,const char *);

+ 54 - 1
tools/esdlcomp/esdlgram.y

@@ -188,7 +188,60 @@ EspServiceStart
  : ESPSERVICE EspMetaData ID
  {
     CurService=new EspServInfo($3.getName());
-    CurService->tags = getClearCurMetaTags();
+    if (CurService)
+    {
+        CurService->tags = getClearCurMetaTags();
+
+        StringBuffer minPingVer;
+        for (MetaTagInfo* t = CurService->tags; t!=NULL; t = t->next)
+        {
+            if (streq("ping_min_ver",t->getName()))
+            {
+                minPingVer.set(t->getString());
+                break;
+            }
+        }
+
+        VStringBuffer reqname("%sPingRequest", $3.getName());
+        CurEspMessage = new EspMessageInfo(reqname.str(), EspMessageInfo::espm_request);
+
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            CurEspMessage->tags = getClearCurMetaTags();
+         }
+
+        AddEspMessage();
+        CurEspMessage=NULL;
+
+        VStringBuffer respname("%sPingResponse", $3.getName());
+        CurEspMessage = new EspMessageInfo(respname.str(), EspMessageInfo::espm_response);
+
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            CurEspMessage->tags = getClearCurMetaTags();
+         }
+
+        AddEspMessage();
+
+        EspMethodInfo *method=new EspMethodInfo("Ping", reqname.str(), respname.str());
+
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            method->tags = getClearCurMetaTags();
+         }
+
+        method->next=CurService->methods;
+        CurService->methods=method;
+
+        CurMetaTags   = NULL;
+        CurEspMessage = NULL;
+    }
  }
  ;
 

+ 16 - 8
tools/hidl/hidlcomp.cpp

@@ -3272,7 +3272,6 @@ void EspMessageInfo::write_esp_ipp()
     
     outs("\n");
     write_esp_methods(espaxm_both, true, false);
-    
     outs("};\n\n");
 }
 
@@ -6379,18 +6378,27 @@ void EspServInfo::write_esp_service_ipp()
     outs("\tvirtual IEspContainer *queryContainer()\n\t{\n\t\treturn m_container;\n\t}\n");
     
     outf("\tvirtual const char* getServiceType(){return \"%s\";}\n\n", name_);
-    
+
     EspMethodInfo *mthi;
     for (mthi=methods;mthi!=NULL;mthi=mthi->next)
     {
         bool stubbed = (findMetaTag(mthi->tags,"stubbed")!=NULL);
-
-        outf(1, "%sbool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n", (stubbed) ? "" : "//", mthi->getName(), mthi->getReq(), mthi->getResp());
-        outf(1, "%s{\n", (stubbed) ? "" : "//");
-        outf(2, "%sreturn false;\n", (stubbed) ? "" : "//");
-        outf(1, "%s}\n", (stubbed) ? "" : "//");
+        if (streq(mthi->getName(), "Ping")) //We'll implement the onPing automatically for all ESP Services.
+        {
+            outf(1, "bool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n",  mthi->getName(), mthi->getReq(), mthi->getResp());
+            outs(1, "{\n");
+            outs(2, "return true;\n");
+            outs(1, "}\n");
+        }
+        else
+        {
+            outf(1, "%sbool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n", (stubbed) ? "" : "//", mthi->getName(), mthi->getReq(), mthi->getResp());
+            outf(1, "%s{\n", (stubbed) ? "" : "//");
+            outf(2, "%sreturn false;\n", (stubbed) ? "" : "//");
+            outf(1, "%s}\n", (stubbed) ? "" : "//");
+        }
     }
-    
+
     outs("};\n\n");
 }
 

+ 56 - 2
tools/hidl/hidlgram.y

@@ -191,13 +191,67 @@ EspServiceStart
  : ESPSERVICE EspMetaData ID
  {
     CurService=new EspServInfo($3.getName());
-    CurService->tags = getClearCurMetaTags();
+    if (CurService)
+    {
+        CurService->tags = getClearCurMetaTags();
+
+        StrBuffer minPingVer;
+        for (MetaTagInfo* t = CurService->tags; t!=NULL; t = t->next)
+        {
+            if (streq("ping_min_ver",t->getName()))
+            {
+                minPingVer.set(t->getString());
+                break;
+            }
+        }
+
+        VStrBuffer reqname("%sPingRequest", $3.getName());
+        CurEspMessage = new EspMessageInfo(reqname.str(), EspMessageInfo::espm_request);
+        CurEspMessage->write_cpp_interfaces();
+
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            CurEspMessage->tags = getClearCurMetaTags();
+         }
+
+        AddEspMessage();
+        CurEspMessage=NULL;
+
+        VStrBuffer respname("%sPingResponse", $3.getName());
+        CurEspMessage = new EspMessageInfo(respname.str(), EspMessageInfo::espm_response);
+        CurEspMessage->write_cpp_interfaces();
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            CurEspMessage->tags = getClearCurMetaTags();
+         }
+
+        AddEspMessage();
+
+        EspMethodInfo *method=new EspMethodInfo("Ping", reqname.str(), respname.str());
+
+        if(minPingVer.length()!=0)
+        {
+            CurMetaTags = NULL;
+            AddMetaTag(new MetaTagInfo("min_ver", minPingVer.str()));
+            method->tags = getClearCurMetaTags();
+         }
+
+        method->next=CurService->methods;
+        CurService->methods=method;
+
+        CurMetaTags   = NULL;
+        CurEspMessage = NULL;
+    }
  }
  ;
 
 EspServiceBody
  : '{' EspServiceEntryList '}' 
- | '{' '}' 
+ | '{' '}'
  ;
 
 EspServiceEntryList