Repository: knox
Updated Branches:
  refs/heads/master 189b55414 -> 27c1c0f8d


KNOX-1326 - Fix the Datanode link on the Namenode page


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

Branch: refs/heads/master
Commit: 27c1c0f8d10e3a763fc7b676d5f9c4ed087fc870
Parents: 189b554
Author: Sandeep More <m...@apache.org>
Authored: Mon May 21 11:44:16 2018 -0400
Committer: Sandeep More <m...@apache.org>
Committed: Mon May 21 11:44:16 2018 -0400

----------------------------------------------------------------------
 .../services/datanode/1.0.0/rewrite.xml         | 21 ++++---
 .../services/datanode/1.0.0/service.xml         |  1 +
 .../resources/services/hdfsui/2.7.0/rewrite.xml |  6 ++
 .../gateway/dispatch/URLDecodingDispatch.java   | 57 +++++++++++++++++
 .../dispatch/URLDecodingDispatchTest.java       | 65 ++++++++++++++++++++
 5 files changed, 141 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/27c1c0f8/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/rewrite.xml
----------------------------------------------------------------------
diff --git 
a/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/rewrite.xml
 
b/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/rewrite.xml
index b10de1a..439796f 100644
--- 
a/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/rewrite.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/rewrite.xml
@@ -38,14 +38,17 @@
        <rewrite template="{host}/logs/{**}"/>
     </rule>
 
-  <filter name="DATANODE/outbound/datanode/static">
-     <content type="*/html">
-      <apply path="dn.js"    rule="DATANODE/outbound/datanode/dn"/>
-    </content>
-    <content type="application/x-javascript">
-      <apply path="/jmx" rule="DATANODE/outbound/datanode/dfs/jmx"/>
-   </content>
-  </filter>
+    <filter name="DATANODE/outbound/datanode/static">
+        <content type="*/html">
+            <apply path="dn.js"    rule="DATANODE/outbound/datanode/dn"/>
+        </content>
+        <content type="application/x-javascript">
+            <apply path="/jmx" rule="DATANODE/outbound/datanode/dfs/jmx"/>
+        </content>
+        <content type="application/javascript">
+            <apply path="/jmx" rule="DATANODE/outbound/datanode/dfs/jmx"/>
+        </content>
+    </filter>
 
   <rule dir="OUT" name="DATANODE/outbound/datanode/window/location">
     <rewrite template="'{$inboundurl[host]}'"/>
@@ -66,7 +69,7 @@
   </rule>
 
   <rule dir="OUT" name="DATANODE/inbound/datanode/html" 
pattern="*0;url=datanode.html">
-    <rewrite 
template="0;url=/gateway/default/datanode/datanode.html?host={$inboundurl[host]}"/>
+      <rewrite 
template="{$prefix[0;url&amp;equals;,url]}/datanode/datanode.html?host={$inboundurl[host]}"/>
   </rule>
   <rule dir="OUT" name="DATANODE/datanode/outbound/logs/files" 
pattern="/logs/{**}">
     <rewrite 
template="{gateway.url}/datanode/logs/{**}?host={$inboundurl[host]}"/>

http://git-wip-us.apache.org/repos/asf/knox/blob/27c1c0f8/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/service.xml
----------------------------------------------------------------------
diff --git 
a/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/service.xml
index 39bd7dd..2d898cf 100644
--- 
a/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/datanode/1.0.0/service.xml
@@ -28,4 +28,5 @@
         </route>
         <route path="/datanode/?**"/>
     </routes>
+    <dispatch 
classname="org.apache.knox.gateway.dispatch.URLDecodingDispatch"/>
 </service>

http://git-wip-us.apache.org/repos/asf/knox/blob/27c1c0f8/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/rewrite.xml
----------------------------------------------------------------------
diff --git 
a/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/rewrite.xml
 
b/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/rewrite.xml
index 09350f4..1cd047b 100644
--- 
a/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/rewrite.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/rewrite.xml
@@ -92,6 +92,10 @@
     <match pattern="{infoSecureAddr}"/>
     <rewrite 
template="{$prefix[',url]}/datanode/?host=http://{infoSecureAddr}'"/>
   </rule>
