2 * Copyright 2016 [ZTE] 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.
16 package org.openo.carbon.bpel;
18 import io.dropwizard.Application;
19 import io.dropwizard.assets.AssetsBundle;
20 import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
21 import io.dropwizard.configuration.SubstitutingSourceProvider;
22 import io.dropwizard.server.SimpleServerFactory;
23 import io.dropwizard.setup.Bootstrap;
24 import io.dropwizard.setup.Environment;
25 import io.swagger.jaxrs.config.BeanConfig;
26 import io.swagger.jaxrs.listing.ApiListingResource;
28 import org.glassfish.jersey.media.multipart.MultiPartFeature;
29 import org.openo.carbon.bpel.common.Config;
30 import org.openo.carbon.bpel.common.ServiceRegistrer;
31 import org.openo.carbon.bpel.resources.BpsPackage;
32 import org.openo.carbon.bpel.resources.BpsProcess;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.fasterxml.jackson.annotation.JsonInclude;
40 public class Wso2BpelApplication extends Application<Wso2BpelConfiguration> {
41 private static final Logger LOGGER = LoggerFactory.getLogger(Wso2BpelApplication.class);
42 private static final String API_RESOURCE = "org.openo.carbon.bpel.resources";
44 public static void main(String[] args) throws Exception {
45 new Wso2BpelApplication().run(args);
50 public String getName() {
51 return "hello-wso2bpel";
55 public void initialize(Bootstrap<Wso2BpelConfiguration> bootstrap) {
56 bootstrap.setConfigurationSourceProvider(new SubstitutingSourceProvider(
57 bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
58 // binding jar static resource
59 bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
62 private void initService() {
63 Thread registerWso2bpelService = new Thread(new ServiceRegistrer());
64 registerWso2bpelService.setName("register wso2bpel service to Microservice Bus");
65 registerWso2bpelService.start();
71 public void run(Wso2BpelConfiguration configuration, Environment environment) {
72 environment.jersey().register(MultiPartFeature.class);
73 environment.jersey().register(new BpsPackage());
74 environment.jersey().register(new BpsProcess());
76 initSwaggerConfig(environment, configuration);
77 Config.setConfigration(configuration);
81 private void initSwaggerConfig(Environment environment, Wso2BpelConfiguration configuration) {
82 // register swagger scan class
83 environment.jersey().register(new ApiListingResource());
84 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
86 BeanConfig config = new BeanConfig();
87 config.setTitle(configuration.getApiDescription());
88 config.setVersion("1.0");
89 config.setResourcePackage(API_RESOURCE);
91 // read rootPath config from yml
92 SimpleServerFactory simpleServerFactory =
93 (SimpleServerFactory) configuration.getServerFactory();
94 String basePath = simpleServerFactory.getApplicationContextPath();
95 String rootPath = simpleServerFactory.getJerseyRootPath();
97 // set basepath for rest api
98 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
99 basePath = basePath.equals("/") ? rootPath
100 : (new StringBuilder()).append(basePath).append(rootPath).toString();
102 LOGGER.info("getApplicationContextPath:" + basePath);
103 config.setBasePath(basePath);
104 config.setScan(true);