|
@@ -40,13 +40,6 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.ws.rs.core.UriBuilder;
|
|
|
|
|
|
-import org.apache.commons.httpclient.Header;
|
|
|
-import org.apache.commons.httpclient.HostConfiguration;
|
|
|
-import org.apache.commons.httpclient.HttpClient;
|
|
|
-import org.apache.commons.httpclient.HttpMethod;
|
|
|
-import org.apache.commons.httpclient.cookie.CookiePolicy;
|
|
|
-import org.apache.commons.httpclient.methods.GetMethod;
|
|
|
-import org.apache.commons.httpclient.params.HttpClientParams;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
|
@@ -59,8 +52,15 @@ import org.apache.hadoop.yarn.util.TrackingUriPlugin;
|
|
|
import org.apache.hadoop.yarn.webapp.MimeType;
|
|
|
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
|
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
|
+import org.apache.http.Header;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.params.ClientPNames;
|
|
|
+import org.apache.http.client.params.CookiePolicy;
|
|
|
import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
+import org.apache.http.conn.params.ConnRoutePNames;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -155,23 +155,22 @@ public class WebAppProxyServlet extends HttpServlet {
|
|
|
private static void proxyLink(HttpServletRequest req,
|
|
|
HttpServletResponse resp, URI link, Cookie c, String proxyHost)
|
|
|
throws IOException {
|
|
|
- org.apache.commons.httpclient.URI uri =
|
|
|
- new org.apache.commons.httpclient.URI(link.toString(), false);
|
|
|
- HttpClientParams params = new HttpClientParams();
|
|
|
- params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
|
|
|
- params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
|
|
- HttpClient client = new HttpClient(params);
|
|
|
+ DefaultHttpClient client = new DefaultHttpClient();
|
|
|
+ client
|
|
|
+ .getParams()
|
|
|
+ .setParameter(ClientPNames.COOKIE_POLICY,
|
|
|
+ CookiePolicy.BROWSER_COMPATIBILITY)
|
|
|
+ .setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
|
|
|
// Make sure we send the request from the proxy address in the config
|
|
|
// since that is what the AM filter checks against. IP aliasing or
|
|
|
// similar could cause issues otherwise.
|
|
|
- HostConfiguration config = new HostConfiguration();
|
|
|
InetAddress localAddress = InetAddress.getByName(proxyHost);
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("local InetAddress for proxy host: {}", localAddress);
|
|
|
}
|
|
|
- config.setLocalAddress(localAddress);
|
|
|
- HttpMethod method = new GetMethod(uri.getEscapedURI());
|
|
|
- method.setRequestHeader("Connection","close");
|
|
|
+ client.getParams()
|
|
|
+ .setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress);
|
|
|
+ HttpGet httpGet = new HttpGet(link);
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Enumeration<String> names = req.getHeaderNames();
|
|
|
while(names.hasMoreElements()) {
|
|
@@ -181,30 +180,31 @@ public class WebAppProxyServlet extends HttpServlet {
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("REQ HEADER: {} : {}", name, value);
|
|
|
}
|
|
|
- method.setRequestHeader(name, value);
|
|
|
+ httpGet.setHeader(name, value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String user = req.getRemoteUser();
|
|
|
if (user != null && !user.isEmpty()) {
|
|
|
- method.setRequestHeader("Cookie",
|
|
|
+ httpGet.setHeader("Cookie",
|
|
|
PROXY_USER_COOKIE_NAME + "=" + URLEncoder.encode(user, "ASCII"));
|
|
|
}
|
|
|
OutputStream out = resp.getOutputStream();
|
|
|
try {
|
|
|
- resp.setStatus(client.executeMethod(config, method));
|
|
|
- for(Header header : method.getResponseHeaders()) {
|
|
|
+ HttpResponse httpResp = client.execute(httpGet);
|
|
|
+ resp.setStatus(httpResp.getStatusLine().getStatusCode());
|
|
|
+ for (Header header : httpResp.getAllHeaders()) {
|
|
|
resp.setHeader(header.getName(), header.getValue());
|
|
|
}
|
|
|
if (c != null) {
|
|
|
resp.addCookie(c);
|
|
|
}
|
|
|
- InputStream in = method.getResponseBodyAsStream();
|
|
|
+ InputStream in = httpResp.getEntity().getContent();
|
|
|
if (in != null) {
|
|
|
IOUtils.copyBytes(in, out, 4096, true);
|
|
|
}
|
|
|
} finally {
|
|
|
- method.releaseConnection();
|
|
|
+ httpGet.releaseConnection();
|
|
|
}
|
|
|
}
|
|
|
|