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:44:02 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 1876a1fd1 -> 262ebe6bd


[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/262ebe6b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/262ebe6b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/262ebe6b

Branch: refs/heads/master
Commit: 262ebe6bd5a46a7f5c27976b02e2e4ba25e589f8
Parents: 1876a1f
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:43:42 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/262ebe6b/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d2f8de1..5e2906e 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -159,6 +159,7 @@
         <cxf.spring.ldap.version>2.3.1.RELEASE</cxf.spring.ldap.version>
         <cxf.spring.mock>spring-test</cxf.spring.mock>
         <cxf.swagger2.version>1.5.16</cxf.swagger2.version>
+        <cxf.swagger.ui.version>3.0.21</cxf.swagger.ui.version>
         <cxf.velocity.version>2.0</cxf.velocity.version>
         <cxf.woodstox.core.version>5.0.3</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/262ebe6b/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 b522f1b..5e856be 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/262ebe6b/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 314e8b3..60f7d20 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/262ebe6b/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index 6c61668..635cba7 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -128,7 +128,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>
@@ -136,6 +135,11 @@
             <scope>test</scope>
         </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/262ebe6b/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 02be718..2157ed1 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
@@ -159,6 +159,8 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
         } finally {
             client.close();
         }
+        
+        checkUiResource();
     }
 
     @Test
@@ -191,6 +193,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