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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
18 package org.onap.sdnc.apps.pomba.networkdiscovery;
20 import java.util.logging.Logger;
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;
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;
37 import io.swagger.jaxrs.config.BeanConfig;
38 import io.swagger.jaxrs.listing.ApiListingResource;
39 import io.swagger.jaxrs.listing.SwaggerSerializers;
43 public class JerseyConfiguration extends ResourceConfig {
45 public static final String SERVICE_NAME = "network-discovery";
47 private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName());
50 public JerseyConfiguration() {
51 register(RestServiceImpl.class);
52 property(ServletProperties.FILTER_FORWARD_ON_404, true);
53 register(new LoggingFeature(log));
57 public Client jerseyClient() {
58 return ClientBuilder.newClient(new ClientConfig());
63 // Register components where DI is needed
64 this.configureSwagger();
67 private void configureSwagger() {
68 // Available at localhost:port/swagger.json
69 this.register(ApiListingResource.class);
70 this.register(SwaggerSerializers.class);
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);