+  <rule dir="OUT" name="HDFSUI/hdfs/outbound/datanode/address">
+    <match pattern="{dnWebAddress}"/>
+    <rewrite template="{$prefix[',url]}/datanode/?host={dnWebAddress}'"/>
+  </rule>
 
   <!-- Redirection rules that rewrite the Location reponse header  -->
   <filter name="HDFSUI/hdfs/outbound/headers/logs">
@@ -152,6 +156,8 @@
        <apply path="\'//\{infoSecureAddr\}\'" 
rule="HDFSUI/hdfs/outbound/datanode/infoSecureAddr"/>
        <!-- KNOX-1277 -->
        <apply path=".*dfshealth\.html" 
rule="HDFSUI/hdfs/inbound/namenode/root/filter/refresh-tag"/>
+       <!-- DN web Address Change -->
+       <apply path="\'\{dnWebAddress\}\'" 
rule="HDFSUI/hdfs/outbound/datanode/address"/>
     </content>
   </filter>
 

http://git-wip-us.apache.org/repos/asf/knox/blob/27c1c0f8/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java
----------------------------------------------------------------------
diff --git 
a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java
 
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java
new file mode 100644
index 0000000..eb0bab0
--- /dev/null
+++ 
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java
@@ -0,0 +1,57 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.dispatch;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.URI;
+import java.net.URLDecoder;
+
+/**
+ * Dispatch which decodes the outgoing URLs (to services).
+ * This is useful in cases where the url is picked up
+ * from the query parameter and is already encoded.
+ *
+ * @since 1.1.0
+ */
+public class URLDecodingDispatch extends DefaultDispatch {
+
+  public URLDecodingDispatch() {
+    super();
+  }
+
+  @Override
+  public URI getDispatchUrl(final HttpServletRequest request) {
+    String decoded;
+
+    try {
+      decoded = URLDecoder.decode(request.getRequestURL().toString(), "UTF-8" 
);
+    } catch (final Exception e) {
+      /* fall back in case of exception */
+      decoded = request.getRequestURL().toString();
+    }
+
+    final StringBuffer str = new StringBuffer(decoded);
+    final String query = request.getQueryString();
+    if ( query != null ) {
+      str.append('?');
+      str.append(query);
+    }
+    final URI url = URI.create(str.toString());
+    return url;
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/27c1c0f8/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/URLDecodingDispatchTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/URLDecodingDispatchTest.java
 
b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/URLDecodingDispatchTest.java
new file mode 100644
index 0000000..b030807
--- /dev/null
+++ 
b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/URLDecodingDispatchTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.dispatch;
+
+import org.apache.knox.test.TestUtils;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.URI;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test NoURLEncodingDispatch dispatch.
+ *
+ * @since 1.1.0
+ */
+public class URLDecodingDispatchTest {
+
+  HttpServletRequest request;
+  Dispatch dispatch = new URLDecodingDispatch();
+
+  public URLDecodingDispatchTest() {
+    super();
+  }
+
+  /**
+   * Test whether the encoded url is decoded properly.
+   *
+   * @throws Exception
+   */
+  @Test(timeout = TestUtils.MEDIUM_TIMEOUT)
+  public void testGetDispatchUrl() throws Exception {
+
+    final String path = 
"https://localhost:8443/gateway/sandbox/datanode/datanode.html?host=http%3A%2F%2Flocalhost%3A9864";;
+    URI uri;
+
+    request = EasyMock.createNiceMock(HttpServletRequest.class);
+    EasyMock.expect(request.getRequestURI()).andReturn(path).anyTimes();
+    EasyMock.expect(request.getRequestURL()).andReturn(new StringBuffer(path))
+        .anyTimes();
+    EasyMock.expect(request.getQueryString()).andReturn(null).anyTimes();
+    EasyMock.replay(request);
+    uri = dispatch.getDispatchUrl(request);
+    assertThat(uri.toASCIIString(),
+        
is("https://localhost:8443/gateway/sandbox/datanode/datanode.html?host=http://localhost:9864";));
+  }
+
+}

Reply via email to