[CXF-6960] Updates to the Swagger link at the services page
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/README b/distribution/src/main/release/samples/jax_rs/spring_boot/README
index 21c6e5b..7fdc9c1 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/README
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/README
@@ -25,6 +25,11 @@
http://localhost:8080/services/helloservice/api-docs?url=/services/helloservice/swagger.json
+or access it from the CXF Services page:
+
+ http://localhost:8080/services/helloservice/services
+ and follow a Swagger link.
+
To run the client from a command line open a new terminal window and run:
----
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
index a054dc8..baeb48c 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/README
@@ -38,5 +38,10 @@
http://localhost:8080/services/helloservice/api-docs?url=/services/helloservice/swagger.json
+or access it from the CXF Services page:
+
+ http://localhost:8080/services/helloservice/services
+ and follow a Swagger link.
+
Check client/README on how to run a command line client.
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
index 7bb75ae..0c25519 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.net.URI;
import java.util.Map;
import org.apache.cxf.Bus;
@@ -175,7 +176,14 @@
if (bus != null && PropertyUtils.isTrue(bus.getProperty("swagger.service.description.available"))) {
String swaggerPath = "swagger.json";
if (PropertyUtils.isTrue(bus.getProperty("swagger.service.ui.available"))) {
- swaggerPath = "api-docs?url=/" + swaggerPath;
+ URI uri = URI.create(absoluteURL);
+ String schemePath = uri.getScheme() + "://" + uri.getHost()
+ + (uri.getPort() == -1 ? "" : ":" + uri.getPort());
+ String relPath = absoluteURL.substring(schemePath.length());
+ if (!relPath.endsWith("/")) {
+ relPath += "/";
+ }
+ swaggerPath = "api-docs?url=" + relPath + swaggerPath;
}
if (!absoluteURL.endsWith("/")) {
swaggerPath = "/" + swaggerPath;