Added properties file to WebAPI
authorEriks Jenkevics <eriks@netxms.org>
Wed, 3 May 2017 14:26:45 +0000 (17:26 +0300)
committerEriks Jenkevics <eriks@netxms.org>
Wed, 3 May 2017 14:26:45 +0000 (17:26 +0300)
src/server/nxapisrv/java/src/main/java/org/netxms/websvc/ApiProperties.java [new file with mode: 0644]
src/server/nxapisrv/java/src/main/java/org/netxms/websvc/handlers/AbstractHandler.java

diff --git a/src/server/nxapisrv/java/src/main/java/org/netxms/websvc/ApiProperties.java b/src/server/nxapisrv/java/src/main/java/org/netxms/websvc/ApiProperties.java
new file mode 100644 (file)
index 0000000..6cec78f
--- /dev/null
@@ -0,0 +1,50 @@
+package org.netxms.websvc;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class ApiProperties
+{
+   private Properties properties;
+   
+   /**
+    * Class for reading API properties file
+    */
+   public ApiProperties()
+   {
+      properties = new Properties();
+      InputStream in = null;
+      try
+      {
+         in = getClass().getResourceAsStream("/nxapisrv.properties"); //$NON-NLS-1$
+         if (in != null)
+            properties.load(in);
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if (in != null)
+         {
+            try
+            {
+               in.close();
+            }
+            catch(IOException e)
+            {
+            }
+         }
+      }
+   }
+   
+   /**
+    * @return the address of the NetXMS server
+    */
+   public String getNXServerAddress()
+   {
+      return properties.getProperty("NXServer", "127.0.0.1");
+   }
+}
\ No newline at end of file
index edd9936..a8747ef 100644 (file)
@@ -25,6 +25,7 @@ import org.json.JSONException;
 import org.json.JSONObject;
 import org.netxms.client.NXCSession;
 import org.netxms.client.constants.RCC;
+import org.netxms.websvc.ApiProperties;
 import org.netxms.websvc.SessionStore;
 import org.netxms.websvc.SessionToken;
 import org.netxms.websvc.WebSvcStatusService;
@@ -49,7 +50,8 @@ import com.google.gson.JsonObject;
  */
 public abstract class AbstractHandler extends ServerResource
 {
-   public static String serverAddress = "127.0.0.1";
+   static ApiProperties properties = new ApiProperties();
+   protected static String serverAddress = properties.getNXServerAddress();
    private Logger log = LoggerFactory.getLogger(AbstractHandler.class);
    private SessionToken sessionToken = null;
    private NXCSession session = null;