Merge "AsyncRestClient reuse of SSL context"
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java
index 9e2142e..ce41956 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java
@@ -78,7 +78,7 @@
 
     @Bean
     public ProducerCallbacks getProducerCallbacks() {
-        return new ProducerCallbacks();
+        return new ProducerCallbacks(this.applicationConfig);
     }
 
     private static Connector getHttpConnector(int httpPort) {
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java
index 2782f94..76da624 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 Nordix Foundation
+ * Copyright (C) 2020 Nordix Foundation
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,36 +22,18 @@
 
 import io.netty.channel.ChannelOption;
 import io.netty.handler.ssl.SslContext;
-import io.netty.handler.ssl.SslContextBuilder;
-import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
 import io.netty.handler.timeout.ReadTimeoutHandler;
 import io.netty.handler.timeout.WriteTimeoutHandler;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.invoke.MethodHandles;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.util.Collections;
-import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.Collectors;
 
-import javax.net.ssl.KeyManagerFactory;
-
-import org.oransc.enrichment.configuration.WebClientConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.reactive.ReactorClientHttpConnector;
 import org.springframework.lang.Nullable;
-import org.springframework.util.ResourceUtils;
 import org.springframework.web.reactive.function.client.ExchangeStrategies;
 import org.springframework.web.reactive.function.client.WebClient;
 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
@@ -66,22 +48,25 @@
  * Generic reactive REST client.
  */
 public class AsyncRestClient {
+
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
     private WebClient webClient = null;
     private final String baseUrl;
     private static final AtomicInteger sequenceNumber = new AtomicInteger();
-    private final WebClientConfig clientConfig;
-    static KeyStore clientTrustStore = null;
-    private boolean sslEnabled = true;
+    private final SslContext sslContext;
 
+    /**
+     * Note that only http (not https) will work when this constructor is used.
+     * 
+     * @param baseUrl
+     */
     public AsyncRestClient(String baseUrl) {
         this(baseUrl, null);
-        this.sslEnabled = false;
     }
 
-    public AsyncRestClient(String baseUrl, WebClientConfig config) {
+    public AsyncRestClient(String baseUrl, SslContext sslContext) {
         this.baseUrl = baseUrl;
-        this.clientConfig = config;
+        this.sslContext = sslContext;
     }
 
     public Mono<ResponseEntity<String>> postForEntity(String uri, @Nullable String body) {
@@ -185,10 +170,14 @@
         final Class<String> clazz = String.class;
         return request.retrieve() //
             .toEntity(clazz) //
-            .doOnNext(entity -> logger.trace("{} Received: {}", traceTag, entity.getBody())) //
+            .doOnNext(entity -> logReceivedData(traceTag, entity)) //
             .doOnError(throwable -> onHttpError(traceTag, throwable));
     }
 
+    private void logReceivedData(Object traceTag, ResponseEntity<String> entity) {
+        logger.trace("{} Received: {} {}", traceTag, entity.getBody(), entity.getHeaders().getContentType());
+    }
+
     private static Object createTraceTag() {
         return sequenceNumber.incrementAndGet();
     }
@@ -211,65 +200,6 @@
         }
     }
 
-    private boolean isCertificateEntry(KeyStore trustStore, String alias) {
-        try {
-            return trustStore.isCertificateEntry(alias);
-        } catch (KeyStoreException e) {
-            logger.error("Error reading truststore {}", e.getMessage());
-            return false;
-        }
-    }
-
-    private Certificate getCertificate(KeyStore trustStore, String alias) {
-        try {
-            return trustStore.getCertificate(alias);
-        } catch (KeyStoreException e) {
-            logger.error("Error reading truststore {}", e.getMessage());
-            return null;
-        }
-    }
-
-    private static synchronized KeyStore getTrustStore(String trustStorePath, String trustStorePass)
-        throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
-        if (clientTrustStore == null) {
-            KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
-            store.load(new FileInputStream(ResourceUtils.getFile(trustStorePath)), trustStorePass.toCharArray());
-            clientTrustStore = store;
-        }
-        return clientTrustStore;
-    }
-
-    private SslContext createSslContextRejectingUntrustedPeers(String trustStorePath, String trustStorePass,
-        KeyManagerFactory keyManager)
-        throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
-
-        final KeyStore trustStore = getTrustStore(trustStorePath, trustStorePass);
-        List<Certificate> certificateList = Collections.list(trustStore.aliases()).stream() //
-            .filter(alias -> isCertificateEntry(trustStore, alias)) //
-            .map(alias -> getCertificate(trustStore, alias)) //
-            .collect(Collectors.toList());
-        final X509Certificate[] certificates = certificateList.toArray(new X509Certificate[certificateList.size()]);
-
-        return SslContextBuilder.forClient() //
-            .keyManager(keyManager) //
-            .trustManager(certificates) //
-            .build();
-    }
-
-    private SslContext createSslContext(KeyManagerFactory keyManager)
-        throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
-        if (this.clientConfig.isTrustStoreUsed()) {
-            return createSslContextRejectingUntrustedPeers(this.clientConfig.trustStore(),
-                this.clientConfig.trustStorePassword(), keyManager);
-        } else {
-            // Trust anyone
-            return SslContextBuilder.forClient() //
-                .keyManager(keyManager) //
-                .trustManager(InsecureTrustManagerFactory.INSTANCE) //
-                .build();
-        }
-    }
-
     private TcpClient createTcpClientSecure(SslContext sslContext) {
         return TcpClient.create(ConnectionProvider.newConnection()) //
             .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) //
