diff options
author | jh7358 <jh7358@att.com> | 2019-02-22 16:41:54 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-02-22 17:50:57 -0500 |
commit | 92eabbc64c1ea6f6bfe6df979ccc487e99e806be (patch) | |
tree | 599dfa47b4a6a159f8c28502cd045ceade4b89bf /main/src | |
parent | d5d3b44d40dbaa0cd5a78d55d546577871b8924e (diff) |
Use constants for http property names
Modified the PAP REST server to use constants from policy-endpoints
instead of hard-coding property names.
Also made "alive" volatile.
Also modified to use standard gson as the serialization provider to
ensure that it will always work with gson.
Removed unneeded constant.
Removed trailing whitespace.
Replaced another literal with a constant name.
Updated licenses.
Change-Id: Ibfc6d19ad4dae62ebd610d6127d1d253175ae71e
Issue-ID: POLICY-1444
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src')
3 files changed, 34 insertions, 24 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java index d67d0d5b..6f4c1cc0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,9 +45,12 @@ public class HealthCheckProvider { final HealthCheckReport report = new HealthCheckReport(); report.setName(NAME); report.setUrl(URL); - report.setHealthy(PapActivator.isAlive()); - report.setCode(PapActivator.isAlive() ? 200 : 500); - report.setMessage(PapActivator.isAlive() ? ALIVE : NOT_ALIVE); + + boolean alive = PapActivator.isAlive(); + + report.setHealthy(alive); + report.setCode(alive ? 200 : 500); + report.setMessage(alive ? ALIVE : NOT_ALIVE); return report; } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java index e9064a82..c6a5e301 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +27,8 @@ 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.properties.PolicyEndPointProperties; +import org.onap.policy.common.gson.GsonMessageBodyHandler; import org.onap.policy.pap.main.parameters.RestServerParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,9 +42,6 @@ public class PapRestServer implements Startable { private static final Logger LOGGER = LoggerFactory.getLogger(PapRestServer.class); - private static final String SEPARATOR = "."; - private static final String HTTP_SERVER_SERVICES = "http.server.services"; - private List<HttpServletServer> servers = new ArrayList<>(); private RestServerParameters restServerParameters; @@ -82,23 +82,28 @@ public class PapRestServer implements Startable { */ 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", - PapRestController.class.getCanonicalName()); - 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(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, restServerParameters.getName()); + + final String svcpfx = + PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + restServerParameters.getName(); + + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, restServerParameters.getHost()); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, + Integer.toString(restServerParameters.getPort())); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, + PapRestController.class.getCanonicalName()); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false"); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "true"); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, + restServerParameters.getUserName()); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, + restServerParameters.getPassword()); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, + String.valueOf(restServerParameters.isHttps())); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX, + String.valueOf(restServerParameters.isAaf())); + props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, + GsonMessageBodyHandler.class.getName()); return props; } diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java index 86a435ae..9fb3535b 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +39,7 @@ public class PapActivator { private static final Logger LOGGER = LoggerFactory.getLogger(PapActivator.class); private final PapParameterGroup papParameterGroup; - private static boolean alive = false; + private static volatile boolean alive = false; private PapRestServer restServer; /** |