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;
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
28 * Apex parameters for REST as an event carrier technology with Apex as a REST client.
30 * <p>The parameters for this plugin are:
32 * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
33 * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
34 * only on REST server event inputs.
35 * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
36 * event inputs in standalone mode.
37 * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
38 * inputs in standalone mode.
41 * @author Liam Fallon (liam.fallon@ericsson.com)
43 public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
45 private static final int MIN_USER_PORT = 1024;
46 private static final int MAX_USER_PORT = 65535;
48 /** The label of this carrier technology. */
49 public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
51 /** The producer plugin class for the REST carrier technology. */
52 public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getName();
54 /** The consumer plugin class for the REST carrier technology. */
55 public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getName();
57 // REST server parameters
58 private boolean standalone = false;
59 private String host = null;
60 private int port = -1;
64 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
67 public RestServerCarrierTechnologyParameters() {
70 // Set the carrier technology properties for the web socket carrier technology
71 this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
72 this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
73 this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
77 * Check if the REST server is running in standalone mode or is using an underlying servlet infrastructure to manage
80 * @return true if in standalone mode
82 public boolean isStandalone() {
91 public String getHost() {
100 public int getPort() {
108 public GroupValidationResult validate() {
109 final GroupValidationResult result = super.validate();
111 // Check if host is defined, it is only defined on REST server consumers
113 if (host != null && host.trim().length() == 0) {
114 result.setResult("host", ValidationStatus.INVALID,
115 "host not specified, host must be specified as a string");
118 // Check if port is defined, it is only defined on REST server consumers
119 if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
120 result.setResult("port", ValidationStatus.INVALID,
121 "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
125 result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode");
128 result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode");