From 466ed7575923331922a6a131bba5228b5766e21a Mon Sep 17 00:00:00 2001 From: Michael O'Brien Date: Sun, 6 Sep 2020 19:05:33 -0400 Subject: [PATCH] #2 - add swagger2 --- reference-nbi/pom.xml | 19 +++++++++-- .../reference/nbi/Base64Filter.java | 33 +++++++++++-------- .../reference/nbi/SwaggerConfig.java | 26 +++++++++++++++ .../src/main/resources/application.properties | 1 + 4 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 reference-nbi/src/main/java/cloud/containerization/reference/nbi/SwaggerConfig.java diff --git a/reference-nbi/pom.xml b/reference-nbi/pom.xml index 127f44a..439c2be 100755 --- a/reference-nbi/pom.xml +++ b/reference-nbi/pom.xml @@ -55,6 +55,19 @@ test + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + + javax.ws.rs @@ -193,7 +206,7 @@ - + + package ${project.basedir}/target/docker-stage @@ -414,6 +427,6 @@ - + diff --git a/reference-nbi/src/main/java/cloud/containerization/reference/nbi/Base64Filter.java b/reference-nbi/src/main/java/cloud/containerization/reference/nbi/Base64Filter.java index e582a3e..4252106 100644 --- a/reference-nbi/src/main/java/cloud/containerization/reference/nbi/Base64Filter.java +++ b/reference-nbi/src/main/java/cloud/containerization/reference/nbi/Base64Filter.java @@ -13,27 +13,32 @@ import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; -@Component -@Order(1) +// disable for now +//@Component +//@Order(1) public class Base64Filter implements Filter { private final static Logger LOG = Logger.getLogger(Base64Filter.class.getName()); + public static final Boolean enabled = false; @Override public void doFilter(ServletRequest request, javax.servlet.ServletResponse response, FilterChain chain) throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - // Note: the query string does not include the anchor hash (clent) content - String queryString = req.getQueryString(); - LOG.info("Pre request + querystring: " + req.getRequestURI() + "?" + queryString); - //LOG.info(encode(queryString)); - // decode base64 encoded parameters high in the chain - String decoded = decode(queryString); - LOG.info("decoded: " + decoded); + if(enabled) { + HttpServletRequest req = (HttpServletRequest) request; + + // Note: the query string does not include the anchor hash (clent) content + String queryString = req.getQueryString(); + LOG.info("Pre request + querystring: " + req.getRequestURI() + "?" + queryString); + //LOG.info(encode(queryString)); + // decode base64 encoded parameters high in the chain + String decoded = decode(queryString); + LOG.info("decoded: " + decoded); - // 3 solutions to emulate a setQueryParameter() call (wrapping request, request attributes, or custom parameters) - req.setAttribute("qs", decoded); - chain.doFilter(request, response); - LOG.info("Post request: " + req.getRequestURI()); + // 3 solutions to emulate a setQueryParameter() call (wrapping request, request attributes, or custom parameters) + req.setAttribute("qs", decoded); + chain.doFilter(request, response); + LOG.info("Post request: " + req.getRequestURI()); + } } diff --git a/reference-nbi/src/main/java/cloud/containerization/reference/nbi/SwaggerConfig.java b/reference-nbi/src/main/java/cloud/containerization/reference/nbi/SwaggerConfig.java new file mode 100644 index 0000000..dfcd242 --- /dev/null +++ b/reference-nbi/src/main/java/cloud/containerization/reference/nbi/SwaggerConfig.java @@ -0,0 +1,26 @@ +package cloud.containerization.reference.nbi; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + + } + +} diff --git a/reference-nbi/src/main/resources/application.properties b/reference-nbi/src/main/resources/application.properties index 29148fe..3328e25 100755 --- a/reference-nbi/src/main/resources/application.properties +++ b/reference-nbi/src/main/resources/application.properties @@ -1 +1,2 @@ server.servlet.context-path=/nbi +logging.level.org.springframework.web=DEBUG