knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject [6/6] knox git commit: KNOX-949 - WeBHDFS proxy replaces %20 encoded spaces in URL with + encoding
Date Sat, 17 Jun 2017 14:18:52 GMT
KNOX-949 - WeBHDFS proxy replaces %20 encoded spaces in URL with + encoding

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

Branch: refs/heads/master
Commit: 680e8a6e4faf6b65dcb81a61525faedb0e937f09
Parents: 5376907
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Sat Jun 17 10:18:05 2017 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Sat Jun 17 10:18:05 2017 -0400

----------------------------------------------------------------------
 .../filter/rewrite/impl/UrlRewriteRequest.java  |  2 +-
 .../filter/rewrite/impl/UrlRewriteResponse.java |  2 +-
 .../resources/services/ambari/2.2.0/service.xml |  2 +-
 .../services/ambariui/2.2.0/service.xml         |  2 +-
 .../dispatch/AbstractGatewayDispatch.java       |  8 ++++
 .../PassAllHeadersNoEncodingDispatch.java       | 50 ++++++++++++++++++++
 .../hadoop/gateway/GatewayBasicFuncTest.java    |  3 +-
 .../gateway/util/urltemplate/Template.java      | 19 ++++----
 8 files changed, 72 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
index cd053de..de9331b 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
@@ -43,7 +43,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
-
+import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.List;

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index d3b00b0..d4e31e3 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -116,7 +116,7 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
       Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( this, input, UrlRewriter.Direction.OUT, rule );
       if( output != null ) {
-        value = output.toEncodedString();
+        value = output.toString();
       }
     } catch( URISyntaxException e ) {
       LOG.failedToParseValueForUrlRewrite( value );

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-service-definitions/src/main/resources/services/ambari/2.2.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/ambari/2.2.0/service.xml
b/gateway-service-definitions/src/main/resources/services/ambari/2.2.0/service.xml
index b48d1ee..cb6f35e 100644
--- a/gateway-service-definitions/src/main/resources/services/ambari/2.2.0/service.xml
+++ b/gateway-service-definitions/src/main/resources/services/ambari/2.2.0/service.xml
@@ -30,5 +30,5 @@
             <rewrite apply="AMBARI/ambari/api/inbound" to="request.body"/>
         </route>
     </routes>
-    <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/>
+    <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersNoEncodingDispatch"/>
 </service>

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
b/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
index 48a5755..ab4ab2b 100644
--- a/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
+++ b/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
@@ -87,6 +87,6 @@
 
         <!-- No need to rewrite Slider View -->
     </routes>
-    <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/>
+    <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersNoEncodingDispatch"/>
 </service>
 

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
index 4ae5e7a..70a6996 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/AbstractGatewayDispatch.java
@@ -133,4 +133,12 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
     return REQUEST_EXCLUDE_HEADERS;
   }
 
+  protected void encodeUnwiseCharacters(StringBuffer str) {
+    int pipe = str.indexOf("|");
+    while (pipe > -1) {
+      str.replace(pipe, pipe+1, "%7C");
+      pipe = str.indexOf("|", pipe+1);
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java
new file mode 100644
index 0000000..09ab2ca
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.dispatch;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+
+import javax.servlet.http.HttpServletRequest;
+
+  /**
+   * This is a specialized PassAllHeadersDispatch dispatch that decodes the URL before
+   * dispatch. Ambari Views do not work with the query string percent encoded. Other
+   * UIs may require this at some point as well.
+   */
+public class PassAllHeadersNoEncodingDispatch extends PassAllHeadersDispatch {
+  public URI getDispatchUrl( HttpServletRequest request) {
+    String base = request.getRequestURI();
+    StringBuffer str = new StringBuffer();
+    str.append( base );
+    String query = request.getQueryString();
+    if (query != null) {
+      try {
+        query = URLDecoder.decode(query, "UTF-8");
+      } catch (UnsupportedEncodingException e) {
+        // log
+      }
+      str.append( '?' );
+      str.append( query );
+    }
+    encodeUnwiseCharacters(str);
+    URI uri = URI.create( str.toString() );
+    return uri;
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index d7e99c5..2cc1573 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -386,7 +386,8 @@ public class GatewayBasicFuncTest {
         .expect()
         //.log().ifError()
         .statusCode( HttpStatus.SC_TEMPORARY_REDIRECT )
-        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC"
);
+        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/fileレポー" );
+//        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC"
);
     String location = response.getHeader( "Location" );
     //System.out.println( location );
     log.debug( "Redirect location: " + response.getHeader( "Location" ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/680e8a6e/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Template.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Template.java
b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Template.java
index f2eba5a..3cce86a 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Template.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Template.java
@@ -312,17 +312,14 @@ public class Template {
   }
 
   public String toString() {
-    String s = image;
-    if( s == null ) {
-      StringBuilder b = new StringBuilder();
-      buildScheme( b );
-      buildAuthority( b );
-      buildPath( b );
-      buildQuery( b );
-      buildFragment( b );
-      s = b.toString();
-      //image = s;
-    }
+    String s = null;
+    StringBuilder b = new StringBuilder();
+    buildScheme( b );
+    buildAuthority( b );
+    buildPath( b );
+    buildQuery( b );
+    buildFragment( b );
+    s = b.toString();
     return s;
   }
 


Mime
View raw message