b3118469e0a8a4102599a47a10d8ff411608c822
[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.exceptions.MusicExceptionMapper;
24 import org.onap.music.rest.*;
25 import org.springframework.beans.factory.annotation.Value;
26 import org.springframework.stereotype.Component;
27
28 import javax.annotation.PostConstruct;
29
30 @Component public class JerseyConfig extends ResourceConfig {
31
32     @Value("${spring.jersey.application-path:/}") private String apiPath;
33
34     public JerseyConfig() {
35         this.registerEndpoints();
36         register(MusicExceptionMapper.class);
37     }
38
39     @PostConstruct public void init() {
40         this.configureSwagger();
41     }
42
43     private void registerEndpoints() {
44         register(RestMusicAdminAPI.class);
45         register(RestMusicDataAPI.class);
46         register(RestMusicLocksAPI.class);
47         register(RestMusicQAPI.class);
48         register(RestMusicTestAPI.class);
49         register(RestMusicVersionAPI.class);
50         register(RestMusicHealthCheckAPI.class);
51     }
52
53     private void configureSwagger() {
54         //Available at localhost:port/swagger.json
55         this.register(ApiListingResource.class);
56         this.register(SwaggerSerializers.class);
57
58         BeanConfig config = new BeanConfig();
59         config.setConfigId("MUSIC");
60         config.setTitle("MUSIC");
61         config.setVersion("v2");
62         config.setContact("Thomas Nelson");
63         config.setSchemes(new String[] {"http", "https"});
64         config.setBasePath("/MUSIC/rest");
65         config.setResourcePackage("org.onap.music");
66         config.setPrettyPrint(true);
67         config.setScan(true);
68     }
69
70 }