summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java159
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java21
2 files changed, 9 insertions, 171 deletions
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java
deleted file mode 100644
index a6213da2..00000000
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pdpx.main.rest;
-
-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.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class to manage life cycle of xacml pdp rest server.
- *
- */
-public class XacmlPdpRestServer implements Startable {
-
- private static final String SEPARATOR = ".";
- private static final String HTTP_SERVER_SERVICES = "http.server.services";
- private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpRestServer.class);
-
- private List<HttpServletServer> servers = new ArrayList<>();
-
- private final RestServerParameters restServerParameters;
-
- /**
- * Constructor for instantiating XacmlPdpRestServer.
- *
- * @param restServerParameters the rest server parameters
- */
- public XacmlPdpRestServer(final RestServerParameters restServerParameters) {
- this.restServerParameters = restServerParameters;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean start() {
- try {
- LOGGER.info("Starting XacmlPdpRestServer...");
-
- //
- // Get the server properties
- //
- servers = HttpServletServerFactoryInstance.getServerFactory().build(getServerProperties());
- //
- // Start all the servers
- //
- for (final HttpServletServer server : servers) {
- if (server.isAaf()) {
- server.addFilterClass(null, XacmlPdpAafFilter.class.getName());
- }
- server.start();
- }
- LOGGER.info("servers are started");
- } catch (final Exception exp) {
- LOGGER.error("Failed to start xacml pdp http server", exp);
- return false;
- }
- return true;
- }
-
- /**
- * Creates the server properties object using restServerParameters.
- *
- * @return the properties object
- */
- private Properties getServerProperties() {
- final Properties props = new Properties();
- props.setProperty(HTTP_SERVER_SERVICES, restServerParameters.getName());
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".host",
- restServerParameters.getHost());
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".port",
- Integer.toString(restServerParameters.getPort()));
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".restClasses",
- XacmlPdpRestController.class.getName());
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".managed", "false");
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".swagger", "true");
- props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".userName",
- 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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean stop() {
- for (final HttpServletServer server : servers) {
- try {
- server.shutdown();
- } catch (final Exception exp) {
- LOGGER.error("Failed to stop xacml pdp http server", exp);
- }
- }
- return true;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void shutdown() {
- stop();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public boolean isAlive() {
- return !servers.isEmpty();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("XacmlPdpRestServer [servers=");
- builder.append(servers);
- builder.append("]");
- return builder.toString();
- }
-
-}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
index eb3ac230..70253c09 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
@@ -29,6 +29,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
+import org.onap.policy.common.endpoints.http.server.RestServer;
import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
@@ -40,8 +41,9 @@ import org.onap.policy.pdpx.main.comm.XacmlPdpHearbeatPublisher;
import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpStateChangeListener;
import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpUpdateListener;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
+import org.onap.policy.pdpx.main.rest.XacmlPdpAafFilter;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
-import org.onap.policy.pdpx.main.rest.XacmlPdpRestServer;
+import org.onap.policy.pdpx.main.rest.XacmlPdpRestController;
import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,11 +68,6 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
private final XacmlPdpParameterGroup xacmlPdpParameterGroup;
/**
- * The XACML PDP REST API server.
- */
- private XacmlPdpRestServer restServer;
-
- /**
* Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then
* dispatches them to appropriate listener.
*/
@@ -91,6 +88,7 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
final XacmlPdpHearbeatPublisher heartbeat;
final TopicSinkClient sinkClient;
final XacmlState state;
+ final RestServer restServer;
try {
XacmlPdpApplicationManager appmgr =
@@ -119,6 +117,9 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(),
new XacmlPdpUpdateListener(sinkClient, state, heartbeat, appmgr));
+ restServer = new RestServer(xacmlPdpParameterGroup.getRestServerParameters(), XacmlPdpAafFilter.class,
+ XacmlPdpRestController.class);
+
} catch (RuntimeException | TopicSinkClientException e) {
throw new PolicyXacmlPdpRuntimeException(e.getMessage(), e);
}
@@ -146,13 +147,9 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
heartbeat::start,
heartbeat::terminate);
- addAction("Create REST server",
- () -> restServer = new XacmlPdpRestServer(xacmlPdpParameterGroup.getRestServerParameters()),
- () -> restServer = null);
-
addAction("REST server",
- () -> restServer.start(),
- () -> restServer.stop());
+ restServer::start,
+ restServer::stop);
// @formatter:on
}