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-7474] Support for non URLClassLoaders
Date Tue, 15 Aug 2017 10:57:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes e4899b534 -> b6547f75a


[CXF-7474] Support for non URLClassLoaders


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

Branch: refs/heads/3.1.x-fixes
Commit: b6547f75a198e8b345c120b0b4f71f198b044660
Parents: e4899b5
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Aug 15 11:43:42 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Aug 15 11:57:15 2017 +0100

----------------------------------------------------------------------
 parent/pom.xml                                  |  1 +
 .../jaxrs/swagger/OsgiSwaggerUiResolver.java    |  3 +-
 .../cxf/jaxrs/swagger/SwaggerUiResolver.java    | 52 +++++++++++++-------
 systests/jaxrs/pom.xml                          |  6 ++-
 .../AbstractSwagger2ServiceDescriptionTest.java |  9 ++++
 5 files changed, 51 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b6547f75/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 9dd565a..2fd5f76 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -157,6 +157,7 @@
         <cxf.spring.mock>spring-test</cxf.spring.mock>
         <cxf.swagger.version>1.3.13</cxf.swagger.version>
         <cxf.swagger2.version>1.5.12</cxf.swagger2.version>
+        <cxf.swagger.ui.version>2.2.10-1</cxf.swagger.ui.version>
         <cxf.velocity.version>1.7</cxf.velocity.version>
         <cxf.woodstox.core.version>4.4.1</cxf.woodstox.core.version>
         <cxf.woodstox.stax2-api.version>3.1.4</cxf.woodstox.stax2-api.version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/b6547f75/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
index f5e8c8f..5a2e397 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
@@ -70,8 +70,7 @@ public class OsgiSwaggerUiResolver extends SwaggerUiResolver {
     }
 
     private String getSwaggerUiRoot(Bundle b, String swaggerUiVersion) {
-        final String resourcesRootStart = "META-INF/resources/webjars/swagger-ui/";
-        URL entry = b.getEntry(resourcesRootStart + swaggerUiVersion);
+        URL entry = b.getEntry(SwaggerUiResolver.UI_RESOURCES_ROOT_START + swaggerUiVersion);
         if (entry != null) {
             return entry.toString() + "/";
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b6547f75/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 79c15e0..53b908d 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
@@ -20,8 +20,11 @@ package org.apache.cxf.jaxrs.swagger;
 
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Enumeration;
 
 public class SwaggerUiResolver {
+    static final String UI_RESOURCES_ROOT_START = "META-INF/resources/webjars/swagger-ui/";
+    
     static final SwaggerUiResolver HELPER;
     static {
         SwaggerUiResolver theHelper = null;
@@ -42,26 +45,22 @@ public class SwaggerUiResolver {
         try {
             ClassLoader cl = AbstractSwaggerFeature.class.getClassLoader();
             if (cl instanceof URLClassLoader) {
-                final String resourcesRootStart = "META-INF/resources/webjars/swagger-ui/";
                 for (URL url : ((URLClassLoader)cl).getURLs()) {
-                    String urlStr = url.toString();
-                    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 + "/";
-                        }
+                    String root = 
+                        checkUiRoot(url.toString(), swaggerUiMavenGroupAndArtifact, swaggerUiVersion);
+                    if (root != null) {
+                        return root;
+                    }
+                }
+            } else {
+                Enumeration<URL> urls = cl.getResources(UI_RESOURCES_ROOT_START);
+                while (urls.hasMoreElements()) {
+                    String urlStr = urls.nextElement().toString().replace(UI_RESOURCES_ROOT_START,
"");     
+                    String root = checkUiRoot(urlStr, swaggerUiMavenGroupAndArtifact, swaggerUiVersion);
+                    if (root != null) {
+                        return root;
                     }
                 }
-                
             }
         } catch (Throwable ex) {
             // ignore
@@ -69,6 +68,25 @@ public class SwaggerUiResolver {
         return null;
     }
 
+    protected static String checkUiRoot(String urlStr, String swaggerUiMavenGroupAndArtifact,
String swaggerUiVersion) {
+        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))
{
+                    return null;
+                }
+                if (!urlEndsWithJarSep) {
+                    urlStr = "jar:" + urlStr + "!/";
+                }
+                return urlStr + UI_RESOURCES_ROOT_START + version + "/";
+            }
+        }
+        return null;
+    }
+
     public static String findSwaggerUiRoot(String swaggerUiMavenGroupAndArtifact, 
                                            String swaggerUiVersion) {
         String root = HELPER.findSwaggerUiRootInternal(swaggerUiMavenGroupAndArtifact, 

http://git-wip-us.apache.org/repos/asf/cxf/blob/b6547f75/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index cf6120a..843a196 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -121,7 +121,6 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
-        <!-- Swagger 2 dep is strong, 1.2 - optional -->
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
@@ -141,6 +140,11 @@
             <optional>true</optional>
         </dependency>
         <dependency>
+            <groupId>org.webjars</groupId>
+            <artifactId>swagger-ui</artifactId>
+            <version>${cxf.swagger.ui.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.ant</groupId>
             <artifactId>ant</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/cxf/blob/b6547f75/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
index aaddb93..88682d5 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
@@ -161,6 +161,8 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
         } finally {
             client.close();
         }
+        
+        checkUiResource();
     }
 
     @Test
@@ -193,6 +195,13 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends
AbstractBus
             .accept(MediaType.APPLICATION_JSON).accept("application/yaml");
     }
 
+    protected void checkUiResource() {
+        WebClient uiClient = WebClient.create("http://localhost:" + getPort() + "/api-docs")
+            .accept(MediaType.WILDCARD);
+        String uiHtml = uiClient.get(String.class);
+        assertTrue(uiHtml.contains("<title>Swagger UI</title>"));
+    }
+    
     private static String getExpectedValue(String name, Object... args) throws IOException
{
         return String.format(IOUtils.readStringFromStream(
             AbstractSwagger2ServiceDescriptionTest.class.getResourceAsStream(name)), args);


Mime
View raw message