Jelajahi Sumber

HPCC-16891 Add implementation independent method to ISmartSocket interface

- ISmartSocket requires implementation of getUrlStr
- Esdl binding utilizes IsmartSocket::getUrlStr

Signed-off-by: Rodrigo Pastrana <rodrigo.pastrana@lexisnexis.com>
Rodrigo Pastrana 8 tahun lalu
induk
melakukan
fccfbcbc5d

+ 3 - 12
esp/services/esdl_svc_engine/esdl_binding.cpp

@@ -432,7 +432,7 @@ void EsdlServiceImpl::configureUrlMethod(const char *method, IPropertyTree &entr
     entry.setProp("@prot", protocol);
     entry.setProp("@path", path);
 
-    Owned<ISmartSocketFactory> sf = new CSmartSocketFactory(iplist, true);
+    Owned<ISmartSocketFactory> sf = createSmartSocketFactory(iplist, true);
 
     connMap.remove(method);
     connMap.setValue(method, sf.getClear());
@@ -869,7 +869,7 @@ void EsdlServiceImpl::generateTargetURL(IEspContext & context,
 
     StringBuffer name(srvinfo->queryProp("@name"));
 
-    CSmartSocketFactory *sconn = static_cast<CSmartSocketFactory*>(connMap.getValue(name));
+    ISmartSocketFactory *sconn = connMap.getValue(name);
     if (!sconn)
         throw MakeStringException(-1, "Could not create smartsocket.");
 
@@ -878,16 +878,7 @@ void EsdlServiceImpl::generateTargetURL(IEspContext & context,
         url.append("HTTP");
     url.append("://");
 
-    SmartSocketEndpoint * sep = sconn->nextSmartEndpoint();
-    SocketEndpoint ep = sep->ep;
-    if (sep->name.length())
-    {
-        url.append(sep->name.str());
-        if (ep.port)
-            url.append(':').append((unsigned)ep.port);
-    }
-    else
-        ep.getUrlStr(url);
+    sconn->getUrlStr(url, true, -1);
 
     if(srvinfo->hasProp("@path"))  //Append the server path
     {

+ 28 - 0
system/jlib/jsmartsock.cpp

@@ -428,6 +428,34 @@ void CSmartSocketFactory::setStatus(SocketEndpoint &ep, bool status)
         ss->status=status;
 }
 
+StringBuffer & CSmartSocketFactory::getUrlStr(StringBuffer &url, bool useHostName, unsigned dnsIntervalSecs)
+{
+	SmartSocketEndpoint * sep = nextSmartEndpoint();
+	if (sep)
+	{
+		SocketEndpoint ep;
+
+		if(useHostName)
+		{
+			ep = sep->ep;
+			if (sep->name.length())
+			{
+				url.append(sep->name.str());
+				if (ep.port)
+					url.append(':').append((unsigned)ep.port);
+			}
+			else
+				ep.getUrlStr(url);
+		}
+		else
+		{
+			sep->checkHost(dnsInterval);
+			ep = sep->ep;
+			ep.getUrlStr(url);
+		}
+	}
+	return url;
+}
 
 ISmartSocketFactory *createSmartSocketFactory(const char *_socklist, bool _retry, unsigned _retryInterval, unsigned _dnsInterval) {
     return new CSmartSocketFactory(_socklist, _retry, _retryInterval, _dnsInterval);

+ 2 - 0
system/jlib/jsmartsock.hpp

@@ -57,6 +57,8 @@ interface jlib_decl ISmartSocketFactory : extends IInterface
     virtual void stop() = 0;
 
     virtual void resolveHostnames() = 0;
+
+    virtual StringBuffer & getUrlStr(StringBuffer &str, bool useHostName, unsigned dnsIntervalSecs) = 0;
 };
 
 

+ 2 - 0
system/jlib/jsmartsock.ipp

@@ -94,6 +94,8 @@ public:
     virtual void stop();
 
     virtual void resolveHostnames();
+
+    virtual StringBuffer & getUrlStr(StringBuffer &str, bool useHostName, unsigned dnsIntervalSecs);
 };