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=========================================================
20 package org.onap.aai.web;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.apache.commons.lang.StringUtils;
25 import org.springframework.beans.factory.annotation.Value;
26 import org.springframework.context.annotation.Bean;
27 import org.springframework.context.annotation.Configuration;
28 import org.springframework.http.HttpHeaders;
29 import org.springframework.http.MediaType;
30 import org.springframework.web.client.RestTemplate;
32 import java.io.UnsupportedEncodingException;
33 import java.util.Base64;
36 public class EventClientPublisher {
38 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(EventClientPublisher.class);
40 @Value("${dmaap.ribbon.listOfServers:}")
43 @Value("${dmaap.ribbon.username:}")
44 private String username;
46 @Value("${dmaap.ribbon.password:}")
47 private String password;
49 @Value("${dmaap.ribbon.topic:AAI-EVENT}")
52 @Value("${dmaap.ribbon.batchSize:100}")
53 private int maxBatchSize;
55 @Value("${dmaap.ribbon.maxAgeMs:250}")
58 @Value("${dmaap.ribbon.delayBetweenBatches:100}")
59 private int delayBetweenBatches;
61 @Value("${dmaap.ribbon.protocol:http}")
62 private String protocol;
64 @Value("${dmaap.ribbon.transportType:HTTPNOAUTH}")
65 private String tranportType;
67 @Value("${dmaap.ribbon.contentType:application/json}")
68 private String contentType;
70 @Bean(name="dmaapRestTemplate")
71 public RestTemplate dmaapRestTemplate(){
72 return new RestTemplate();
75 @Bean(name="dmaapHeaders")
76 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));