]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Adding system property support for starting SCL REST server on startup 14/1014/2
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 22 Sep 2017 07:30:52 +0000 (10:30 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Fri, 22 Sep 2017 07:32:09 +0000 (10:32 +0300)
refs #7374

Change-Id: I4d961a547ccf5101fd36846c4deddda4c20048b9

bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/Activator.java

index 4f90e690089c91094484602f303ec1eb809eefaf..b7cf316893447fdd6a0994474372f2a57e68c279 100644 (file)
@@ -2,9 +2,15 @@ package org.simantics.scl.rest;
 
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Activator implements BundleActivator {
 
+    public static final String START_SERVER = "org.simantics.scl.rest.startServer";
+    
+    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+    
     private static BundleContext context;
 
     static BundleContext getContext() {
@@ -18,6 +24,15 @@ public class Activator implements BundleActivator {
      * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
     public void start(BundleContext bundleContext) throws Exception {
+        String onStartup = System.getProperty(START_SERVER);
+        if (onStartup != null && !onStartup.isEmpty()) {
+            try {
+                String[] tokenAndPort = onStartup.split("::");
+                SCLRESTServer.start(tokenAndPort[0], Integer.parseInt(tokenAndPort[1]));
+            } catch (Exception e) {
+                LOGGER.error("Could not start server with value {}. It should be in the form of <secret-token>::<port-number>", onStartup, e);
+            }
+        }
         Activator.context = bundleContext;
     }