From 4d2e296cb512550448d7b0114ffdbdc6f3174b19 Mon Sep 17 00:00:00 2001 From: "Kumar, Amaresh (ak583p)" Date: Thu, 10 May 2018 14:35:25 +0530 Subject: initial commit for CDT proxy Service Initial commit for CDT proxy server to fix CORS Issues. Issue-ID: APPC-885 Change-Id: Idf2688dbca3fd6c25636544147ed5b23a5a4ed7f Signed-off-by: Kumar, Amaresh (ak583p) --- .../org/onap/appc/cdt/service/MainApplication.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 CdtProxyService/src/main/java/org/onap/appc/cdt/service/MainApplication.java (limited to 'CdtProxyService/src/main/java/org/onap/appc/cdt/service/MainApplication.java') diff --git a/CdtProxyService/src/main/java/org/onap/appc/cdt/service/MainApplication.java b/CdtProxyService/src/main/java/org/onap/appc/cdt/service/MainApplication.java new file mode 100644 index 0000000..c160519 --- /dev/null +++ b/CdtProxyService/src/main/java/org/onap/appc/cdt/service/MainApplication.java @@ -0,0 +1,79 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software 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. + +============LICENSE_END============================================ +*/ +package org.onap.appc.cdt.service; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +/** + * Created by Amaresh Kumar on 09/May/2018. + */ + +@EnableAutoConfiguration +@Configuration +@ComponentScan +public class MainApplication { + + public static void main(String args[]) { + SpringApplication.run(MainApplication.class, args); + } + + @Bean + public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { + MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + jsonConverter.setObjectMapper(objectMapper); + return jsonConverter; + } + + @Bean + public StringHttpMessageConverter stringHttpMessageConverter() { + StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(); + stringHttpMessageConverter.setWriteAcceptCharset(true); + return stringHttpMessageConverter; + } + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurerAdapter() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE"); + } + }; + } +} -- cgit 1.2.3-korg