hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject hadoop git commit: YARN-1728. Workaround guice3x-undecoded pathInfo in YARN WebApp. (Yuanbo Liu via gera)
Date Tue, 28 Feb 2017 17:48:46 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 5fb785e15 -> df35ba81f


YARN-1728. Workaround guice3x-undecoded pathInfo in YARN WebApp. (Yuanbo Liu via gera)


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

Branch: refs/heads/branch-2
Commit: df35ba81fe26f526a1534b72089fbb310efccdd9
Parents: 5fb785e
Author: Gera Shegalov <gera@apache.org>
Authored: Tue Feb 28 09:41:54 2017 -0800
Committer: Gera Shegalov <gera@apache.org>
Committed: Tue Feb 28 09:46:57 2017 -0800

----------------------------------------------------------------------
 .../apache/hadoop/yarn/webapp/Dispatcher.java   | 11 +++++++
 .../apache/hadoop/yarn/webapp/TestWebApp.java   | 31 +++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/df35ba81/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
index d519dbb..eed077a 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
@@ -21,6 +21,8 @@ package org.apache.hadoop.yarn.webapp;
 import static com.google.common.base.Preconditions.checkState;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -116,6 +118,15 @@ public class Dispatcher extends HttpServlet {
     if (pathInfo == null) {
       pathInfo = "/";
     }
+    // The implementation class of HttpServletRequest in
+    // Guice-3.0 does not decode paths that are encoded,
+    // decode path info here for further operation.
+    try {
+      pathInfo = new URI(pathInfo).getPath();
+    }  catch (URISyntaxException ex) {
+      // Just leave it alone for compatibility.
+      LOG.error(pathInfo + ": Failed to decode path.", ex);
+    }
     Controller.RequestContext rc =
         injector.getInstance(Controller.RequestContext.class);
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/df35ba81/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
index 9454002..db50dd3 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
@@ -27,12 +27,12 @@ import static org.apache.hadoop.yarn.webapp.view.JQueryUI._TH;
 import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID;
 import static org.apache.hadoop.yarn.webapp.view.JQueryUI.tableInit;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLEncoder;
 
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.hadoop.conf.Configuration;
@@ -263,6 +263,35 @@ public class TestWebApp {
     }
   }
 
+  @Test public void testEncodedUrl() throws Exception {
+    WebApp app =
+        WebApps.$for("test", TestWebApp.class, this, "ws").start(new WebApp() {
+          @Override
+          public void setup() {
+            bind(MyTestJAXBContextResolver.class);
+            bind(MyTestWebService.class);
+
+            route("/:foo", FooController.class);
+          }
+        });
+    String baseUrl = baseUrl(app);
+
+    try {
+      // Test encoded url
+      String rawPath = "localhost:8080";
+      String encodedUrl = baseUrl + "test/" +
+          URLEncoder.encode(rawPath, "UTF-8");
+      assertEquals("foo" + rawPath, getContent(encodedUrl).trim());
+
+      rawPath = "@;%$";
+      encodedUrl = baseUrl + "test/" +
+          URLEncoder.encode(rawPath, "UTF-8");
+      assertEquals("foo" + rawPath, getContent(encodedUrl).trim());
+    } finally {
+      app.stop();
+    }
+  }
+
   @Test public void testRobotsText() throws Exception {
     WebApp app =
         WebApps.$for("test", TestWebApp.class, this, "ws").start(new WebApp() {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message