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
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=========================================================
21 package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
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;
41 * @author waqas.ikram@est.tech
42 * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
45 public class CnfmHttpServiceConfiguration {
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";
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();
59 final RestTemplate restTemplate =
60 new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory));
61 restTemplate.getInterceptors().add(new SOSpringClientFilter());
62 restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
68 @Qualifier(CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN)
69 public HttpRestServiceProvider cnfmHttpRestServiceProvider(
70 @Qualifier(CNFM_REST_TEMPLATE_CLIENT_BEAN) @Autowired final RestTemplate restTemplate) {
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);
77 return new HttpRestServiceProviderImpl(restTemplate, hearders);