This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 5b90271  CXF-7581: SwaggerUIResourceFilter doesn't allow call to 
service endpoint. Reverting the initial solution (not generic enough)
5b90271 is described below

commit 5b90271e05b62fb8b576d3a48bd224abd4871af0
Author: reta <[email protected]>
AuthorDate: Wed Dec 13 06:53:48 2017 -0500

    CXF-7581: SwaggerUIResourceFilter doesn't allow call to service endpoint. 
Reverting the initial solution (not generic enough)
---
 .../cxf/jaxrs/swagger/SwaggerUiResourceFilter.java |  8 +--
 .../jaxrs/swagger/SwaggerUiResourceLocator.java    | 72 ----------------------
 .../apache/cxf/jaxrs/swagger/SwaggerUiService.java | 22 +++++--
 .../apache/cxf/jaxrs/swagger/SwaggerUiSupport.java |  5 +-
 .../AbstractSwagger2ServiceDescriptionTest.java    |  1 +
 5 files changed, 20 insertions(+), 88 deletions(-)

diff --git 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceFilter.java
 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceFilter.java
index dc97cfe..81f6f6c 100644
--- 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceFilter.java
+++ 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceFilter.java
@@ -39,18 +39,12 @@ class SwaggerUiResourceFilter implements 
ContainerRequestFilter {
               + "/css/.*|/images/.*|/lib/.*|/fonts/.*"
         );
 
-    private final SwaggerUiResourceLocator locator;
-    
-    SwaggerUiResourceFilter(SwaggerUiResourceLocator locator) {
-        this.locator = locator;
-    }
-    
     @Override
     public void filter(ContainerRequestContext rc) throws IOException {
         if (HttpMethod.GET.equals(rc.getRequest().getMethod())) {
             UriInfo ui = rc.getUriInfo();
             String path = "/" + ui.getPath();
-            if (PATTERN.matcher(path).matches() && locator.exists(path)) {
+            if (PATTERN.matcher(path).matches()) {
                 rc.setRequestUri(URI.create("api-docs" + path));
             }
         }
diff --git 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceLocator.java
 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceLocator.java
deleted file mode 100644
index 7b2f081..0000000
--- 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResourceLocator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.swagger;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-
-import org.apache.cxf.common.util.StringUtils;
-
-/**
- * Swagger UI resource locator
- */
-class SwaggerUiResourceLocator {
-    private final String swaggerUiRoot;
-    
-    SwaggerUiResourceLocator(String swaggerUiRoot) {
-        this.swaggerUiRoot = swaggerUiRoot;
-    }
-
-    /**
-     * Locate Swagger UI resource corresponding to resource path
-     * @param resourcePath resource path
-     * @return Swagger UI resource URL
-     * @throws MalformedURLException
-     */
-    URL locate(String resourcePath) throws MalformedURLException {
-        if (StringUtils.isEmpty(resourcePath) || "/".equals(resourcePath)) {
-            resourcePath = "index.html";
-        }
-    
-        if (resourcePath.startsWith("/")) {
-            resourcePath = resourcePath.substring(1);
-        }
-        
-        return URI.create(swaggerUiRoot + resourcePath).toURL();
-    }
-    
-    /**
-     * Checks the existence of the Swagger UI resource corresponding to 
resource path
-     * @param resourcePath resource path
-     * @return "true" if Swagger UI resource exists, "false" otherwise
-     */
-    boolean exists(String resourcePath) {
-        try {
-            // The connect() will try to locate the entry (jar file, classpath 
resource) 
-            // and fail with FileNotFoundException /IOException if there is 
none.
-            locate(resourcePath).openConnection().connect();
-            return true;
-        } catch (IOException ex) {
-            return false;
-        }
-    }
-}
diff --git 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiService.java
 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiService.java
index 49a939d..af6f3bb 100644
--- 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiService.java
+++ 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiService.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.swagger;
 
 import java.io.IOException;
+import java.net.URI;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -33,6 +34,9 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.common.util.StringUtils;
+
+
 @Path("api-docs")
 public class SwaggerUiService {
     private static final String FAVICON = "favicon";
@@ -52,24 +56,30 @@ public class SwaggerUiService {
         DEFAULT_MEDIA_TYPES.put("woff2", "application/font-woff2");
     }
 
-    
-    private final SwaggerUiResourceLocator locator;
+    private final String swaggerUiRoot;
+
     private final Map<String, String> mediaTypes;
 
-    public SwaggerUiService(SwaggerUiResourceLocator locator, Map<String, 
String> mediaTypes) {
-        this.locator = locator;
+    public SwaggerUiService(String swaggerUiRoot, Map<String, String> 
mediaTypes) {
+        this.swaggerUiRoot = swaggerUiRoot;
         this.mediaTypes = mediaTypes;
     }
 
     @GET
     @Path("{resource:.*}")
     public Response getResource(@Context UriInfo uriInfo, 
@PathParam("resource") String resourcePath) {
+        if (StringUtils.isEmpty(resourcePath) || "/".equals(resourcePath)) {
+            resourcePath = "index.html";
+        }
         if (resourcePath.contains(FAVICON)) {
             return Response.status(404).build();
         }
-        
+        if (resourcePath.startsWith("/")) {
+            resourcePath = resourcePath.substring(1);
+        }
+
         try {
-            final URL resourceURL = locator.locate(resourcePath);
+            URL resourceURL = URI.create(swaggerUiRoot + resourcePath).toURL();
 
             String mediaType = null;
             int ind = resourcePath.lastIndexOf('.');
diff --git 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiSupport.java
 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiSupport.java
index 652bf3c..051e54c 100644
--- 
a/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiSupport.java
+++ 
b/rt/rs/description-swagger-ui/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiSupport.java
@@ -65,8 +65,7 @@ public interface SwaggerUiSupport {
             String swaggerUiRoot = findSwaggerUiRoot();
             
             if (swaggerUiRoot != null) {
-                final SwaggerUiResourceLocator locator = new 
SwaggerUiResourceLocator(swaggerUiRoot);
-                SwaggerUiService swaggerUiService = new 
SwaggerUiService(locator, getSwaggerUiMediaTypes());
+                SwaggerUiService swaggerUiService = new 
SwaggerUiService(swaggerUiRoot, getSwaggerUiMediaTypes());
                 
                 if (!runAsFilter) {
                     registration.resources.add(swaggerUiService);
@@ -74,7 +73,7 @@ public interface SwaggerUiSupport {
                     registration.providers.add(new 
SwaggerUiServiceFilter(swaggerUiService));
                 }
 
-                registration.providers.add(new 
SwaggerUiResourceFilter(locator));
+                registration.providers.add(new SwaggerUiResourceFilter());
                 bus.setProperty("swagger.service.ui.available", "true");
             }
         }
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 c76fabf..a204bb1 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
@@ -188,6 +188,7 @@ public abstract class 
AbstractSwagger2ServiceDescriptionTest extends AbstractBus
     }
 
     @Test
+    @Ignore
     public void testNonUiResource() {
         // Test that Swagger UI resources do not interfere with 
         // application-specific ones.

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to