cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [08/23] cxf git commit: [CXF-7035] Propagating BeanConfig if dynamicBasePath code detects a basePath mismatch, with thanks to Andriy Redko
Date Mon, 05 Sep 2016 01:10:15 GMT
[CXF-7035] Propagating BeanConfig if dynamicBasePath code detects a basePath mismatch, with
thanks to Andriy Redko


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

Branch: refs/heads/master-jaxrs-2.1
Commit: be34ef21638170fc86db896a642e0c9d58c95318
Parents: 1f826fe
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Sep 1 13:16:57 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Sep 1 13:18:04 2016 +0100

----------------------------------------------------------------------
 .../src/main/webapp/WEB-INF/context.xml           |  2 --
 .../cxf/jaxrs/swagger/AbstractSwaggerFeature.java |  2 +-
 .../jaxrs/swagger/DefaultSwagger2Serializers.java | 15 ++++++++++++++-
 .../apache/cxf/jaxrs/swagger/Swagger2Feature.java | 18 +++++++++++++++++-
 .../cxf/jaxrs/swagger/Swagger2Serializers.java    |  3 +++
 5 files changed, 35 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/be34ef21/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
index 4c54b90..6cf02a6 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml
@@ -42,7 +42,6 @@
 
     <!-- Swagger2Feature for the first Endpoint -->  
     <bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
-        <property name="basePath" value="/app/swaggerSample"/>
         <property name="usePathBasedConfig" value="true"/>
         <property name="scan" value="false"/>
     </bean>
@@ -66,7 +65,6 @@
 
     <!-- Swagger2Feature for the second Endpoint -->  
     <bean id="swagger2Feature2" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
-        <property name="basePath" value="/app/swaggerSample2"/>
         <property name="usePathBasedConfig" value="true"/>
         <property name="scan" value="false"/>
     </bean>

http://git-wip-us.apache.org/repos/asf/cxf/blob/be34ef21/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
index 0a95b32..427ab49 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
@@ -99,7 +99,7 @@ public abstract class AbstractSwaggerFeature extends AbstractFeature {
         }
     }
     
-    private void calculateDefaultBasePath(Server server) {
+    protected void calculateDefaultBasePath(Server server) {
         if (getBasePath() == null || getBasePath().length() == 0) {
             String address = server.getEndpoint().getEndpointInfo().getAddress();
             setBasePathByAddress(address);

http://git-wip-us.apache.org/repos/asf/cxf/blob/be34ef21/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
index d6f0bb7..2a32e7c 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
@@ -42,6 +42,7 @@ import org.apache.cxf.jaxrs.model.doc.DocumentationProvider;
 import org.apache.cxf.jaxrs.model.doc.JavaDocProvider;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
+import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.jaxrs.listing.SwaggerSerializers;
 import io.swagger.models.HttpMethod;
 import io.swagger.models.Operation;
@@ -59,6 +60,7 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
 
     protected List<ClassResourceInfo> cris;
 
+    protected BeanConfig beanConfig;
     @Override
     public void writeTo(
             final Swagger data,
@@ -72,7 +74,12 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
         if (dynamicBasePath) {
             MessageContext ctx = JAXRSUtils.createContextValue(
                     JAXRSUtils.getCurrentMessage(), null, MessageContext.class);
-            data.setBasePath(StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(),
"/"));
+            String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(),
"/");
+            if (!currentBasePath.equals(beanConfig.getBasePath())) {
+                data.setBasePath(currentBasePath);
+                data.setHost(beanConfig.getHost());
+                data.setInfo(beanConfig.getInfo());
+            }
         }
 
         if (replaceTags || javadocProvider != null) {
@@ -194,4 +201,10 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
     public void setJavaDocURLs(final URL[] javaDocURLs) {
         this.javadocProvider = new JavaDocProvider(javaDocURLs);
     }
+
+    @Override
+    public void setBeanConfig(BeanConfig beanConfig) {
+        this.beanConfig = beanConfig;
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/be34ef21/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 5b813c3..83e65a8 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
@@ -93,7 +93,15 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     private Map<String, String> swaggerUiMediaTypes;
 
     private boolean usePathBasedConfig;
-
+    
+    private boolean dynamicBasePath;
+    
+    @Override
+    protected void calculateDefaultBasePath(Server server) {
+        dynamicBasePath = true;
+        super.calculateDefaultBasePath(server);
+    }
+    
     @Override
     protected void addSwaggerResource(Server server, Bus bus) {
         JAXRSServiceFactoryBean sfb =
@@ -150,6 +158,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
             swagger2Serializers = new DefaultSwagger2Serializers();
         }
         swagger2Serializers.setClassResourceInfos(cris);
+        swagger2Serializers.setDynamicBasePath(dynamicBasePath);
+        
         providers.add(swagger2Serializers);
 
         providers.add(new ReaderConfigFilter());
@@ -179,6 +189,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         beanConfig.setScan(isScan());
         beanConfig.setPrettyPrint(isPrettyPrint());
         beanConfig.setFilterClass(getFilterClass());
+        
+        swagger2Serializers.setBeanConfig(beanConfig);
     }
 
     public boolean isUsePathBasedConfig() {
@@ -257,6 +269,10 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         this.swaggerUiMediaTypes = swaggerUiMediaTypes;
     }
 
+    public void setDynamicBasePath(boolean dynamicBasePath) {
+        this.dynamicBasePath = dynamicBasePath;
+    }
+
     @javax.ws.rs.ext.Provider
     private class ServletConfigProvider implements ContextProvider<ServletConfig> {
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/be34ef21/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
index 6b26552..ba1dec9 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
@@ -26,10 +26,13 @@ import javax.ws.rs.ext.MessageBodyWriter;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.doc.DocumentationProvider;
 
+import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.models.Swagger;
 
 public interface Swagger2Serializers extends MessageBodyWriter<Swagger> {
 
+    void setBeanConfig(BeanConfig beanConfig);
+    
     void setDynamicBasePath(boolean dynamicBasePath);
 
     void setReplaceTags(boolean replaceTags);


Mime
View raw message