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 org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.io.UnsupportedEncodingException;
27 import java.util.Base64;
29 import org.apache.commons.lang.StringUtils;
30 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.context.annotation.Configuration;
33 import org.springframework.http.HttpHeaders;
34 import org.springframework.http.MediaType;
35 import org.springframework.web.client.RestTemplate;
38 public class EventClientPublisher {
40 private static final Logger LOGGER = LoggerFactory.getLogger(EventClientPublisher.class);
42 @Value("${dmaap.ribbon.listOfServers:}")
45 @Value("${dmaap.ribbon.username:}")
46 private String username;
48 @Value("${dmaap.ribbon.password:}")
49 private String password;
51 @Value("${dmaap.ribbon.topic:AAI-EVENT}")
54 @Value("${dmaap.ribbon.batchSize:100}")
55 private int maxBatchSize;
57 @Value("${dmaap.ribbon.maxAgeMs:250}")
60 @Value("${dmaap.ribbon.delayBetweenBatches:100}")
61 private int delayBetweenBatches;
63 @Value("${dmaap.ribbon.protocol:http}")
64 private String protocol;
66 @Value("${dmaap.ribbon.transportType:HTTPNOAUTH}")
67 private String tranportType;
69 @Value("${dmaap.ribbon.contentType:application/json}")
70 private String contentType;
72 @Bean(name = "dmaapRestTemplate")
73 public RestTemplate dmaapRestTemplate() {
74 return new RestTemplate();
77 @Bean(name = "dmaapHeaders")
78 public HttpHeaders dmaapHeaders() throws UnsupportedEncodingException {
80 HttpHeaders httpHeaders = new HttpHeaders();
81 httpHeaders.setContentType(MediaType.APPLICATION_JSON);
83 if (username != null && password != null) {
85 if (!StringUtils.EMPTY.equals(username) && !StringUtils.EMPTY.equals(password)) {
87 byte[] userPass = (username + ":" + password).getBytes("UTF-8");
89 httpHeaders.set("Authorization", "Basic " + Base64.getEncoder().encodeToString(userPass));