2 * Copyright 2016-2017 ZTE Corporation.
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.
16 package org.onap.aai.esr;
18 import com.fasterxml.jackson.annotation.JsonInclude;
19 import io.dropwizard.Application;
20 import io.dropwizard.assets.AssetsBundle;
21 import io.dropwizard.server.SimpleServerFactory;
22 import io.dropwizard.setup.Bootstrap;
23 import io.dropwizard.setup.Environment;
24 import io.swagger.jaxrs.config.BeanConfig;
25 import io.swagger.jaxrs.listing.ApiListingResource;
27 import org.glassfish.jersey.media.multipart.MultiPartFeature;
28 import org.onap.aai.esr.common.Config;
29 import org.onap.aai.esr.externalservice.msb.MsbHelper;
30 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
36 private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
38 public static void main(String[] args) throws Exception {
39 new ExtsysApp().run(args);
43 public String getName() {
49 public void initialize(Bootstrap<ExtsysAppConfiguration> bootstrap) {
50 bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
54 public void run(ExtsysAppConfiguration configuration, Environment environment) {
55 LOGGER.info("Start to initialize esr.");
56 environment.jersey().packages("org.onap.aai.esr.resource");
57 environment.jersey().register(MultiPartFeature.class);
58 String MSB_IP=configuration.getMsbIp();
59 int MSB_Port=configuration.getMsbPort();
61 initSwaggerConfig(environment, configuration);
62 Config.setConfigration(configuration);
63 MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
65 MsbHelper helper = new MsbHelper(msbClient);
68 } catch (Exception e) {
69 LOGGER.error("Register ESR to msb failed", e);
72 LOGGER.info("Initialize extsys finished.");
76 * initialize swagger configuration.
78 * @param environment environment information
79 * @param configuration configuration
81 private void initSwaggerConfig(Environment environment, ExtsysAppConfiguration configuration) {
82 environment.jersey().register(new ApiListingResource());
83 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
85 BeanConfig config = new BeanConfig();
86 config.setTitle("Open-o ExtSys Service rest API");
87 config.setVersion("1.0.0");
88 config.setResourcePackage("org.onap.aai.esr.resource");
89 // set rest api basepath in swagger
90 SimpleServerFactory simpleServerFactory =
91 (SimpleServerFactory) configuration.getServerFactory();
92 String basePath = simpleServerFactory.getApplicationContextPath();
93 String rootPath = simpleServerFactory.getJerseyRootPath();
94 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
95 basePath = basePath.equals("/") ? rootPath
96 : (new StringBuilder()).append(basePath).append(rootPath).toString();
97 config.setBasePath(basePath);