|
@@ -23,12 +23,14 @@ import java.io.IOException;
|
|
|
import java.net.InetAddress;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.UnknownHostException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.classification.InterfaceStability.Evolving;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.http.HtmlQuoting;
|
|
|
import org.apache.hadoop.http.HttpConfig.Policy;
|
|
|
import org.apache.hadoop.http.HttpServer2;
|
|
|
import org.apache.hadoop.net.NetUtils;
|
|
@@ -40,6 +42,10 @@ import org.apache.hadoop.yarn.factories.RecordFactory;
|
|
|
import org.apache.hadoop.yarn.util.RMHAUtils;
|
|
|
import org.apache.hadoop.yarn.webapp.BadRequestException;
|
|
|
import org.apache.hadoop.yarn.webapp.NotFoundException;
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
+import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
@Private
|
|
|
@Evolving
|
|
@@ -399,4 +405,49 @@ public class WebAppUtils {
|
|
|
}
|
|
|
return aid;
|
|
|
}
|
|
|
+
|
|
|
+ private static String getURLEncodedQueryString(HttpServletRequest request) {
|
|
|
+ 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);
|
|
|
+ return URLEncodedUtils.format(params, encoding);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get a HTML escaped uri with the query parameters of the request.
|
|
|
+ * @param request HttpServletRequest with the request details
|
|
|
+ * @return HTML escaped uri with the query paramters
|
|
|
+ */
|
|
|
+ public static String getHtmlEscapedURIWithQueryString(
|
|
|
+ HttpServletRequest request) {
|
|
|
+ String urlEncodedQueryString = getURLEncodedQueryString(request);
|
|
|
+ if (urlEncodedQueryString != null) {
|
|
|
+ return HtmlQuoting.quoteHtmlChars(
|
|
|
+ request.getRequestURI() + "?" + urlEncodedQueryString);
|
|
|
+ }
|
|
|
+ return HtmlQuoting.quoteHtmlChars(request.getRequestURI());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add the query params from a HttpServletRequest to the target uri passed.
|
|
|
+ * @param request HttpServletRequest with the request details
|
|
|
+ * @param targetUri the uri to which the query params must be added
|
|
|
+ * @return URL encoded string containing the targetUri + "?" + query string
|
|
|
+ */
|
|
|
+ public static String appendQueryParams(HttpServletRequest request,
|
|
|
+ String targetUri) {
|
|
|
+ String ret = targetUri;
|
|
|
+ String urlEncodedQueryString = getURLEncodedQueryString(request);
|
|
|
+ if (urlEncodedQueryString != null) {
|
|
|
+ ret += "?" + urlEncodedQueryString;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
}
|