Xacml PDP Register/Unregister Changes
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / rest / XacmlPdpRestServer.java
index 3a3992f..f7f6cc3 100644 (file)
 
 package org.onap.policy.pdpx.main.rest;
 
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+
 import org.onap.policy.common.capabilities.Startable;
 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
 import org.onap.policy.pdpx.main.parameters.RestServerParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,14 +45,16 @@ public class XacmlPdpRestServer implements Startable {
     private List<HttpServletServer> servers = new ArrayList<>();
 
     private RestServerParameters restServerParameters;
+    private String applicationPath;
 
     /**
      * Constructor for instantiating XacmlPdpRestServer.
      *
      * @param restServerParameters the rest server parameters
      */
-    public XacmlPdpRestServer(final RestServerParameters restServerParameters) {
+    public XacmlPdpRestServer(final RestServerParameters restServerParameters, final String applicationPath) {
         this.restServerParameters = restServerParameters;
+        this.applicationPath = applicationPath;
     }
 
     /**
@@ -58,8 +63,27 @@ public class XacmlPdpRestServer implements Startable {
     @Override
     public boolean start() {
         try {
+            //
+            // Initialize the applications - SEND PROPERTIES
+            //
+            XacmlPdpApplicationManager.initializeApplications(Paths.get(applicationPath));
+
+            //
+            // Update statistics manager on the policy types
+            //
+            XacmlPdpStatisticsManager.setTotalPolicyTypesCount(XacmlPdpApplicationManager.getPolicyTypeCount());
+
+            //
+            // Get the server properties
+            //
             servers = HttpServletServer.factory.build(getServerProperties());
+            //
+            // Start all the servers
+            //
             for (final HttpServletServer server : servers) {
+                if (server.isAaf()) {
+                    server.addFilterClass(null, XacmlPdpAafFilter.class.getCanonicalName());
+                }
                 server.start();
             }
         } catch (final Exception exp) {
@@ -89,6 +113,12 @@ public class XacmlPdpRestServer implements Startable {
                 restServerParameters.getUserName());
         props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".password",
                 restServerParameters.getPassword());
+        props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".https",
+                String.valueOf(restServerParameters.isHttps()));
+        props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".aaf",
+                String.valueOf(restServerParameters.isAaf()));
+        props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".serialization.provider",
+                GsonMessageBodyHandler.class.getName());
         return props;
     }
 
@@ -99,7 +129,7 @@ public class XacmlPdpRestServer implements Startable {
     public boolean stop() {
         for (final HttpServletServer server : servers) {
             try {
-                server.stop();
+                server.shutdown();
             } catch (final Exception exp) {
                 LOGGER.error("Failed to stop xacml pdp http server", exp);
             }