cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7040] Correctly identifying a Swagger UI root in repackaged JAR
Date Tue, 06 Sep 2016 11:11:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes dac029e0e -> 267dc2107


[CXF-7040] Correctly identifying a Swagger UI root in repackaged JAR


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/267dc210
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/267dc210
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/267dc210

Branch: refs/heads/3.1.x-fixes
Commit: 267dc2107ed7e79f167bceaf3d228ea808a20dec
Parents: dac029e
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Sep 6 12:10:17 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Sep 6 12:11:27 2016 +0100

----------------------------------------------------------------------
 .../release/samples/jax_rs/spring_boot/README   |  2 ++
 .../release/samples/jax_rs/spring_boot/pom.xml  | 18 ++++++++++++++++++
 .../cxf/jaxrs/swagger/SwaggerUiResolver.java    | 20 +++++++++++++-------
 3 files changed, 33 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/267dc210/distribution/src/main/release/samples/jax_rs/spring_boot/README
----------------------------------------------------------------------
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 7fdc9c1..81b4b4d 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/README
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/README
@@ -7,6 +7,8 @@ The sample uses Maven. It can be built and run from the command line:
 
 ----
 $ mvn -Pserver
+or
+$ java -jar target/spring-boot-sample-rs-cxf-3.2.0-SNAPSHOT.jar
 ----
 
 http://localhost:8080/services/helloservice/sayHello/ApacheCxfUser

http://git-wip-us.apache.org/repos/asf/cxf/blob/267dc210/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml b/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
index 9a21d31..932e55f 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/pom.xml
@@ -32,6 +32,24 @@
             <version>${cxf.version}</version>
         </dependency>
     </dependencies>
+    <build>
+      <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                   <mainClass>sample.rs.service.SampleRestApplication</mainClass>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+      </plugins>
+    </build>
     <profiles>
        <profile>
          <id>server</id>

http://git-wip-us.apache.org/repos/asf/cxf/blob/267dc210/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
index 1df1119..2ac9664 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
@@ -44,14 +44,20 @@ public class SwaggerUiResolver {
                 final String resourcesRootStart = "META-INF/resources/webjars/swagger-ui/";
                 for (URL url : ((URLClassLoader)cl).getURLs()) {
                     String urlStr = url.toString();
-                    if (urlStr.contains("/swagger-ui") && urlStr.toString().endsWith(".jar"))
{
-                        urlStr = urlStr.substring(0, urlStr.length() - 4);
-                        String version = urlStr.substring(urlStr.lastIndexOf("/swagger-ui")
+ 12);
-                        if (swaggerUiVersion != null && !swaggerUiVersion.equals(version))
{
-                            continue;
+                    int swaggerUiIndex = urlStr.lastIndexOf("/swagger-ui-"); 
+                    if (swaggerUiIndex != -1) {
+                        boolean urlEndsWithJarSep = urlStr.endsWith(".jar!/");
+                        if (urlEndsWithJarSep || urlStr.endsWith(".jar")) {
+                            int offset = urlEndsWithJarSep ? 6 : 4;
+                            String version = urlStr.substring(swaggerUiIndex + 12, urlStr.length()
- offset);
+                            if (swaggerUiVersion != null && !swaggerUiVersion.equals(version))
{
+                                continue;
+                            }
+                            if (!urlEndsWithJarSep) {
+                                urlStr = "jar:" + urlStr + "!/";
+                            }
+                            return urlStr + resourcesRootStart + version + "/";
                         }
-                        return "jar:" + url.toString() + "!/"
-                                 +  resourcesRootStart + version + "/";
                     }
                 }
                 


Mime
View raw message