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-6904] making sure ApiListingResource sees Application too - for now only if the scan is disabled
Date Wed, 17 Aug 2016 16:42:20 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 869be21c4 -> 81ed24d98


[CXF-6904] making sure ApiListingResource sees Application too - for now only if the scan
is disabled


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

Branch: refs/heads/3.1.x-fixes
Commit: 81ed24d9802d8d82775e27c3326a58098ee883e8
Parents: 869be21
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Aug 17 17:40:34 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Aug 17 17:41:57 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/Swagger2Feature.java      | 55 +++++++++++++++-----
 1 file changed, 42 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/81ed24d9/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
index c8807dd..136bbee 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -39,6 +40,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -53,6 +55,7 @@ import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.model.ApplicationInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.doc.DocumentationProvider;
 import org.apache.cxf.jaxrs.model.doc.JavaDocProvider;
@@ -90,6 +93,22 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     
     @Override
     protected void addSwaggerResource(Server server, Bus bus) {
+        JAXRSServiceFactoryBean sfb =
+            (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
+        if (!isScan()) {
+            ServerProviderFactory factory = 
+                (ServerProviderFactory)server.getEndpoint().get(ServerProviderFactory.class.getName());
+            ApplicationInfo applicationInfo = factory.getApplicationProvider();
+            if (applicationInfo == null) {
+                Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
+                for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
+                    serviceClasses.add(cri.getServiceClass());
+                }
+                applicationInfo = new ApplicationInfo(new DefaultApplication(serviceClasses),
bus);
+                server.getEndpoint().put(Application.class.getName(), applicationInfo);
+            }
+        }
+        
         List<Object> swaggerResources = new LinkedList<Object>();
         ApiListingResource apiListingResource = new ApiListingResource();
         swaggerResources.add(apiListingResource);
@@ -104,8 +123,6 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
             }
         }
         
-        JAXRSServiceFactoryBean sfb =
-                (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
         sfb.setResourceClassesFromBeans(swaggerResources);
         
         List<ClassResourceInfo> cris = sfb.getClassResourceInfo();
@@ -217,6 +234,19 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
             setBasePath(address);
         }
     }
+
+    public void setSwaggerUiVersion(String swaggerUiVersion) {
+        this.swaggerUiVersion = swaggerUiVersion;
+    }
+
+    public void setSupportSwaggerUi(boolean supportSwaggerUi) {
+        this.supportSwaggerUi = supportSwaggerUi;
+    }
+
+    public void setSwaggerUiMediaTypes(Map<String, String> swaggerUiMediaTypes) {
+        this.swaggerUiMediaTypes = swaggerUiMediaTypes;
+    }
+
     
     @PreMatching
     protected static class SwaggerContainerRequestFilter extends ApiListingResource implements
ContainerRequestFilter {
@@ -369,16 +399,15 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         }
     }
     
-    public void setSwaggerUiVersion(String swaggerUiVersion) {
-        this.swaggerUiVersion = swaggerUiVersion;
-    }
-
-    public void setSupportSwaggerUi(boolean supportSwaggerUi) {
-        this.supportSwaggerUi = supportSwaggerUi;
-    }
-
-    public void setSwaggerUiMediaTypes(Map<String, String> swaggerUiMediaTypes) {
-        this.swaggerUiMediaTypes = swaggerUiMediaTypes;
+    protected static class DefaultApplication extends Application {
+        Set<Class<?>> serviceClasses;
+        DefaultApplication(Set<Class<?>> serviceClasses) {
+            this.serviceClasses = serviceClasses;
+        }
+        @Override
+        public Set<Class<?>> getClasses() {
+            return serviceClasses;
+        }
     }
-
+    
 }


Mime
View raw message