2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.aai.web;
23 import java.io.UnsupportedEncodingException;
24 import java.util.Base64;
26 import org.apache.commons.lang3.StringUtils;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.http.HttpHeaders;
33 import org.springframework.http.MediaType;
34 import org.springframework.web.client.RestTemplate;
37 public class EventClientPublisher {
39 private static final Logger LOGGER = LoggerFactory.getLogger(EventClientPublisher.class);
41 @Value("${dmaap.ribbon.listOfServers:}")
44 @Value("${dmaap.ribbon.username:}")
45 private String username;
47 @Value("${dmaap.ribbon.password:}")
48 private String password;
50 @Value("${dmaap.ribbon.topic:AAI-EVENT}")
53 @Value("${dmaap.ribbon.batchSize:100}")
54 private int maxBatchSize;
56 @Value("${dmaap.ribbon.maxAgeMs:250}")
59 @Value("${dmaap.ribbon.delayBetweenBatches:100}")
60 private int delayBetweenBatches;
62 @Value("${dmaap.ribbon.protocol:http}")
63 private String protocol;
65 @Value("${dmaap.ribbon.transportType:HTTPNOAUTH}")
66 private String tranportType;
68 @Value("${dmaap.ribbon.contentType:application/json}")
69 private String contentType;
71 @Bean(name = "dmaapRestTemplate")
72 public RestTemplate dmaapRestTemplate() {
73 return new RestTemplate();
76 @Bean(name = "dmaapHeaders")
77 public HttpHeaders dmaapHeaders() throws UnsupportedEncodingException {
79 HttpHeaders httpHeaders = new HttpHeaders();
80 httpHeaders.setContentType(MediaType.APPLICATION_JSON);
82 if (username != null && password != null) {
84 if (!StringUtils.EMPTY.equals(username) && !StringUtils.EMPTY.equals(password)) {
86 byte[] userPass = (username + ":" + password).getBytes("UTF-8");
88 httpHeaders.set("Authorization", "Basic " + Base64.getEncoder().encodeToString(userPass));