2 * Copyright 2016 ZTE, Inc. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.msb.apiroute;
18 import io.dropwizard.Application;
19 import io.dropwizard.assets.AssetsBundle;
20 import io.dropwizard.server.SimpleServerFactory;
21 import io.dropwizard.setup.Bootstrap;
22 import io.dropwizard.setup.Environment;
23 import io.swagger.jaxrs.config.BeanConfig;
24 import io.swagger.jaxrs.listing.ApiListingResource;
26 import org.onap.msb.apiroute.health.ApiRouteHealthCheck;
27 import org.onap.msb.apiroute.resources.ApiRouteResource;
28 import org.onap.msb.apiroute.resources.CustomRouteResource;
29 import org.onap.msb.apiroute.resources.IuiRouteResource;
30 import org.onap.msb.apiroute.resources.MicroServiceResource;
31 import org.onap.msb.apiroute.wrapper.InitRouteServiceWrapper;
32 import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.fasterxml.jackson.annotation.JsonInclude;
38 public class ApiRouteApp extends Application<ApiRouteAppConfig> {
40 private static final Logger LOGGER = LoggerFactory.getLogger(ApiRouteApp.class);
42 public static void main(String[] args) throws Exception {
43 new ApiRouteApp().run(args);
45 InitRouteServiceWrapper.getInstance().initFilterConfig();
47 InitRouteServiceWrapper.getInstance().initDataSynchro();
49 InitRouteServiceWrapper.getInstance().initHealthCheck();
54 public String getName() {
55 return " MicroService Bus ";
59 public void initialize(Bootstrap<ApiRouteAppConfig> bootstrap) {
60 super.initialize(bootstrap);
65 public void run(ApiRouteAppConfig configuration, Environment environment) throws Exception {
68 ConfigUtil.getInstance().initRootPath();
71 String iuiRootPath=ConfigUtil.getInstance().getIUI_ROOT_PATH();
73 // new AssetsBundle("/iui-metrics", "/"+iuiRootPath+"/microservices/metrics","index.html", "iui-metrics").run(environment);
75 new AssetsBundle("/iui-route", "/"+iuiRootPath+"/microservices", "index.html","iui-microservices").run(environment);
77 new AssetsBundle("/api-doc", "/"+iuiRootPath+"/microservices/api-doc","index.html", "api-doc").run(environment);
79 new AssetsBundle("/ext", "/"+iuiRootPath+"/microservices/ext","index.html", "ext").run(environment);
84 final ApiRouteHealthCheck healthCheck =new ApiRouteHealthCheck();
85 environment.healthChecks().register("consulCheck", healthCheck);
87 environment.jersey().register(new ApiRouteResource());
88 environment.jersey().register(new IuiRouteResource());
89 environment.jersey().register(new CustomRouteResource());
90 environment.jersey().register(new MicroServiceResource());
92 // initSwaggerConfig(environment, configuration);
94 ConfigUtil.getInstance().initConsulIp();
95 ConfigUtil.getInstance().initDiscoverInfo(configuration);
96 // InitRouteServiceWrapper.getInstance().initMetricsConfig(configuration);
106 private void initSwaggerConfig(Environment environment, ApiRouteAppConfig configuration) {
108 environment.jersey().register(new ApiListingResource());
109 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
111 BeanConfig config = new BeanConfig();
112 config.setTitle("ApiRoute RESTful API");
113 config.setVersion("1.0.0");
114 config.setResourcePackage("org.onap.msb.apiroute.resources");
115 SimpleServerFactory simpleServerFactory =(SimpleServerFactory) configuration.getServerFactory();
116 String basePath = simpleServerFactory.getApplicationContextPath();
117 String rootPath = simpleServerFactory.getJerseyRootPath();
119 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
121 basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
123 LOGGER.warn("getApplicationContextPath: " + basePath);
124 config.setBasePath(basePath);
125 config.setScan(true);