1b5f034a95e8817fc64d04024abe4dfb16ebefc6
[music.git] / src / main / java / org / onap / music / JerseyConfig.java
1 /*
2  * Copyright 2012-2015 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.music;
18
19 import io.swagger.jaxrs.config.BeanConfig;
20 import io.swagger.jaxrs.listing.ApiListingResource;
21 import io.swagger.jaxrs.listing.SwaggerSerializers;
22 import org.glassfish.jersey.server.ResourceConfig;
23 import org.onap.music.rest.*;
24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.stereotype.Component;
26
27 import javax.annotation.PostConstruct;
28
29 @Component public class JerseyConfig extends ResourceConfig {
30
31     @Value("${spring.jersey.application-path:/}") private String apiPath;
32
33     public JerseyConfig() {
34         this.registerEndpoints();
35     }
36
37     @PostConstruct public void init() {
38         this.configureSwagger();
39     }
40
41     private void registerEndpoints() {
42         register(RestMusicAdminAPI.class);
43         register(RestMusicDataAPI.class);
44         register(RestMusicLocksAPI.class);
45         register(RestMusicQAPI.class);
46         register(RestMusicTestAPI.class);
47         register(RestMusicVersionAPI.class);
48         register(RestMusicHealthCheckAPI.class);
49     }
50
51     private void configureSwagger() {
52         //Available at localhost:port/swagger.json
53         this.register(ApiListingResource.class);
54         this.register(SwaggerSerializers.class);
55
56         BeanConfig config = new BeanConfig();
57         config.setConfigId("MUSIC");
58         config.setTitle("MUSIC");
59         config.setVersion("v2");
60         config.setContact("Thomas Nelson");
61         config.setSchemes(new String[] {"http", "https"});
62         config.setBasePath("/MUSIC/rest");
63         config.setResourcePackage("org.onap.music");
64         config.setPrettyPrint(true);
65         config.setScan(true);
66     }
67
68 }