From df74daf492f6c7293ff3b31b0aa99342a8e0295b Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Fri, 29 May 2020 17:08:54 +0100 Subject: SOL003 Adapter removing duplicate code Change-Id: Ibf6f2163516b852318b94510a793e25306a638b9 Issue-ID: SO-2771 Signed-off-by: waqas.ikram --- .../AbstractServiceProviderConfiguration.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java (limited to 'adapters/etsi-sol003-adapter/etsi-sol003-adapter-common') diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java new file mode 100644 index 0000000000..6161fa60f9 --- /dev/null +++ b/adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.etsi.sol003.adapter.common.configuration; + +import java.util.Iterator; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestTemplate; +import com.google.gson.Gson; + +/** + * A base class that can be extended by classes for configuring HttpRestServiceProvider classes. Provides common methods + * that will be useful to some such classes. + * + * @author gareth.roper@est.tech + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +public abstract class AbstractServiceProviderConfiguration { + + public void setGsonMessageConverter(final RestTemplate restTemplate) { + final Iterator> iterator = restTemplate.getMessageConverters().iterator(); + while (iterator.hasNext()) { + if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { + iterator.remove(); + } + } + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(getGson())); + } + + protected abstract Gson getGson(); + +} -- cgit 1.2.3-korg