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.restrequestor;
24 import java.util.Arrays;
25 import java.util.HashSet;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29 import java.util.regex.PatternSyntaxException;
31 import javax.ws.rs.core.MultivaluedHashMap;
32 import javax.ws.rs.core.MultivaluedMap;
36 import org.apache.commons.lang3.StringUtils;
37 import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
38 import org.onap.policy.common.parameters.GroupValidationResult;
39 import org.onap.policy.common.parameters.ValidationStatus;
40 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
46 * Apex parameters for REST as an event carrier technology with Apex issuing a REST request and receiving a REST
49 * <p>The parameters for this plugin are:
51 * <li>url: The URL that the Apex Rest Requestor will connect to over REST for REST request sending.
52 * This parameter is mandatory.
53 * <li>httpMethod: The HTTP method to use when making requests over REST, legal values are GET (default),
54 * POST, PUT, and DELETE.
55 * <li>httpHeaders, the HTTP headers to send on REST requests, optional parameter, defaults to none.
56 * <li>httpCodeFilter: a regular expression filter for returned HTTP codes, if the returned HTTP code passes this
57 * filter, then the request is assumed to have succeeded by the plugin, optional, defaults to allowing 2xx codes
58 * through, that is a regular expression of "[2][0-9][0-9]"
61 * @author Liam Fallon (liam.fallon@ericsson.com)
66 public class RestRequestorCarrierTechnologyParameters extends RestPluginCarrierTechnologyParameters {
67 // Get a reference to the logger
68 private static final Logger LOGGER = LoggerFactory.getLogger(RestRequestorCarrierTechnologyParameters.class);
72 /** The default HTTP method for request events. */
73 public static final HttpMethod DEFAULT_REQUESTOR_HTTP_METHOD = HttpMethod.GET;
75 /** The default timeout for REST requests. */
76 public static final long DEFAULT_REST_REQUEST_TIMEOUT = 500;
79 * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
82 public RestRequestorCarrierTechnologyParameters() {
85 // Set the carrier technology properties for the web socket carrier technology
86 CARRIER_TECHNOLOGY_LABEL = "RESTREQUESTOR";
87 EVENT_PRODUCER_PLUGIN_CLASS = ApexRestRequestorProducer.class.getName();
88 EVENT_CONSUMER_PLUGIN_CLASS = ApexRestRequestorConsumer.class.getName();
89 // Set the carrier technology properties for the web socket carrier technology
90 this.setLabel(CARRIER_TECHNOLOGY_LABEL);
91 this.setEventProducerPluginClass(EVENT_PRODUCER_PLUGIN_CLASS);
92 this.setEventConsumerPluginClass(EVENT_CONSUMER_PLUGIN_CLASS);
100 * http://www.blah.com/{par1/somethingelse (Missing end tag) use {[^\\{}]*$
101 * http://www.blah.com/{par1/{some}thingelse (Nested tag) use {[^}]*{
102 * http://www.blah.com/{par1}/some}thingelse (Missing start tag1) use }[^{}]*.}
103 * http://www.blah.com/par1}/somethingelse (Missing start tag2) use }[^{}]*}
104 * http://www.blah.com/{}/somethingelse (Empty tag) use {[\s]*}
105 * @param result the result of the validation
109 public GroupValidationResult validateUrl(final GroupValidationResult result) {
110 // URL is only set on Requestor consumers
111 if (getUrl() == null) {
115 Matcher matcher = patternErrorKey.matcher(getUrl());
116 if (matcher.find()) {
117 result.setResult("url", ValidationStatus.INVALID,
118 "no proper URL has been set for event sending on REST requestor");