2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.client.full.rest;
26 * This class reads and handles command line parameters to the Apex RESTful services.
28 * @author Michael Watkins (michael.watkins@ericsson.com)
30 public class ApexServicesRestParameters {
31 public static final int DEFAULT_REST_PORT = 18989;
32 public static final int INFINITY_TIME_TO_LIVE = -1;
34 // Base URI the HTTP server will listen on
35 private static final String DEFAULT_SERVER_URI_ROOT = "http://localhost:";
36 private static final String DEFAULT_REST_PATH = "/apexservices/";
37 private static final String DEFAULT_STATIC_PATH = "/";
39 // Package that will field REST requests
40 private static final String[] DEFAULT_PACKAGES = new String[] {
41 "org.onap.policy.apex.client.deployment.rest",
42 "org.onap.policy.apex.client.editor.rest",
43 "org.onap.policy.apex.client.monitoring.rest"
46 // The services parameters
47 private boolean helpSet = false;
48 private int restPort = DEFAULT_REST_PORT;
49 private long timeToLive = INFINITY_TIME_TO_LIVE;
52 * Validate the parameters.
53 * @return the result of the validation
55 public String validate() {
56 String validationMessage = "";
57 validationMessage += validatePort();
58 validationMessage += validateTimeToLive();
60 return validationMessage;
63 public URI getBaseUri() {
64 return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH);
67 public String[] getRestPackages() {
68 return DEFAULT_PACKAGES;
71 public String getStaticPath() {
72 return DEFAULT_STATIC_PATH;
75 private String validatePort() {
76 if (restPort < 1024 || restPort > 65535) {
77 return "port must be greater than 1023 and less than 65536\n";
83 private String validateTimeToLive() {
84 if (timeToLive < -1) {
85 return "time to live must be greater than -1 (set to -1 to wait forever)\n";
91 public boolean isHelpSet() {
95 public void setHelp(final boolean helpSet) {
96 this.helpSet = helpSet;
99 public int getRestPort() {
103 public void setRestPort(final int restPort) {
104 this.restPort = restPort;
107 public long getTimeToLive() {
111 public void setTimeToLive(final long timeToLive) {
112 this.timeToLive = timeToLive;
116 public String toString() {
117 final StringBuilder ret = new StringBuilder();
118 ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
119 .append(this.getTimeToLive()).append("sec");
120 return ret.toString();