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;
24 import lombok.AccessLevel;
27 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ValidationStatus;
32 * Apex parameters for REST as an event carrier technology with Apex as a REST client.
34 * <p>The parameters for this plugin are:
36 * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
37 * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
38 * only on REST server event inputs.
39 * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
40 * event inputs in standalone mode.
41 * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
42 * inputs in standalone mode.
45 * @author Liam Fallon (liam.fallon@ericsson.com)
48 public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
50 private static final int MIN_USER_PORT = 1024;
51 private static final int MAX_USER_PORT = 65535;
53 /** The label of this carrier technology. */
54 public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
56 /** The producer plugin class for the REST carrier technology. */
57 public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getName();
59 /** The consumer plugin class for the REST carrier technology. */
60 public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getName();
62 // REST server parameters
63 @Setter(AccessLevel.PACKAGE)
64 private boolean standalone = false;
65 @Setter(AccessLevel.PACKAGE)
66 private String host = null;
67 @Setter(AccessLevel.PACKAGE)
68 private int port = -1;
69 private String userName;
70 private String password;
71 private boolean https;
76 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
79 public RestServerCarrierTechnologyParameters() {
82 // Set the carrier technology properties for the web socket carrier technology
83 this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
84 this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
85 this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
92 public GroupValidationResult validate() {
93 final GroupValidationResult result = super.validate();
95 // Check if host is defined, it is only defined on REST server consumers
97 if (host != null && host.trim().length() == 0) {
98 result.setResult("host", ValidationStatus.INVALID,
99 "host not specified, host must be specified as a string");
102 // Check if port is defined, it is only defined on REST server consumers
103 if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
104 result.setResult("port", ValidationStatus.INVALID,
105 "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
109 result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode");
112 result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode");