summaryrefslogtreecommitdiffstats
path: root/aai-core
diff options
context:
space:
mode:
authorKajur, Harish (vk250x) <vk250x@att.com>2018-11-06 21:40:50 -0500
committerKajur, Harish (vk250x) <vk250x@att.com>2018-11-06 23:05:33 -0500
commitd2d51c26f4378867d870156a5f211510f8a44a38 (patch)
treec5b2699199d62a13d971cf8610d02ae1c33fbfb4 /aai-core
parent6713cba6c39f2e8f57fb835a4cfb7d6dfc411d94 (diff)
Add the https rest template1.3.2
Issue-ID: AAI-1761 Change-Id: I56d423c84bcc0648cca01d0ebd7f20a8bc5a2fd3 Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
Diffstat (limited to 'aai-core')
-rw-r--r--aai-core/pom.xml10
-rw-r--r--aai-core/src/main/java/org/onap/aai/web/EventClientPublisher.java42
2 files changed, 47 insertions, 5 deletions
diff --git a/aai-core/pom.xml b/aai-core/pom.xml
index 74d2f916..261a3e43 100644
--- a/aai-core/pom.xml
+++ b/aai-core/pom.xml
@@ -27,11 +27,11 @@
<parent>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-common</artifactId>
- <version>1.3.1-SNAPSHOT</version>
+ <version>1.3.2-SNAPSHOT</version>
</parent>
<artifactId>aai-core</artifactId>
<name>aai-core</name>
- <version>1.3.1-SNAPSHOT</version>
+ <version>1.3.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<sonar.language>java</sonar.language>
@@ -1019,6 +1019,12 @@
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ <version>1.5.15.RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<!-- Plugins and repositories -->
diff --git a/aai-core/src/main/java/org/onap/aai/web/EventClientPublisher.java b/aai-core/src/main/java/org/onap/aai/web/EventClientPublisher.java
index ac897273..ea614bc9 100644
--- a/aai-core/src/main/java/org/onap/aai/web/EventClientPublisher.java
+++ b/aai-core/src/main/java/org/onap/aai/web/EventClientPublisher.java
@@ -22,13 +22,21 @@ package org.onap.aai.web;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.util.ResourceUtils;
import org.springframework.web.client.RestTemplate;
+import javax.net.ssl.SSLContext;
+import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
@@ -61,14 +69,42 @@ public class EventClientPublisher {
@Value("${dmaap.ribbon.protocol:http}")
private String protocol;
- @Value("${dmaap.ribbon.transportType:HTTPNOAUTH}")
- private String tranportType;
+ @Value("${dmaap.ribbon.transportType:http}")
+ private String transportType;
@Value("${dmaap.ribbon.contentType:application/json}")
private String contentType;
+ @Value("${server.ssl.trust-store:aai_keystore}")
+ private String trustStoreFile;
+
+ @Value("${server.ssl.trust-store-password:somepass}")
+ private String trustStorePass;
+
@Bean(name="dmaapRestTemplate")
- public RestTemplate dmaapRestTemplate(){
+ public RestTemplate dmaapRestTemplate() throws Exception {
+
+ if(transportType.equals("https")){
+
+ RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
+
+ SSLContext sslContext = SSLContextBuilder
+ .create()
+ .loadTrustMaterial(ResourceUtils.getFile(trustStoreFile), trustStorePass.toCharArray())
+ .build();
+
+ HttpClient client = HttpClients
+ .custom()
+ .setSSLContext(sslContext)
+ .build();
+
+ LOGGER.info("Creating a dmaap rest template with https using truststore {}", trustStoreFile);
+ return restTemplateBuilder
+ .requestFactory(new HttpComponentsClientHttpRequestFactory(client))
+ .build();
+ }
+
+ LOGGER.info("Creating a dmaap rest template using http");
return new RestTemplate();
}