From c6bfa3a1cfa20c0a885408c0eef23525d98679d4 Mon Sep 17 00:00:00 2001 From: hanyanan Date: Tue, 19 Sep 2017 15:21:44 +0800 Subject: [PATCH] Issue-ID:VFC-384 Change-Id: Iee553283ae9926800f697c3d1b7aecc30531c6a7 Signed-off-by: hanyanan --- ems/boco/pom.xml | 49 +++++++++++++++++++--- .../vfc/nfvo/emsdriver/EmsDriverApplication.java | 26 ++++++++++++ .../northbound/service/CommandResource.java | 6 +++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/ems/boco/pom.xml b/ems/boco/pom.xml index ac890c5..413cff0 100644 --- a/ems/boco/pom.xml +++ b/ems/boco/pom.xml @@ -31,6 +31,8 @@ UTF-8 + 2.16 + 1.5.3 @@ -159,16 +161,53 @@ dropwizard-core 1.0.6 + + io.dropwizard + dropwizard-assets + 1.0.5 + org.apache.httpcomponents httpclient 4.5.2 - - junit - junit - 4.12 - test + + org.glassfish.jersey.media + jersey-media-multipart + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-servlet + 2.16 + + + org.glassfish.jersey.core + jersey-client + 2.16 + + org.glassfish.jersey.core + jersey-common + 2.16 + + + junit + junit + 4.12 + test + + + io.swagger + swagger-jersey2-jaxrs + ${swagger.version} + diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java index dabf203..6ae160f 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java @@ -16,11 +16,14 @@ package org.onap.vfc.nfvo.emsdriver; import io.dropwizard.Application; +import io.dropwizard.assets.AssetsBundle; import io.dropwizard.jetty.HttpConnectorFactory; import io.dropwizard.server.DefaultServerFactory; import io.dropwizard.server.SimpleServerFactory; import io.dropwizard.setup.Bootstrap; import io.dropwizard.setup.Environment; +import io.swagger.jaxrs.config.BeanConfig; +import io.swagger.jaxrs.listing.ApiListingResource; import java.net.InetAddress; import java.net.UnknownHostException; @@ -39,6 +42,8 @@ import org.onap.vfc.nfvo.emsdriver.serviceregister.model.ServiceNodeVo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; +import com.fasterxml.jackson.annotation.JsonInclude; + public class EmsDriverApplication extends Application { protected static Log log = LogFactory.getLog(EmsDriverApplication.class); @@ -57,6 +62,7 @@ public class EmsDriverApplication extends Application { public void initialize(Bootstrap bootstrap) { // nothing to do yet context = new FileSystemXmlApplicationContext("file:" + Constant.SYS_CFG+ "spring.xml"); + bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc")); } @Override @@ -71,6 +77,7 @@ public class EmsDriverApplication extends Application { } //Start workThread this.startThread(); + initSwaggerConfig(environment, configuration); } private void startThread(){ @@ -86,7 +93,26 @@ public class EmsDriverApplication extends Application { thread.start(); } } + // init swagger + private void initSwaggerConfig(Environment environment, EmsDriverConfiguration configuration) + { + environment.jersey().register(new ApiListingResource()); + environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); + BeanConfig config = new BeanConfig(); + config.setTitle(" Console Service rest API"); + config.setVersion("1.0.0"); + config.setResourcePackage("org.onap.vfc.nfvo.emsdriver.northbound.service"); + //swagger rest api basepath + SimpleServerFactory simpleServerFactory = (SimpleServerFactory)configuration.getServerFactory(); + String basePath = simpleServerFactory.getApplicationContextPath(); + String rootPath = simpleServerFactory.getJerseyRootPath().get(); + rootPath = rootPath.substring(0, rootPath.indexOf("/*")); + basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString(); + config.setBasePath(basePath); + config.setScan(true); + } + private void msbRegisteEmsDriverService(EmsDriverConfiguration configuration) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory)configuration.getServerFactory(); HttpConnectorFactory connector = (HttpConnectorFactory)simpleServerFactory.getConnector(); diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResource.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResource.java index 4a807b8..44c23b4 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResource.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResource.java @@ -15,21 +15,27 @@ */ package org.onap.vfc.nfvo.emsdriver.northbound.service; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import com.codahale.metrics.annotation.Timed; @Path("/ems-driver") @Produces(MediaType.APPLICATION_JSON) +@Api(tags = {"ems-driver TestResource"}) public class CommandResource { @GET @Timed + @ApiOperation(value = "get ems-driver Info") public String executeCommand(@QueryParam("command") String command) { System.out.println("receiver command = "+command); -- 2.16.6