Update INFO.yaml
[appc/cdt.git] / CdtProxyService / src / main / java / org / onap / appc / cdt / service / MainApplication.java
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 ============LICENSE_END============================================
21 */
22 package org.onap.appc.cdt.service;
23
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.SerializationFeature;
27 import org.springframework.boot.SpringApplication;
28 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29 import org.springframework.context.annotation.Bean;
30 import org.springframework.context.annotation.ComponentScan;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.http.converter.StringHttpMessageConverter;
33 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
34 import org.springframework.web.servlet.config.annotation.CorsRegistry;
35 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
36 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
37
38 /**
39  * Created by Amaresh Kumar on 09/May/2018.
40  */
41
42 @EnableAutoConfiguration
43 @Configuration
44 @ComponentScan
45 public class MainApplication {
46
47     public static void main(String args[]) {
48         SpringApplication.run(MainApplication.class, args);
49     }
50
51     @Bean
52     public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
53         MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
54         ObjectMapper objectMapper = new ObjectMapper();
55         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
56         objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
57         jsonConverter.setObjectMapper(objectMapper);
58         return jsonConverter;
59     }
60
61     @Bean
62     public StringHttpMessageConverter stringHttpMessageConverter() {
63         StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
64         stringHttpMessageConverter.setWriteAcceptCharset(true);
65          return stringHttpMessageConverter;
66     }
67
68     @Bean
69     public WebMvcConfigurer corsConfigurer() {
70         return new WebMvcConfigurerAdapter() {
71             @Override
72             public void addCorsMappings(CorsRegistry registry) {
73                 registry.addMapping("/**")
74                         .allowedOrigins("*")
75                         .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE");
76             }
77         };
78     }
79 }