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.plugins.event.carrier.restserver;
23 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
26 * Apex parameters for REST as an event carrier technology with Apex as a REST client.
28 * The parameters for this plugin are:
30 * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
31 * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
32 * only on REST server event inputs.
33 * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
34 * event inputs in standalone mode.
35 * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
36 * inputs in standalone mode.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class RESTServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
43 private static final int MIN_USER_PORT = 1024;
44 private static final int MAX_USER_PORT = 65535;
46 /** The label of this carrier technology. */
47 public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
49 /** The producer plugin class for the REST carrier technology. */
50 public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getCanonicalName();
52 /** The consumer plugin class for the REST carrier technology. */
53 public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getCanonicalName();
55 // REST server parameters
56 private boolean standalone = false;
57 private String host = null;
58 private int port = -1;
62 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
65 public RESTServerCarrierTechnologyParameters() {
66 super(RESTServerCarrierTechnologyParameters.class.getCanonicalName());
68 // Set the carrier technology properties for the web socket carrier technology
69 this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
70 this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
71 this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
75 * Check if the REST server is running in standalone mode or is using an underlying servlet infrastructure to manage
78 * @return true if in standalone mode
80 public boolean isStandalone() {
89 public String getHost() {
98 public int getPort() {
105 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
108 public String validate() {
109 final StringBuilder errorMessageBuilder = new StringBuilder();
111 errorMessageBuilder.append(super.validate());
113 // Check if host is defined, it is only defined on REST server consumers
116 if (host.trim().length() == 0) {
117 errorMessageBuilder.append(" host not specified, must be host as a string\n");
121 // Check if port is defined, it is only defined on REST server consumers
123 if (port < MIN_USER_PORT || port > MAX_USER_PORT) {
125 .append(" port [" + port + "] invalid, must be specified as 1024 <= port <= 6535\n");
129 if (host != null || port != -1) {
130 errorMessageBuilder.append(" host and port are specified only in standalone mode\n");
134 return errorMessageBuilder.toString();