@@ -305,18 +235,7 @@
     private Mono<WebClient> getWebClient() {
         if (this.webClient == null) {
             try {
-                if (this.sslEnabled) {
-                    final KeyManagerFactory keyManager =
-                        KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
-                    final KeyStore keyStore = KeyStore.getInstance(this.clientConfig.keyStoreType());
-                    final String keyStoreFile = this.clientConfig.keyStore();
-                    final String keyStorePassword = this.clientConfig.keyStorePassword();
-                    final String keyPassword = this.clientConfig.keyPassword();
-                    try (final InputStream inputStream = new FileInputStream(keyStoreFile)) {
-                        keyStore.load(inputStream, keyStorePassword.toCharArray());
-                    }
-                    keyManager.init(keyStore, keyPassword.toCharArray());
-                    SslContext sslContext = createSslContext(keyManager);
+                if (this.sslContext != null) {
                     TcpClient tcpClient = createTcpClientSecure(sslContext);
                     this.webClient = createWebClient(this.baseUrl, tcpClient);
                 } else {
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java
new file mode 100644
index 0000000..07f23e9
--- /dev/null
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java
@@ -0,0 +1,179 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
+package org.oransc.enrichment.clients;
+
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.invoke.MethodHandles;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import org.oransc.enrichment.configuration.WebClientConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.ResourceUtils;
+
+/**
+ * Factory for a generic reactive REST client.
+ */
+public class AsyncRestClientFactory {
+    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    private final SslContextFactory sslContextFactory;
+
+    public AsyncRestClientFactory(WebClientConfig clientConfig) {
+        if (clientConfig != null) {
+            this.sslContextFactory = new CachingSslContextFactory(clientConfig);
+        } else {
+            this.sslContextFactory = null;
+        }
+    }
+
+    public AsyncRestClient createRestClient(String baseUrl) {
+        if (this.sslContextFactory != null) {
+            try {
+                return new AsyncRestClient(baseUrl, this.sslContextFactory.createSslContext());
+            } catch (Exception e) {
+                String exceptionString = e.toString();
+                logger.error("Could not init SSL context, reason: {}", exceptionString);
+            }
+        }
+        return new AsyncRestClient(baseUrl);
+    }
+
+    private class SslContextFactory {
+        private final WebClientConfig clientConfig;
+
+        public SslContextFactory(WebClientConfig clientConfig) {
+            this.clientConfig = clientConfig;
+        }
+
+        public SslContext createSslContext() throws UnrecoverableKeyException, NoSuchAlgorithmException,
+            CertificateException, KeyStoreException, IOException {
+            return this.createSslContext(createKeyManager());
+        }
+
+        private SslContext createSslContext(KeyManagerFactory keyManager)
+            throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
+            if (this.clientConfig.isTrustStoreUsed()) {
+                return createSslContextRejectingUntrustedPeers(this.clientConfig.trustStore(),
+                    this.clientConfig.trustStorePassword(), keyManager);
+            } else {
+                // Trust anyone
+                return SslContextBuilder.forClient() //
+                    .keyManager(keyManager) //
+                    .trustManager(InsecureTrustManagerFactory.INSTANCE) //
+                    .build();
+            }
+        }
+
+        private SslContext createSslContextRejectingUntrustedPeers(String trustStorePath, String trustStorePass,
+            KeyManagerFactory keyManager)
+            throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
+
+            final KeyStore trustStore = getTrustStore(trustStorePath, trustStorePass);
+            List<Certificate> certificateList = Collections.list(trustStore.aliases()).stream() //
+                .filter(alias -> isCertificateEntry(trustStore, alias)) //
+                .map(alias -> getCertificate(trustStore, alias)) //
+                .collect(Collectors.toList());
+            final X509Certificate[] certificates = certificateList.toArray(new X509Certificate[certificateList.size()]);
+
+            return SslContextBuilder.forClient() //
+                .keyManager(keyManager) //
+                .trustManager(certificates) //
+                .build();
+        }
+
+        private boolean isCertificateEntry(KeyStore trustStore, String alias) {
+            try {
+                return trustStore.isCertificateEntry(alias);
+            } catch (KeyStoreException e) {
+                logger.error("Error reading truststore {}", e.getMessage());
+                return false;
+            }
+        }
+
+        private Certificate getCertificate(KeyStore trustStore, String alias) {
+            try {
+                return trustStore.getCertificate(alias);
+            } catch (KeyStoreException e) {
+                logger.error("Error reading truststore {}", e.getMessage());
+                return null;
+            }
+        }
+
+        private KeyManagerFactory createKeyManager() throws NoSuchAlgorithmException, CertificateException, IOException,
+            UnrecoverableKeyException, KeyStoreException {
+            final KeyManagerFactory keyManager = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+            final KeyStore keyStore = KeyStore.getInstance(this.clientConfig.keyStoreType());
+            final String keyStoreFile = this.clientConfig.keyStore();
+            final String keyStorePassword = this.clientConfig.keyStorePassword();
+            final String keyPassword = this.clientConfig.keyPassword();
+            try (final InputStream inputStream = new FileInputStream(keyStoreFile)) {
+                keyStore.load(inputStream, keyStorePassword.toCharArray());
+            }
+            keyManager.init(keyStore, keyPassword.toCharArray());
+            return keyManager;
+        }
+
+        private synchronized KeyStore getTrustStore(String trustStorePath, String trustStorePass)
+            throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
+
+            KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
+            store.load(new FileInputStream(ResourceUtils.getFile(trustStorePath)), trustStorePass.toCharArray());
+            return store;
+        }
+    }
+
+    public class CachingSslContextFactory extends SslContextFactory {
+        private SslContext cachedContext = null;
+
+        public CachingSslContextFactory(WebClientConfig clientConfig) {
+            super(clientConfig);
+        }
+
+        @Override
+        public SslContext createSslContext() throws UnrecoverableKeyException, NoSuchAlgorithmException,
+            CertificateException, KeyStoreException, IOException {
+            if (this.cachedContext == null) {
+                this.cachedContext = super.createSslContext();
+            }
+            return this.cachedContext;
+
+        }
+    }
+
+}
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java
index 7f28a12..9b23865 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java
@@ -30,7 +30,6 @@
 import org.oransc.enrichment.repository.EiProducer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -46,11 +45,14 @@
         .serializeNulls() //
         .create(); //
 
-    @Autowired
-    ApplicationConfig applicationConfig;
+    private final AsyncRestClient restClient;
+
+    public ProducerCallbacks(ApplicationConfig config) {
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+        this.restClient = restClientFactory.createRestClient("");
+    }
 
     public void notifyProducersJobDeleted(EiJob eiJob) {
-        AsyncRestClient restClient = restClient();
         ProducerJobInfo request = new ProducerJobInfo(eiJob);
         String body = gson.toJson(request);
         for (EiProducer producer : eiJob.type().getProducers()) {
@@ -81,7 +83,6 @@
      * @return the body of the response from the REST call
      */
     public Mono<String> notifyProducerJobStarted(EiProducer producer, EiJob eiJob) {
-        AsyncRestClient restClient = restClient();
         ProducerJobInfo request = new ProducerJobInfo(eiJob);
         String body = gson.toJson(request);
 
@@ -93,8 +94,4 @@
             });
     }
 
-    private AsyncRestClient restClient() {
-        return new AsyncRestClient("", this.applicationConfig.getWebClientConfig());
-    }
-
 }
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java
index 164159b..ada16e2 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java
index 225b83a..2d4087f 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java
index 4e68c1a..28c40bf 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java
index 77439c5..42ab7cb 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java
index 1933c2b..80b6a80 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java
index dcddef3..a8e88d8 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java
index a08d52b..39796ee 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java
index 3111d10..47abcbb 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java
index 0d04115..3a2ab41 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java
index 9e56197..9722594 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java
index 8adff41..d67b8ed 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java
index 9a82161..f13f981 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java
index 19bb541..859443d 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java
index 3b62fa7..f239a48 100644
--- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java
+++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -21,6 +21,7 @@
 package org.oransc.enrichment.tasks;
 
 import org.oransc.enrichment.clients.AsyncRestClient;
+import org.oransc.enrichment.clients.AsyncRestClientFactory;
 import org.oransc.enrichment.configuration.ApplicationConfig;
 import org.oransc.enrichment.repository.EiJobs;
 import org.oransc.enrichment.repository.EiProducer;
@@ -45,17 +46,20 @@
 public class ProducerSupervision {
     private static final Logger logger = LoggerFactory.getLogger(ProducerSupervision.class);
 
-    @Autowired
-    ApplicationConfig applicationConfig;
+    private final EiProducers eiProducers;
+    private final EiJobs eiJobs;
+    private final EiTypes eiTypes;
+    private final AsyncRestClient restClient;
 
     @Autowired
-    EiProducers eiProducers;
-
-    @Autowired
-    EiJobs eiJobs;
-
-    @Autowired
-    EiTypes eiTypes;
+    public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs,
+        EiTypes eiTypes) {
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig());
+        this.restClient = restClientFactory.createRestClient("");
+        this.eiJobs = eiJobs;
+        this.eiProducers = eiProducers;
+        this.eiTypes = eiTypes;
+    }
 
     @Scheduled(fixedRate = 1000 * 60 * 5)
     public void checkAllProducers() {
@@ -69,7 +73,7 @@
     }
 
     private Mono<EiProducer> checkOneProducer(EiProducer producer) {
-        return restClient().get(producer.getProducerSupervisionCallbackUrl()) //
+        return restClient.get(producer.getProducerSupervisionCallbackUrl()) //
             .onErrorResume(throwable -> {
                 handleNonRespondingProducer(throwable, producer);
                 return Mono.empty();
@@ -91,8 +95,4 @@
         producer.setAliveStatus(true);
     }
 
-    private AsyncRestClient restClient() {
-        return new AsyncRestClient("", this.applicationConfig.getWebClientConfig());
-    }
-
 }
diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java
index 8b8cb67..e564fef 100644
--- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java
+++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -42,6 +42,7 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.oransc.enrichment.clients.AsyncRestClient;
+import org.oransc.enrichment.clients.AsyncRestClientFactory;
 import org.oransc.enrichment.clients.ProducerJobInfo;
 import org.oransc.enrichment.configuration.ApplicationConfig;
 import org.oransc.enrichment.configuration.ImmutableWebClientConfig;
@@ -601,7 +602,8 @@
             .trustStorePassword(config.trustStorePassword()) //
             .build();
 
-        return new AsyncRestClient(baseUrl(), config);
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config);
+        return restClientFactory.createRestClient(baseUrl());
     }
 
     private AsyncRestClient restClient() {
diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java
index fa11044..d51007b 100644
--- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java
+++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java
index e2273cf..f879c7b 100644
--- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java
+++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java
index 479c1b2..c465196 100644
--- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java
+++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at