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