e07593c55dc81a4a5e4842b61a6646e127a04822
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.plugins.event.carrier.restclient;
22
23 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
24
25 /**
26  * Apex parameters for REST as an event carrier technology with Apex as a REST client.
27  *
28  * The parameters for this plugin are:
29  * <ol>
30  * <li>url: The URL that the Apex Rest client will connect to over REST for event reception or event sending. This
31  * parameter is mandatory.
32  * <li>httpMethod: The HTTP method to use when sending events over REST, legal values are POST (default) and PUT. When
33  * receiving events, the REST client plugin always uses the HTTP GET method.
34  * </ol>
35  *
36  * @author Joss Armstrong (joss.armstrong@ericsson.com)
37  */
38 public class RESTClientCarrierTechnologyParameters extends CarrierTechnologyParameters {
39
40     /** The label of this carrier technology. */
41     public static final String RESTCLIENT_CARRIER_TECHNOLOGY_LABEL = "RESTCLIENT";
42
43     /** The producer plugin class for the REST carrier technology. */
44     public static final String RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestClientProducer.class.getCanonicalName();
45
46     /** The consumer plugin class for the REST carrier technology. */
47     public static final String RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestClientConsumer.class.getCanonicalName();
48
49     /** The default HTTP method for output of events. */
50     public static final String DEFAULT_PRODUCER_HTTP_METHOD = "POST";
51
52     /** The HTTP method for input of events. */
53     public static final String CONSUMER_HTTP_METHOD = "GET";
54
55     private String url = null;
56     private String httpMethod = null;
57
58     /**
59      * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
60      * service.
61      */
62     public RESTClientCarrierTechnologyParameters() {
63         super(RESTClientCarrierTechnologyParameters.class.getCanonicalName());
64
65         // Set the carrier technology properties for the web socket carrier technology
66         this.setLabel(RESTCLIENT_CARRIER_TECHNOLOGY_LABEL);
67         this.setEventProducerPluginClass(RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS);
68         this.setEventConsumerPluginClass(RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS);
69
70     }
71
72     /**
73      * Gets the URL for the REST request.
74      *
75      * @return the URL
76      */
77     public String getURL() {
78         return url;
79     }
80
81     /**
82      * Sets the URL for the REST request.
83      *
84      * @param incomingURL the URL
85      */
86     public void setURL(final String incomingURL) {
87         this.url = incomingURL;
88     }
89
90     /**
91      * Gets the HTTP method to use for the REST request.
92      *
93      * @return the HTTP method
94      */
95     public String getHttpMethod() {
96         return httpMethod;
97     }
98
99     /**
100      * Sets the HTTP method to use for the REST request.
101      *
102      * @param httpMethod the HTTP method
103      */
104     public void setHttpMethod(final String httpMethod) {
105         this.httpMethod = httpMethod;
106     }
107
108     /*
109      * (non-Javadoc)
110      *
111      * @see java.lang.Object#toString()
112      */
113     @Override
114     public String toString() {
115         return "RESTClientCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + "]";
116     }
117
118
119     /*
120      *
121      * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
122      */
123     @Override
124     public String validate() {
125         final StringBuilder errorMessageBuilder = new StringBuilder();
126
127         // Check if the URL has been set for event output
128         if (getURL() == null) {
129             errorMessageBuilder.append("  no URL has been set for event sending on REST client");
130         }
131
132         return errorMessageBuilder.toString();
133     }
134 }