Fix java check style warning
[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"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.apiroute;
15
16 import org.onap.msb.apiroute.health.ApiRouteHealthCheck;
17 import org.onap.msb.apiroute.resources.ApiRouteResource;
18 import org.onap.msb.apiroute.resources.CustomRouteResource;
19 import org.onap.msb.apiroute.resources.IuiRouteResource;
20 import org.onap.msb.apiroute.resources.MicroServiceResource;
21 import org.onap.msb.apiroute.wrapper.InitRouteServiceWrapper;
22 import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import com.fasterxml.jackson.annotation.JsonInclude;
27
28 import io.dropwizard.Application;
29 import io.dropwizard.assets.AssetsBundle;
30 import io.dropwizard.server.SimpleServerFactory;
31 import io.dropwizard.setup.Bootstrap;
32 import io.dropwizard.setup.Environment;
33 import io.swagger.jaxrs.config.BeanConfig;
34 import io.swagger.jaxrs.listing.ApiListingResource;
35
36 public class ApiRouteApp extends Application<ApiRouteAppConfig> {
37
38     private static final Logger LOGGER = LoggerFactory.getLogger(ApiRouteApp.class);
39
40     public static void main(String[] args) throws Exception {
41         new ApiRouteApp().run(args);
42
43         InitRouteServiceWrapper.getInstance().initFilterConfig();
44
45         InitRouteServiceWrapper.getInstance().initDataSynchro();
46
47         InitRouteServiceWrapper.getInstance().initHealthCheck();
48     }
49
50
51     @Override
52     public String getName() {
53         return " MicroService Bus ";
54     }
55
56     @Override
57     public void initialize(Bootstrap<ApiRouteAppConfig> bootstrap) {
58         super.initialize(bootstrap);
59
60     }
61
62     @Override
63     public void run(ApiRouteAppConfig configuration, Environment environment) throws Exception {
64
65
66         ConfigUtil.getInstance().initRootPath();
67
68
69         String iuiRootPath = ConfigUtil.getInstance().getIUI_ROOT_PATH();
70
71         // new AssetsBundle("/iui-metrics", "/"+iuiRootPath+"/microservices/metrics","index.html",
72         // "iui-metrics").run(environment);
73
74         new AssetsBundle("/iui-route", "/" + iuiRootPath + "/microservices", "index.html", "iui-microservices")
75                         .run(environment);
76
77         new AssetsBundle("/api-doc", "/" + iuiRootPath + "/microservices/api-doc", "index.html", "api-doc")
78                         .run(environment);
79
80         new AssetsBundle("/ext", "/" + iuiRootPath + "/microservices/ext", "index.html", "ext").run(environment);
81
82
83
84         final ApiRouteHealthCheck healthCheck = new ApiRouteHealthCheck();
85         environment.healthChecks().register("consulCheck", healthCheck);
86
87         environment.jersey().register(new ApiRouteResource());
88         environment.jersey().register(new IuiRouteResource());
89         environment.jersey().register(new CustomRouteResource());
90         environment.jersey().register(new MicroServiceResource());
91
92         // initSwaggerConfig(environment, configuration);
93
94         ConfigUtil.getInstance().initConsulIp();
95         ConfigUtil.getInstance().initDiscoverInfo(configuration);
96         // InitRouteServiceWrapper.getInstance().initMetricsConfig(configuration);
97
98
99     }
100
101
102
103     private void initSwaggerConfig(Environment environment, ApiRouteAppConfig configuration) {
104
105         environment.jersey().register(new ApiListingResource());
106         environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
107
108         BeanConfig config = new BeanConfig();
109         config.setTitle("ApiRoute RESTful API");
110         config.setVersion("1.0.0");
111         config.setResourcePackage("org.onap.msb.apiroute.resources");
112         SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory();
113         String basePath = simpleServerFactory.getApplicationContextPath();
114         String rootPath = simpleServerFactory.getJerseyRootPath();
115
116         rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
117
118         basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
119
120         LOGGER.warn("getApplicationContextPath: " + basePath);
121         config.setBasePath(basePath);
122         config.setScan(true);
123     }
124
125
126
127 }