Add license header for java files
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / ApiRouteApp.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
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 package org.onap.msb.apiroute;
17 import io.dropwizard.Application;
18 import io.dropwizard.assets.AssetsBundle;
19 import io.dropwizard.server.SimpleServerFactory;
20 import io.dropwizard.setup.Bootstrap;
21 import io.dropwizard.setup.Environment;
22 import io.swagger.jaxrs.config.BeanConfig;
23 import io.swagger.jaxrs.listing.ApiListingResource;
24
25 import org.onap.msb.apiroute.health.ApiRouteHealthCheck;
26 import org.onap.msb.apiroute.resources.ApiRouteResource;
27 import org.onap.msb.apiroute.resources.CustomRouteResource;
28 import org.onap.msb.apiroute.resources.IuiRouteResource;
29 import org.onap.msb.apiroute.resources.MicroServiceResource;
30 import org.onap.msb.apiroute.wrapper.InitRouteServiceWrapper;
31 import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 import com.fasterxml.jackson.annotation.JsonInclude;
36
37 public class ApiRouteApp extends Application<ApiRouteAppConfig> {
38
39     private static final Logger LOGGER = LoggerFactory.getLogger(ApiRouteApp.class);
40
41     public static void main(String[] args) throws Exception {
42         new ApiRouteApp().run(args);
43         
44         InitRouteServiceWrapper.getInstance().initFilterConfig();
45         
46         InitRouteServiceWrapper.getInstance().initDataSynchro();
47         
48         InitRouteServiceWrapper.getInstance().initHealthCheck();
49     }
50
51
52     @Override
53     public String getName() {
54         return " MicroService Bus ";
55     }
56
57     @Override
58     public void initialize(Bootstrap<ApiRouteAppConfig> bootstrap) {
59       super.initialize(bootstrap);
60         
61     }
62
63     @Override
64     public void run(ApiRouteAppConfig configuration, Environment environment) throws Exception {
65      
66    
67       ConfigUtil.getInstance().initRootPath();
68      
69       
70        String iuiRootPath=ConfigUtil.getInstance().getIUI_ROOT_PATH();
71       
72         // new AssetsBundle("/iui-metrics", "/"+iuiRootPath+"/microservices/metrics","index.html", "iui-metrics").run(environment); 
73         
74         new AssetsBundle("/iui-route",  "/"+iuiRootPath+"/microservices", "index.html","iui-microservices").run(environment); 
75         
76         new AssetsBundle("/api-doc",  "/"+iuiRootPath+"/microservices/api-doc","index.html", "api-doc").run(environment);
77         
78         new AssetsBundle("/ext",  "/"+iuiRootPath+"/microservices/ext","index.html", "ext").run(environment);
79         
80         
81         
82
83         final ApiRouteHealthCheck healthCheck =new ApiRouteHealthCheck();
84         environment.healthChecks().register("consulCheck", healthCheck);
85         
86         environment.jersey().register(new ApiRouteResource());
87         environment.jersey().register(new IuiRouteResource());   
88         environment.jersey().register(new CustomRouteResource());
89         environment.jersey().register(new MicroServiceResource());
90         
91         // initSwaggerConfig(environment, configuration);
92         
93         ConfigUtil.getInstance().initConsulIp();
94         ConfigUtil.getInstance().initDiscoverInfo(configuration);
95         // InitRouteServiceWrapper.getInstance().initMetricsConfig(configuration);
96         
97         
98     }
99     
100
101     
102     
103
104
105     private void initSwaggerConfig(Environment environment, ApiRouteAppConfig configuration) {
106
107         environment.jersey().register(new ApiListingResource());
108         environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
109
110         BeanConfig config = new BeanConfig();
111         config.setTitle("ApiRoute RESTful API");
112         config.setVersion("1.0.0");
113         config.setResourcePackage("org.onap.msb.apiroute.resources");
114         SimpleServerFactory simpleServerFactory =(SimpleServerFactory) configuration.getServerFactory();
115         String basePath = simpleServerFactory.getApplicationContextPath();
116         String rootPath = simpleServerFactory.getJerseyRootPath();
117
118         rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
119
120         basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
121
122         LOGGER.warn("getApplicationContextPath: " + basePath);
123         config.setBasePath(basePath);
124         config.setScan(true);
125     }
126     
127
128    
129
130 }