Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
6547af2d
Commit
6547af2d
authored
Jul 24, 2017
by
nixonrodrigues
Committed by
Madhan Neethiraj
Jul 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1985: fix incorrect URL-encoding while redirecting to active instance in HA
Change-Id: I919fcef66368c10b1f8a752043c422a333835508 Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
2e8f6013
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
ActiveServerFilter.java
...java/org/apache/atlas/web/filters/ActiveServerFilter.java
+10
-5
ActiveServerFilterTest.java
.../org/apache/atlas/web/filters/ActiveServerFilterTest.java
+20
-1
No files found.
webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
View file @
6547af2d
...
...
@@ -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
...
...
webapp/src/test/java/org/apache/atlas/web/filters/ActiveServerFilterTest.java
View file @
6547af2d
...
...
@@ -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
%3D
TRAIT"
);
}
@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"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment