e073e34e0924665e6fc3c8d97f3eb75cf0545095
[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 java.util.logging.Logger;
21
22 import javax.annotation.PostConstruct;
23 import javax.ws.rs.ApplicationPath;
24 import javax.ws.rs.client.Client;
25 import javax.ws.rs.client.ClientBuilder;
26
27 import org.glassfish.jersey.client.ClientConfig;
28 import org.glassfish.jersey.logging.LoggingFeature;
29 import org.glassfish.jersey.server.ResourceConfig;
30 import org.glassfish.jersey.servlet.ServletProperties;
31 import org.onap.sdnc.apps.pomba.networkdiscovery.service.rs.RestService;
32 import org.onap.sdnc.apps.pomba.networkdiscovery.service.rs.RestServiceImpl;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.Bean;
35 import org.springframework.stereotype.Component;
36
37 import io.swagger.jaxrs.config.BeanConfig;
38 import io.swagger.jaxrs.listing.ApiListingResource;
39 import io.swagger.jaxrs.listing.SwaggerSerializers;
40
41 @Component
42 @ApplicationPath("/")
43 public class JerseyConfiguration extends ResourceConfig {
44     
45     public static final String SERVICE_NAME = "network-discovery";
46
47     private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName());
48     
49     @Autowired
50     public JerseyConfiguration() {
51         register(RestServiceImpl.class);
52         property(ServletProperties.FILTER_FORWARD_ON_404, true);
53         register(new LoggingFeature(log));
54     }
55
56     @Bean
57     public Client jerseyClient() {
58         return ClientBuilder.newClient(new ClientConfig());
59     }
60     
61     @PostConstruct
62     public void init() {
63         // Register components where DI is needed
64         this.configureSwagger();
65     }
66
67     private void configureSwagger() {
68         // Available at localhost:port/swagger.json
69         this.register(ApiListingResource.class);
70         this.register(SwaggerSerializers.class);
71
72         BeanConfig config = new BeanConfig();
73         config.setTitle("Network Discovery Swagger");
74         config.setVersion("v1");
75         config.setSchemes(new String[] { "https", "http" });
76         config.setBasePath("/" + SERVICE_NAME);
77         config.setResourcePackage(RestService.class.getPackage().getName());
78         config.setPrettyPrint(true);
79         config.setScan(true);
80     }
81     
82 }