2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 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.
18 * ============================LICENSE_END===========================================
21 package org.onap.dcae.apod.analytics.dmaap.domain.config;
23 import com.google.common.base.Objects;
24 import org.onap.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import java.util.Locale;
30 import static org.onap.dcae.apod.analytics.common.utils.HTTPUtils.JSON_APPLICATION_TYPE;
34 * Contains common parameters for both DMaaP Message Router Publisher and Subscriber Configs
36 * @author Rajiv Singla . Creation Date: 10/12/2016.
38 public abstract class DMaaPMRBaseConfig implements DMaaPMRConfig {
40 protected static final Logger LOG = LoggerFactory.getLogger(DMaaPMRBaseConfig.class);
42 protected String hostName;
43 protected Integer portNumber;
44 protected String topicName;
45 protected String protocol;
46 protected String userName;
47 protected String userPassword;
48 protected String contentType;
51 * Provides host name e.g. mrlocal-mtnjftle01.homer.com
55 public String getHostName() {
61 * Provides Port Number of DMaaP MR Topic Host. Defaults to 80
63 * @return host port number
65 public Integer getPortNumber() {
70 * Provides topic name e.g. com.dcae.dmaap.mtnje2.DcaeTestVES
74 public String getTopicName() {
79 * Provides protocol type e.g. http or https
81 * @return protocol type
83 public String getProtocol() {
88 * Provides content type e.g. application/json
90 * @return content type
92 public String getContentType() {
98 * Provides User name for the DMaaP MR Topic authentication
102 public String getUserName() {
107 * Provides User password for the DMaaP MR Topic authentication
109 * @return user Password
111 public String getUserPassword() {
117 * Trims, adjusts casing and validates user input String for protocol selection
119 * @param protocol - User input for protocol String
120 * @return - network protocol e.g http or https
122 protected static String normalizeValidateProtocol(final String protocol) {
123 // validate that only http and https are supported protocols are Supported for DMaaP MR
124 String normalizedProtocolString = protocol.trim().toLowerCase(Locale.ENGLISH);
125 if (normalizedProtocolString.isEmpty() ||
126 !("http".equals(normalizedProtocolString) || "https".equals(normalizedProtocolString))) {
128 final String errorMessage =
129 "Unsupported protocol selection. Only HTTPS and HTTPS are currently supported for DMaaP MR";
131 throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
133 return normalizedProtocolString;
138 * Trims, adjust casing and validates content type is supported by DMaaP.
140 * NOTE: DMaaP currently only support application/json content type
142 * @param contentType content type that needs to checked for DMaaP MR support
143 * @return true if content type is supported by DMaaP MR
145 protected static String normalizeValidateContentType(final String contentType) {
146 // Current DMaaP MR is only supporting "application/json" content type
147 String normalizedContentType = contentType.trim().toLowerCase(Locale.ENGLISH);
148 final boolean isSupported = contentType.equals(JSON_APPLICATION_TYPE);
150 final String errorMessage =
151 "Unsupported content type selection. Only application/json is currently supported for DMaaP MR";
153 throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
155 return normalizedContentType;
160 public boolean equals(Object o) {
164 if (!(o instanceof DMaaPMRBaseConfig)) {
167 DMaaPMRBaseConfig that = (DMaaPMRBaseConfig) o;
168 return Objects.equal(hostName, that.hostName) &&
169 Objects.equal(portNumber, that.portNumber) &&
170 Objects.equal(topicName, that.topicName) &&
171 Objects.equal(protocol, that.protocol) &&
172 Objects.equal(userName, that.userName) &&
173 Objects.equal(userPassword, that.userPassword) &&
174 Objects.equal(contentType, that.contentType);
178 public int hashCode() {
179 return Objects.hashCode(hostName, portNumber, topicName, protocol, userName, userPassword, contentType);
183 public String toString() {
184 return Objects.toStringHelper(this)
185 .add("hostName", hostName)
186 .add("portNumber", portNumber)
187 .add("topicName", topicName)
188 .add("protocol", protocol)
189 .add("userName", userName)
190 .add("contentType", contentType)