diff --git a/pom.xml b/pom.xml
index 1a0f6740..b20f47ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,6 +4,9 @@
org.qora
qora-core
2.0.0-SNAPSHOT
+
+ 3.19.0
+
src
@@ -15,6 +18,74 @@
1.8
+
+
+ maven-dependency-plugin
+
+
+ swagger ui
+ generate-resources
+
+ unpack
+
+
+
+
+ org.webjars
+ swagger-ui
+ ${swagger-ui.version}
+
+
+ ${project.build.directory}/swagger-ui.unpacked
+
+
+
+
+
+
+ com.google.code.maven-replacer-plugin
+ replacer
+ 1.5.3
+
+
+ generate-resources
+
+ replace
+
+
+
+
+ ${project.build.directory}/swagger-ui.unpacked/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/index.html
+
+
+ https://petstore.swagger.io/v2/swagger.json
+ /openapi.json
+
+
+
+
+
+
+ maven-resources-plugin
+ 3.1.0
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ ${project.build.directory}/classes/resources/swagger-ui
+
+
+ ${project.build.directory}/swagger-ui.unpacked/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}
+
+
+
+
+
+
@@ -128,15 +199,25 @@
hamcrest-library
1.3
-
- org.glassfish.jersey.media
- jersey-media-multipart
- 2.27
-
-
- javax.mail
- mail
- 1.5.0-b01
-
+
+ org.glassfish.jersey.media
+ jersey-media-multipart
+ 2.27
+
+
+ javax.mail
+ mail
+ 1.5.0-b01
+
+
+ org.webjars
+ swagger-ui
+ ${swagger-ui.version}
+
+
+ org.eclipse.jetty
+ jetty-rewrite
+ 9.4.11.v20180605
+
\ No newline at end of file
diff --git a/src/api/ApiService.java b/src/api/ApiService.java
index 9e3c5012..aa2b2726 100644
--- a/src/api/ApiService.java
+++ b/src/api/ApiService.java
@@ -1,11 +1,15 @@
package api;
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
+import java.io.File;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.jetty.rewrite.handler.RedirectPatternRule;
+import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.InetAccessHandler;
+import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
@@ -36,16 +40,30 @@ public class ApiService {
}
this.server.setHandler(accessHandler);
+ // url rewriting
+ RewriteHandler rewriteHandler = new RewriteHandler();
+ accessHandler.setHandler(rewriteHandler);
+
// context
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
- accessHandler.setHandler(context);
-
+ rewriteHandler.setHandler(context);
+
// API servlet
ServletContainer container = new ServletContainer(config);
ServletHolder apiServlet = new ServletHolder(container);
apiServlet.setInitOrder(1);
context.addServlet(apiServlet, "/*");
+
+ // Swagger-UI static content
+ ClassLoader loader = this.getClass().getClassLoader();
+ File swaggerUIResourceLocation = new File(loader.getResource("resources/swagger-ui/").getFile());
+ ServletHolder swaggerUIServlet = new ServletHolder("static-swagger-ui", DefaultServlet.class);
+ swaggerUIServlet.setInitParameter("resourceBase", swaggerUIResourceLocation.getAbsolutePath());
+ swaggerUIServlet.setInitParameter("dirAllowed","true");
+ swaggerUIServlet.setInitParameter("pathInfoOnly","true");
+ context.addServlet(swaggerUIServlet,"/api-documentation/*");
+ rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/index.html")); // redirect to swagger ui start page
}
//XXX: replace singleton pattern by dependency injection?