Add fix for host lookup during NodeConf fetch 25/62925/2
authorFiachra Corcoran <fiachra.corcoran@ericsson.com>
Sun, 26 Aug 2018 13:52:16 +0000 (14:52 +0100)
committerFiachra Corcoran <fiachra.corcoran@ericsson.com>
Sun, 26 Aug 2018 14:45:01 +0000 (15:45 +0100)
Issue-ID: DMAAP-107
Change-Id: I8322db5da1cb5bab4552954d624d33ec967e95bd
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@ericsson.com>
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
datarouter-prov/src/main/resources/provserver.properties
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java

index 7e3b4bf..35ba095 100644 (file)
@@ -24,6 +24,8 @@
 
 package org.onap.dmaap.datarouter.node;
 
+import org.apache.log4j.Logger;
+
 import java.util.*;
 import java.net.*;
 
@@ -34,6 +36,7 @@ public class IsFrom {
     private long nextcheck;
     private String[] ips;
     private String fqdn;
+    private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.IsFrom");
 
     /**
      * Configure the JVM DNS cache to have a 10 second TTL.  This needs to be called very very early or it won't have any effect.
@@ -59,18 +62,20 @@ public class IsFrom {
         long now = System.currentTimeMillis();
         if (now > nextcheck) {
             nextcheck = now + 10000;
-            Vector<String> v = new Vector<String>();
+            Vector<String> v = new Vector<>();
             try {
                 InetAddress[] addrs = InetAddress.getAllByName(fqdn);
                 for (InetAddress a : addrs) {
                     v.add(a.getHostAddress());
                 }
-            } catch (Exception e) {
+            } catch (UnknownHostException e) {
+                logger.debug("IsFrom: UnknownHostEx: " + e.toString(), e);
             }
             ips = v.toArray(new String[v.size()]);
+            logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips));
         }
         for (String s : ips) {
-            if (s.equals(ip)) {
+            if (s.equals(ip) || s.equals(System.getenv("DMAAP_DR_PROV_SERVICE_HOST"))) {
                 return (true);
             }
         }
index 6ed5d8b..412e132 100644 (file)
@@ -273,7 +273,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         try {
             thishost = InetAddress.getLocalHost();
             loopback = InetAddress.getLoopbackAddress();
-            checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
+            //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
         } catch (UnknownHostException e) {
             // ignore
         }
@@ -575,7 +575,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     private void checkHttpsRelaxation() {
         if (!mailSendFlag) {
             Properties p = (new DB()).getProperties();
-            intlogger.info("HTTPS relaxatio: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
+            intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
 
             if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
                 try {
index 10bb5eb..383bce3 100644 (file)
@@ -24,7 +24,7 @@
 #Jetty Server properties
 org.onap.dmaap.datarouter.provserver.http.port           = 8080
 org.onap.dmaap.datarouter.provserver.https.port          = 8443
-org.onap.dmaap.datarouter.provserver.https.relaxation    = false
+org.onap.dmaap.datarouter.provserver.https.relaxation    = true
 
 org.onap.dmaap.datarouter.provserver.keystore.type       = jks
 org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
index 10bb5eb..383bce3 100644 (file)
@@ -24,7 +24,7 @@
 #Jetty Server properties
 org.onap.dmaap.datarouter.provserver.http.port           = 8080
 org.onap.dmaap.datarouter.provserver.https.port          = 8443
-org.onap.dmaap.datarouter.provserver.https.relaxation    = false
+org.onap.dmaap.datarouter.provserver.https.relaxation    = true
 
 org.onap.dmaap.datarouter.provserver.keystore.type       = jks
 org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
index c663451..eea213f 100644 (file)
@@ -201,6 +201,7 @@ public class SubscribeServletTest extends DrServletTestBase {
     public void Given_Request_Is_HTTP_POST_And_POST_Fails_Bad_Request_Response_Is_Generated() throws Exception {
         PowerMockito.mockStatic(Subscription.class);
         PowerMockito.when(Subscription.getSubscriptionMatching(mock(Subscription.class))).thenReturn(null);
+        PowerMockito.when(Subscription.countActiveSubscriptions()).thenReturn(0);
         JSONObject JSObject = buildRequestJsonObject();
         SubscribeServlet subscribeServlet = new SubscribeServlet() {
             protected JSONObject getJSONfromInput(HttpServletRequest req) {