2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.plugins.event.carrier.restserver;
25 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ValidationStatus;
30 * Apex parameters for REST as an event carrier technology with Apex as a REST client.
32 * <p>The parameters for this plugin are:
34 * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
35 * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
36 * only on REST server event inputs.
37 * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
38 * event inputs in standalone mode.
39 * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
40 * inputs in standalone mode.
43 * @author Liam Fallon (liam.fallon@ericsson.com)
46 public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
48 private static final int MIN_USER_PORT = 1024;
49 private static final int MAX_USER_PORT = 65535;
51 /** The label of this carrier technology. */
52 public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
54 /** The producer plugin class for the REST carrier technology. */
55 public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getName();
57 /** The consumer plugin class for the REST carrier technology. */
58 public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getName();
60 // REST server parameters
61 private boolean standalone = false;
62 private String host = null;
63 private int port = -1;
64 private String userName;
65 private String password;
66 private boolean https;
71 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
74 public RestServerCarrierTechnologyParameters() {
77 // Set the carrier technology properties for the web socket carrier technology
78 this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
79 this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
80 this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
87 public GroupValidationResult validate() {
88 final GroupValidationResult result = super.validate();
90 // Check if host is defined, it is only defined on REST server consumers
92 if (host != null && host.trim().length() == 0) {
93 result.setResult("host", ValidationStatus.INVALID,
94 "host not specified, host must be specified as a string");
97 // Check if port is defined, it is only defined on REST server consumers
98 if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
99 result.setResult("port", ValidationStatus.INVALID,
100 "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
104 result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode");
107 result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode");