LP1825891 Hatch 'hostname' command user/berick/lp1825891-hatch-hostname
authorBill Erickson <berickxx@gmail.com>
Wed, 17 Apr 2019 20:22:56 +0000 (16:22 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 22 Apr 2019 20:44:19 +0000 (16:44 -0400)
Returns the hostname as reported by Java:

InetAddress.getLocalHost().getHostName();

Includes hostname request in TestJava program.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/org/evergreen_ils/hatch/RequestHandler.java
src/org/evergreen_ils/hatch/TestHatch.java

index 400e02c..22947cf 100644 (file)
@@ -18,6 +18,8 @@ package org.evergreen_ils.hatch;
 import org.json.*;
 import java.io.File;
 import java.util.logging.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 /**
  * Dispatches requests received via MessageIO, sends responses back 
@@ -163,6 +165,16 @@ public class RequestHandler extends Thread {
                 }
                 break;
 
+            case "hostname":
+                try {
+                    String hostname = InetAddress.getLocalHost().getHostName();
+                    response.put("content", hostname);
+                } catch (UnknownHostException e) {
+                    response.put("status", 500);
+                    response.put("message", "Cannot determine hostname " + e);
+                }
+                break;
+
             default:
                 response.put("status", 404); 
                 response.put("message", "Action not found: " + action);
index ee85154..1f9ca79 100644 (file)
@@ -120,6 +120,17 @@ public class TestHatch {
 
         pause();
 
+        // get the hostname
+        obj = new JSONObject();
+        obj.put("msgid", msgid++);
+        obj.put("clientid", clientid);
+        obj.put("origin", origin);
+        obj.put("action", "hostname");
+        io.sendMessage(obj);
+
+        pause();
+
+
         /*
         // Printing tests