2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2020 Ericsson. All rights reserved.
 
   4  * ================================================================================
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  20 package org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement;
 
  22 import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
 
  23 import java.nio.charset.StandardCharsets;
 
  24 import org.apache.commons.codec.binary.Base64;
 
  25 import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
 
  26 import org.onap.so.configuration.rest.HttpHeadersProvider;
 
  27 import org.onap.so.rest.service.HttpRestServiceProvider;
 
  28 import org.onap.so.rest.service.HttpRestServiceProviderImpl;
 
  29 import org.springframework.beans.factory.annotation.Autowired;
 
  30 import org.springframework.beans.factory.annotation.Qualifier;
 
  31 import org.springframework.web.client.RestTemplate;
 
  34  * A base class that can be extended by classes for providing notification services. Provides common methods that will
 
  35  * be useful to those classes.
 
  37  * @author Waqas Ikram (waqas.ikram@est.tech)
 
  38  * @author Andrew Lamb (andrew.a.lamb@est.tech)
 
  40 public abstract class AbstractNotificationServiceProvider {
 
  43     @Qualifier(CONFIGURABLE_REST_TEMPLATE)
 
  44     private RestTemplate restTemplate;
 
  46     protected HttpRestServiceProvider getHttpRestServiceProvider(final HttpHeadersProvider httpHeadersProvider) {
 
  47         final HttpRestServiceProvider httpRestServiceProvider =
 
  48                 new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
 
  49         return httpRestServiceProvider;
 
  52     protected BasicHttpHeadersProvider getBasicHttpHeadersProviderWithBasicAuth(final String username,
 
  53             final String password) {
 
  54         final byte[] encodedAuth = getBasicAuth(username, password);
 
  55         final String authHeader = "Basic " + new String(encodedAuth);
 
  56         return new BasicHttpHeadersProvider(authHeader);
 
  59     protected byte[] getBasicAuth(final String username, final String password) {
 
  60         final String auth = username + ":" + password;
 
  61         return Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));