2 * Copyright (c) 2017-2018 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the Apache License, Version 2.0
5 * and the Eclipse Public License v1.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial API and implementation and/or initial documentation
13 package org.onap.sdc.workflowdesigner;
15 import org.glassfish.jersey.media.multipart.MultiPartFeature;
16 import org.onap.sdc.workflowdesigner.config.AppConfig;
17 import org.onap.sdc.workflowdesigner.resources.ExtendActivityResource;
18 import org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.fasterxml.jackson.annotation.JsonInclude;
24 import io.dropwizard.Application;
25 import io.dropwizard.assets.AssetsBundle;
26 import io.dropwizard.server.SimpleServerFactory;
27 import io.dropwizard.setup.Bootstrap;
28 import io.dropwizard.setup.Environment;
29 import io.swagger.jaxrs.config.BeanConfig;
30 import io.swagger.jaxrs.listing.ApiListingResource;
32 public class WorkflowDesignerApp extends Application<WorkflowDesignerConfiguration> {
33 private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowDesignerApp.class);
35 public static void main(String[] args) throws Exception {
36 new WorkflowDesignerApp().run(args);
40 public String getName() {
41 return "Workflow Designer";
45 public void initialize(Bootstrap<WorkflowDesignerConfiguration> bootstrap) {
46 bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
47 bootstrap.addBundle(new AssetsBundle("/workflow-modeler", "/workflow-modeler", "index.html",
49 bootstrap.addBundle(new AssetsBundle("/workflow-modeler", "/", "index.html", "ng"));
53 public void run(WorkflowDesignerConfiguration configuration, Environment environment) {
54 LOGGER.info("Start to initialize Workflow Designer.");
56 AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
58 environment.jersey().register(new WorkflowModelerResource());
59 environment.jersey().register(new ExtendActivityResource());
61 // register rest interface
62 environment.jersey().packages("org.onap.sdc.workflowdesigner.resources");
63 // upload file by inputstream need to register MultiPartFeature
64 environment.jersey().register(MultiPartFeature.class);
66 initSwaggerConfig(environment, configuration);
68 LOGGER.info("Initialize catalogue finished.");
72 * initialize swagger configuration.
74 * @param environment environment information
75 * @param configuration catalogue configuration
77 private void initSwaggerConfig(Environment environment,
78 WorkflowDesignerConfiguration configuration) {
79 environment.jersey().register(new ApiListingResource());
80 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
82 BeanConfig config = new BeanConfig();
83 config.setTitle("Workflow Designer rest API");
84 config.setVersion("1.0.0");
85 config.setResourcePackage("org.onap.sdc.workflowdesigner.resources");
87 // set rest api basepath in swagger
88 SimpleServerFactory simpleServerFactory =
89 (SimpleServerFactory) configuration.getServerFactory();
90 String basePath = simpleServerFactory.getApplicationContextPath();
91 String rootPath = simpleServerFactory.getJerseyRootPath().get();
92 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
93 basePath = basePath.equals("/") ? rootPath
94 : (new StringBuilder()).append(basePath).append(rootPath).toString();
95 config.setBasePath(basePath);