2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019,2023 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.plugins.event.carrier.restserver;
25 import lombok.AccessLevel;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
30 import org.onap.policy.common.parameters.BeanValidationResult;
31 import org.onap.policy.common.parameters.ValidationStatus;
32 import org.onap.policy.models.base.Validated;
35 * Apex parameters for REST as an event carrier technology with Apex as a REST client.
37 * <p>The parameters for this plugin are:
39 * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or
40 * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal
41 * only on REST server event inputs.
42 * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server
43 * event inputs in standalone mode.
44 * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event
45 * inputs in standalone mode.
48 * @author Liam Fallon (liam.fallon@ericsson.com)
51 public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters {
53 private static final int MIN_USER_PORT = 1024;
54 private static final int MAX_USER_PORT = 65535;
56 /** The label of this carrier technology. */
57 public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER";
59 /** The producer plugin class for the REST carrier technology. */
60 public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getName();
62 /** The consumer plugin class for the REST carrier technology. */
63 public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getName();
65 // REST server parameters
66 @Setter(AccessLevel.PACKAGE)
67 private boolean standalone = false;
68 @Setter(AccessLevel.PACKAGE)
69 private String host = null;
70 @Setter(AccessLevel.PACKAGE)
71 private int port = -1;
72 private String userName;
73 private String password;
74 private boolean https;
75 private boolean sniHostCheck;
80 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
83 public RestServerCarrierTechnologyParameters() {
86 // Set the carrier technology properties for the web socket carrier technology
87 this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL);
88 this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS);
89 this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS);
96 public BeanValidationResult validate() {
97 final BeanValidationResult result = super.validate();
99 // Check if host is defined, it is only defined on REST server consumers
101 if (StringUtils.isBlank(host)) {
102 result.addResult("host", host, ValidationStatus.INVALID, Validated.IS_BLANK);
105 // Check if port is defined, it is only defined on REST server consumers
106 if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
107 result.addResult("port", port, ValidationStatus.INVALID, "must be between 1024 and 65535");
111 result.addResult("host", host, ValidationStatus.INVALID, "should be specified only in standalone mode");
114 result.addResult("port", port, ValidationStatus.INVALID, "should be specified only in standalone mode");