|
@@ -25,6 +25,8 @@ import java.io.PrintWriter;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
|
+import java.util.List;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
@@ -48,6 +50,8 @@ import org.apache.hadoop.yarn.util.Apps;
|
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
|
import org.apache.hadoop.yarn.webapp.YarnWebParams;
|
|
import org.apache.hadoop.yarn.webapp.YarnWebParams;
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
|
+import org.apache.http.client.utils.URLEncodedUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -106,22 +110,40 @@ public class RMWebAppFilter extends GuiceContainer {
|
|
HttpServletResponse response, FilterChain chain) throws IOException,
|
|
HttpServletResponse response, FilterChain chain) throws IOException,
|
|
ServletException {
|
|
ServletException {
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
- String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
|
|
|
|
|
|
+ String htmlEscapedUri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
|
|
|
|
|
|
- if (uri == null) {
|
|
|
|
- uri = "/";
|
|
|
|
|
|
+ if (htmlEscapedUri == null) {
|
|
|
|
+ htmlEscapedUri = "/";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ String uriWithQueryString = htmlEscapedUri;
|
|
|
|
+ String htmlEscapedUriWithQueryString = htmlEscapedUri;
|
|
|
|
+
|
|
|
|
+ String queryString = request.getQueryString();
|
|
|
|
+ if (queryString != null && !queryString.isEmpty()) {
|
|
|
|
+ String reqEncoding = request.getCharacterEncoding();
|
|
|
|
+ if (reqEncoding == null || reqEncoding.isEmpty()) {
|
|
|
|
+ reqEncoding = "ISO-8859-1";
|
|
|
|
+ }
|
|
|
|
+ Charset encoding = Charset.forName(reqEncoding);
|
|
|
|
+ List<NameValuePair> params = URLEncodedUtils.parse(queryString, encoding);
|
|
|
|
+ String urlEncodedQueryString = URLEncodedUtils.format(params, encoding);
|
|
|
|
+ uriWithQueryString += "?" + urlEncodedQueryString;
|
|
|
|
+ htmlEscapedUriWithQueryString = HtmlQuoting.quoteHtmlChars(
|
|
|
|
+ request.getRequestURI() + "?" + urlEncodedQueryString);
|
|
|
|
+ }
|
|
|
|
+
|
|
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
|
|
RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
|
|
rmWebApp.checkIfStandbyRM();
|
|
rmWebApp.checkIfStandbyRM();
|
|
if (rmWebApp.isStandby()
|
|
if (rmWebApp.isStandby()
|
|
- && shouldRedirect(rmWebApp, uri)) {
|
|
|
|
|
|
+ && shouldRedirect(rmWebApp, htmlEscapedUri)) {
|
|
|
|
|
|
String redirectPath = rmWebApp.getRedirectPath();
|
|
String redirectPath = rmWebApp.getRedirectPath();
|
|
|
|
|
|
if (redirectPath != null && !redirectPath.isEmpty()) {
|
|
if (redirectPath != null && !redirectPath.isEmpty()) {
|
|
- redirectPath += uri;
|
|
|
|
- String redirectMsg =
|
|
|
|
- "This is standby RM. The redirect url is: " + redirectPath;
|
|
|
|
|
|
+ redirectPath += uriWithQueryString;
|
|
|
|
+ String redirectMsg = "This is standby RM. The redirect url is: "
|
|
|
|
+ + htmlEscapedUriWithQueryString;
|
|
PrintWriter out = response.getWriter();
|
|
PrintWriter out = response.getWriter();
|
|
out.println(redirectMsg);
|
|
out.println(redirectMsg);
|
|
response.setHeader("Location", redirectPath);
|
|
response.setHeader("Location", redirectPath);
|
|
@@ -142,7 +164,7 @@ public class RMWebAppFilter extends GuiceContainer {
|
|
int next = calculateExponentialTime(retryInterval);
|
|
int next = calculateExponentialTime(retryInterval);
|
|
|
|
|
|
String redirectUrl =
|
|
String redirectUrl =
|
|
- appendOrReplaceParamter(path + uri,
|
|
|
|
|
|
+ appendOrReplaceParamter(path + uriWithQueryString,
|
|
YarnWebParams.NEXT_REFRESH_INTERVAL + "=" + (retryInterval + 1));
|
|
YarnWebParams.NEXT_REFRESH_INTERVAL + "=" + (retryInterval + 1));
|
|
if (redirectUrl == null || next > MAX_SLEEP_TIME) {
|
|
if (redirectUrl == null || next > MAX_SLEEP_TIME) {
|
|
doRetry = false;
|
|
doRetry = false;
|
|
@@ -161,7 +183,7 @@ public class RMWebAppFilter extends GuiceContainer {
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
} else if (ahsEnabled) {
|
|
} else if (ahsEnabled) {
|
|
- String ahsRedirectUrl = ahsRedirectPath(uri, rmWebApp);
|
|
|
|
|
|
+ String ahsRedirectUrl = ahsRedirectPath(uriWithQueryString, rmWebApp);
|
|
if(ahsRedirectUrl != null) {
|
|
if(ahsRedirectUrl != null) {
|
|
response.setHeader("Location", ahsRedirectUrl);
|
|
response.setHeader("Location", ahsRedirectUrl);
|
|
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
|
|
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
|