You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/02/13 14:27:30 UTC

[camel] branch master updated: CAMEL-12222: RestSwaggerServlet - added option to suppress "translateContextPath"

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f01dead  CAMEL-12222: RestSwaggerServlet - added option to suppress "translateContextPath"
f01dead is described below

commit f01deadabe5d5822a97e6dec95483a2d51187e35
Author: realistTheorist <re...@gmail.com>
AuthorDate: Sun Feb 11 12:35:22 2018 -0500

    CAMEL-12222: RestSwaggerServlet - added option to suppress "translateContextPath"
---
 .../camel/swagger/servlet/RestSwaggerServlet.java  | 26 ++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/servlet/RestSwaggerServlet.java b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/servlet/RestSwaggerServlet.java
index 51ca3d2..15f9d00 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/servlet/RestSwaggerServlet.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/servlet/RestSwaggerServlet.java
@@ -34,6 +34,7 @@ import io.swagger.jaxrs.config.BeanConfig;
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultClassResolver;
 import org.apache.camel.spi.ClassResolver;
+import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.swagger.RestApiResponseAdapter;
 import org.apache.camel.swagger.RestSwaggerSupport;
 import org.apache.camel.util.EndpointHelper;
@@ -61,6 +62,19 @@ public class RestSwaggerServlet extends HttpServlet {
 
     private String apiContextIdPattern;
     private boolean apiContextIdListing;
+    private boolean translateContextPath = true;
+
+
+    public boolean isTranslateContextPath() { return translateContextPath; }
+
+    /**
+     * Sets whether the context path of the request should be translated (true) or used as-is (false)
+     * Optional, Defaults to true
+     * @param translateContextPath
+     */
+    public void setTranslateContextPath(boolean translateContextPath) { this.translateContextPath = translateContextPath; }
+
+
 
     public String getApiContextIdPattern() {
         return apiContextIdPattern;
@@ -115,6 +129,11 @@ public class RestSwaggerServlet extends HttpServlet {
         if (listing != null) {
             apiContextIdListing = Boolean.valueOf(listing.toString());
         }
+        Object translate = parameters.remove("translateContextPath");
+        if (translate != null) {
+            translateContextPath = Boolean.valueOf(translate.toString());
+        }
+
     }
 
     @Override
@@ -192,7 +211,7 @@ public class RestSwaggerServlet extends HttpServlet {
                 if (!match) {
                     adapter.noContent();
                 } else {
-                    support.renderResourceListing(adapter, swaggerConfig, name, route, json, yaml, classResolver, null);
+                    support.renderResourceListing(adapter, swaggerConfig, name, route, json, yaml, classResolver, new RestConfiguration());
                 }
             }
         } catch (Exception e) {
@@ -229,6 +248,9 @@ public class RestSwaggerServlet extends HttpServlet {
      */
     private String translateContextPath(HttpServletRequest request) {
         String path = request.getContextPath();
+        if (!translateContextPath) {
+            return path;
+        }
         if (path.isEmpty() || path.equals("/")) {
             return "";
         } else {
@@ -240,4 +262,4 @@ public class RestSwaggerServlet extends HttpServlet {
         return path;
     }
 
-}
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.