[ 
https://issues.apache.org/jira/browse/CAMEL-12222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16362397#comment-16362397
 ] 

ASF GitHub Bot commented on CAMEL-12222:
----------------------------------------

davsclaus closed pull request #2220: CAMEL-12222: RestSwaggerServlet - added 
option to suppress "translate…
URL: https://github.com/apache/camel/pull/2220
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 51ca3d2e0d7..15f9d001627 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 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 @@
 
     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 void init(final ServletConfig config) throws 
ServletException {
         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 @@ protected void doGet(HttpServletRequest request, 
HttpServletResponse response) t
                 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 @@ private void initBaseAndApiPaths(HttpServletRequest 
request) throws MalformedURL
      */
     private String translateContextPath(HttpServletRequest request) {
         String path = request.getContextPath();
+        if (!translateContextPath) {
+            return path;
+        }
         if (path.isEmpty() || path.equals("/")) {
             return "";
         } else {
@@ -240,4 +262,4 @@ private String translateContextPath(HttpServletRequest 
request) {
         return path;
     }
 
-}
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> ResrSwaggerServlet removes last part of context root
> ----------------------------------------------------
>
>                 Key: CAMEL-12222
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12222
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-swagger
>            Reporter: Darius Cooper
>            Priority: Minor
>
> The method within RestSwaggerServlet, looks for the last "/" in the context 
> root, and drops anything after that slash.
> {code:java}
> private String translateContextPath(HttpServletRequest request) {
>   String path = request.getContextPath();
>   if (path.isEmpty() || path.equals("/")) {
>       return "";
>   } else {
>      int idx = path.lastIndexOf("/");
>      if (idx > 0) {
>          return path.substring(0, idx);
>      }
>   }
>   return path;
> }{code}
> Even though this has been deprecated, it would be good to fix it. 
> An approach could be to add a servlet init parameter named 
> "translateContextPath" which would default to true, and would work exactly as 
> it does today by default. if set to false, it would return whatever value is 
> in request.getContextPath() , with no translation.
> Also, to avoid the NPE thrown, pass in an empty RestConfiguration to 
> RestSwaggerSupport.renderResourceListing() 
> (See: https://issues.apache.org/jira/browse/CAMEL-12038) 
> I plan on working on this. Creating a Jira to get feedback on the approach



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to