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-7347] Dynamically setting a Swagger host property if needed
Date Mon, 24 Apr 2017 21:18:58 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 5f04f8f70 -> fb069dc54


[CXF-7347] Dynamically setting a Swagger host property if needed


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

Branch: refs/heads/3.1.x-fixes
Commit: fb069dc54d47d9f4358b1d4503588886a1cbe189
Parents: 5f04f8f
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Apr 24 22:16:33 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Apr 24 22:18:26 2017 +0100

----------------------------------------------------------------------
 .../jaxrs/swagger/DefaultSwagger2Serializers.java  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fb069dc5/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 6a51acc..8048fa1 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
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.net.URI;
 import java.net.URL;
 import java.util.Collections;
 import java.util.Comparator;
@@ -73,9 +74,10 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
             final MultivaluedMap<String, Object> headers,
             final OutputStream out) throws IOException {
 
+        MessageContext ctx = null;
+                                                   
         if (dynamicBasePath) {
-            MessageContext ctx = JAXRSUtils.createContextValue(
-                    JAXRSUtils.getCurrentMessage(), null, MessageContext.class);
+            ctx = createMessageContext();
             String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(),
"/");
             if (!currentBasePath.equals(beanConfig.getBasePath())) {
                 data.setBasePath(currentBasePath);
@@ -88,6 +90,12 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
                 data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions());
             }
         }
+        if (data.getHost() == null) {
+            ctx = ctx == null ? createMessageContext() : ctx;
+            URI uri = ctx.getUriInfo().getAbsolutePath();
+            String authority = uri.getAuthority();
+            data.setHost(authority);
+        }
 
         if (replaceTags || javadocProvider != null) {
             Map<String, ClassResourceInfo> operations = new HashMap<>();
@@ -158,6 +166,11 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
         super.writeTo(data, type, genericType, annotations, mediaType, headers, out);
     }
 
+    private MessageContext createMessageContext() {
+        return JAXRSUtils.createContextValue(
+                               JAXRSUtils.getCurrentMessage(), null, MessageContext.class);
+    }
+
     protected String getNormalizedPath(String classResourcePath, String operationResourcePath)
{
         StringBuilder normalizedPath = new StringBuilder();
 


Mime
View raw message