atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject atlas git commit: ATLAS-1985: fix incorrect URL-encoding while redirecting to active instance in HA
Date Tue, 25 Jul 2017 14:26:43 GMT
Repository: atlas
Updated Branches:
  refs/heads/master 2e8f6013f -> 6547af2d0


ATLAS-1985: fix incorrect URL-encoding while redirecting to active instance in HA

Change-Id: I919fcef66368c10b1f8a752043c422a333835508

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


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

Branch: refs/heads/master
Commit: 6547af2d035fae7402d7a4d77e640e0599fb1075
Parents: 2e8f601
Author: nixonrodrigues <nixon@apache.org>
Authored: Mon Jul 24 18:43:31 2017 +0530
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Tue Jul 25 07:09:42 2017 -0700

----------------------------------------------------------------------
 .../atlas/web/filters/ActiveServerFilter.java   | 15 +++++++++-----
 .../web/filters/ActiveServerFilterTest.java     | 21 +++++++++++++++++++-
 2 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/6547af2d/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
index 29d829f..c68c4b2 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
@@ -20,7 +20,6 @@ package org.apache.atlas.web.filters;
 
 import org.apache.atlas.web.service.ActiveInstanceState;
 import org.apache.atlas.web.service.ServiceState;
-import org.apache.hadoop.http.HtmlQuoting;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -37,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.HttpHeaders;
 import java.io.IOException;
+import java.net.URLEncoder;
 
 /**
  * A servlet {@link Filter} that redirects web requests from a passive Atlas server instance
to an active one.
@@ -127,14 +127,19 @@ public class ActiveServerFilter implements Filter {
                                 String activeServerAddress) throws IOException {
         String requestURI = servletRequest.getRequestURI();
         String queryString = servletRequest.getQueryString();
+
+        if (queryString != null && (!queryString.isEmpty())) {
+            queryString = URLEncoder.encode(queryString, "UTF-8");
+        }
+
         if ((queryString != null) && (!queryString.isEmpty())) {
             requestURI += "?" + queryString;
         }
-        String quotedUri = HtmlQuoting.quoteHtmlChars(requestURI);
-        if (quotedUri == null) {
-            quotedUri = "/";
+
+        if (requestURI == null) {
+            requestURI = "/";
         }
-        String redirectLocation = activeServerAddress + quotedUri;
+        String redirectLocation = activeServerAddress + requestURI;
         LOG.info("Not active. Redirecting to {}", redirectLocation);
         // A POST/PUT/DELETE require special handling by sending HTTP 307 instead of the
regular 301/302.
         // Reference: http://stackoverflow.com/questions/2068418/whats-the-difference-between-a-302-and-a-307-redirect

http://git-wip-us.apache.org/repos/asf/atlas/blob/6547af2d/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
index 3396072..60f3d48 100644
--- a/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
@@ -137,11 +137,30 @@ public class ActiveServerFilterTest {
 
         activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
 
-        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + "types?query=TRAIT");
+        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS + "types?query%3DTRAIT");
 
     }
 
     @Test
+    public void testRedirectedRequestShouldContainEncodeQueryParameters() throws IOException,
ServletException {
+        when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
+
+        ActiveServerFilter activeServerFilter = new ActiveServerFilter(activeInstanceState,
serviceState);
+
+        when(activeInstanceState.getActiveServerAddress()).thenReturn(ACTIVE_SERVER_ADDRESS);
+        when(servletRequest.getMethod()).thenReturn(HttpMethod.GET);
+        when(servletRequest.getRequestURI()).thenReturn("api/atlas/v2/search/basic");
+        when(servletRequest.getQueryString()).thenReturn("limit=25&excludeDeletedEntities=true&classification=ETL&_=1500969656054");
+
+        activeServerFilter.doFilter(servletRequest, servletResponse, filterChain);
+
+        verify(servletResponse).sendRedirect(ACTIVE_SERVER_ADDRESS +
+                "api/atlas/v2/search/basic?limit%3D25%26excludeDeletedEntities%3Dtrue%26classification%3DETL%26_%3D1500969656054");
+
+    }
+
+
+    @Test
     public void testShouldRedirectPOSTRequest() throws IOException, ServletException {
         when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
         when(servletRequest.getRequestURI()).thenReturn("api/atlas/types");


Mime
View raw message