X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2Fconfig%2FNcmpConfiguration.java;h=af33651ebee89aec85f6ef2226482e6f65a46685;hb=324eb16687756f1850ffa484f652e117878cf33f;hp=81c9dff40255cea3eb87ded5ee8f8217d0b9e6d0;hpb=7c483c72e3643abb0d425f0092c15310c5359276;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java index 81c9dff40..af33651eb 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,25 @@ package org.onap.cps.ncmp.api.impl.config; +import java.util.Arrays; +import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +@EnableScheduling @Configuration +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class NcmpConfiguration { @Getter @@ -42,8 +52,26 @@ public class NcmpConfiguration { private String dmiBasePath; } + /** + * Rest template bean. + * + * @param restTemplateBuilder the rest template builder + * @return rest template instance + */ @Bean + @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) { - return restTemplateBuilder.build(); + final RestTemplate restTemplate = restTemplateBuilder.build(); + setRestTemplateMessageConverters(restTemplate); + return restTemplate; } + + private static void setRestTemplateMessageConverters(final RestTemplate restTemplate) { + final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = + new MappingJackson2HttpMessageConverter(); + mappingJackson2HttpMessageConverter.setSupportedMediaTypes( + Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)); + restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter); + } + }