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=b04619e33670546873572d369390a2a604d8ad30;hb=0b80343610a215f26a7d764cc849f8e9ca44fea0;hp=c4e82d3290d32cd5c34c67058c69748aa4327d65;hpb=cf2482c1fa1b7b9d9638e7c658807e8ab35069b4;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 c4e82d329..b04619e33 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,11 +20,16 @@ package org.onap.cps.ncmp.api.impl.config; +import java.util.Arrays; import lombok.Getter; 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.stereotype.Component; import org.springframework.web.client.RestTemplate; @@ -38,10 +43,29 @@ public class NcmpConfiguration { private String authUsername; @Value("${dmi.auth.password}") private String authPassword; + @Value("${dmi.api.base-path}") + 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); } }