5d93f64917c5d1133ccd1b8ed1d70c916624a528
[sdnc/apps.git] /
1 /*
2  * ============LICENSE_START===================================================
3  * Copyright (c) 2018 Amdocs
4  * ============================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=====================================================
17  */
18 package org.onap.sdnc.apps.pomba.networkdiscovery;
19
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import com.fasterxml.jackson.databind.DeserializationFeature;
22 import com.fasterxml.jackson.databind.MapperFeature;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.fasterxml.jackson.databind.SerializationFeature;
25 import java.util.logging.Logger;
26 import javax.ws.rs.ApplicationPath;
27 import javax.ws.rs.client.Client;
28 import javax.ws.rs.client.ClientBuilder;
29 import org.glassfish.jersey.client.ClientConfig;
30 import org.glassfish.jersey.filter.LoggingFilter;
31 import org.glassfish.jersey.server.ResourceConfig;
32 import org.glassfish.jersey.servlet.ServletProperties;
33 import org.onap.sdnc.apps.pomba.networkdiscovery.service.rs.RestServiceImpl;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Bean;
36 import org.springframework.context.annotation.Primary;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 @ApplicationPath("/")
41 public class JerseyConfiguration extends ResourceConfig {
42     private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName());
43
44     @Bean
45     @Primary
46     public ObjectMapper objectMapper() {
47         ObjectMapper objectMapper = new ObjectMapper();
48         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
49         objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
50         objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
51         objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
52         return objectMapper;
53     }
54
55     @Autowired
56     public JerseyConfiguration() {
57         register(RestServiceImpl.class);
58         property(ServletProperties.FILTER_FORWARD_ON_404, true);
59         register(new LoggingFilter(log, true));
60     }
61
62     @Bean
63     public Client jerseyClient() {
64         return ClientBuilder.newClient(new ClientConfig());
65     }
66 }