[SO] Create changes for SO-API and BPMN-INFRA to support CNF's through ASD
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / cnfm / tasks / CnfmHttpServiceConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 Nordix Foundation.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
22
23 import javax.ws.rs.core.MediaType;
24 import org.onap.logging.filter.spring.SpringClientPayloadFilter;
25 import org.onap.so.configuration.rest.HttpComponentsClientConfiguration;
26 import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
27 import org.onap.so.rest.service.HttpRestServiceProvider;
28 import org.onap.so.rest.service.HttpRestServiceProviderImpl;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Qualifier;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Configuration;
35 import org.springframework.http.HttpHeaders;
36 import org.springframework.http.client.BufferingClientHttpRequestFactory;
37 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
38 import org.springframework.web.client.RestTemplate;
39
40 /**
41  * @author waqas.ikram@est.tech
42  * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
43  */
44 @Configuration
45 public class CnfmHttpServiceConfiguration {
46
47     private static final Logger logger = LoggerFactory.getLogger(CnfmHttpServiceConfiguration.class);
48     public static final String CNFM_REST_TEMPLATE_CLIENT_BEAN = "cnfmRestTemplateBean";
49     public static final String CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN = "cnfmHttpRestServiceProvider";
50
51     @Bean
52     @Qualifier(CNFM_REST_TEMPLATE_CLIENT_BEAN)
53     public RestTemplate cnfmRestTemplateBean(
54             @Autowired final HttpComponentsClientConfiguration httpComponentsClientConfiguration) {
55         logger.debug("Setting up cnfm RestTemplate bean...");
56         final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
57                 httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory();
58
59         final RestTemplate restTemplate =
60                 new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory));
61         restTemplate.getInterceptors().add(new SOSpringClientFilter());
62         restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
63         return restTemplate;
64
65     }
66
67     @Bean
68     @Qualifier(CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN)
69     public HttpRestServiceProvider cnfmHttpRestServiceProvider(
70             @Qualifier(CNFM_REST_TEMPLATE_CLIENT_BEAN) @Autowired final RestTemplate restTemplate) {
71
72         logger.debug("Setting up cnfm HttpRestServiceProvider bean...");
73         final HttpHeaders hearders = new HttpHeaders();
74         hearders.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
75         hearders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
76
77         return new HttpRestServiceProviderImpl(restTemplate, hearders);
78     }
79
80 }