WebAppProxyServlet extends HttpServlet { public WebAppProxyServlet() { super(); conf = new YarnConfiguration(); this.trackingUriPlugins = conf.getInstances(YarnConfiguration.YARN_TRACKING_URL_GENERATOR, TrackingUriPlugin.class); this.rmAppPageUrlBase = StringHelper.pjoin(WebAppUtils.getResolvedRMWebAppURLWithScheme(conf), "cluster", "app"); this.failurePageUrlBase = StringHelper.pjoin(WebAppUtils.getResolvedRMWebAppURLWithScheme(conf), "cluster", "failure"); this.ahsAppPageUrlBase = StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf), "applicationhistory", "app"); } WebAppProxyServlet();  static final String PROXY_USER_COOKIE_NAME; }
@Test(timeout=5000) public void testWebAppProxyServlet() throws Exception { configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090"); configuration.setInt("hadoop.http.max.threads", 10); WebAppProxyServerForTest proxy = new WebAppProxyServerForTest(); proxy.init(configuration); proxy.start(); int proxyPort = proxy.proxy.proxyServer.getConnectorAddress(0).getPort(); AppReportFetcherForTest appReportFetcher = proxy.proxy.appReportFetcher; try { URL emptyUrl = new URL("http: HttpURLConnection emptyProxyConn = (HttpURLConnection) emptyUrl .openConnection(); emptyProxyConn.connect(); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, emptyProxyConn.getResponseCode()); URL wrongUrl = new URL("http: HttpURLConnection proxyConn = (HttpURLConnection) wrongUrl .openConnection(); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, proxyConn.getResponseCode()); URL url = new URL("http: proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); assertTrue(isResponseCookiePresent( proxyConn, "checked_application_0_0000", "true")); URL redirectUrl = new URL("http: + "/proxy/redirect/application_00_0"); proxyConn = (HttpURLConnection) redirectUrl.openConnection(); proxyConn.setInstanceFollowRedirects(false); proxyConn.connect(); assertEquals("The proxy returned an unexpected status code rather than" + "redirecting the connection (302)", HttpURLConnection.HTTP_MOVED_TEMP, proxyConn.getResponseCode()); String expected = WebAppUtils.getResolvedRMWebAppURLWithScheme(configuration) + "/cluster/failure/application_00_0"; String redirect = proxyConn.getHeaderField(ProxyUtils.LOCATION); assertEquals("The proxy did not redirect the connection to the failure " + "page of the RM", expected, redirect); appReportFetcher.answer = 1; proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, proxyConn.getResponseCode()); assertFalse(isResponseCookiePresent( proxyConn, "checked_application_0_0000", "true")); appReportFetcher.answer = 4; proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, proxyConn.getResponseCode()); assertFalse(isResponseCookiePresent( proxyConn, "checked_application_0_0000", "true")); appReportFetcher.answer = 2; proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); String s = readInputStream(proxyConn.getInputStream()); assertTrue(s .contains("to continue to an Application Master web interface owned by")); assertTrue(s.contains("WARNING: The following page may not be safe!")); appReportFetcher.answer = 3; proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); appReportFetcher.answer = 5; URL clientUrl = new URL("http: + "/proxy/application_00_0/test/tez?x=y&h=p"); proxyConn = (HttpURLConnection) clientUrl.openConnection(); proxyConn.connect(); LOG.info("" + proxyConn.getURL()); LOG.info("ProxyConn.getHeaderField(): " + proxyConn.getHeaderField(ProxyUtils.LOCATION)); assertEquals("http: + "/foo/bar/test/tez?a=b&x=y&h=p#main", proxyConn.getURL().toString()); } finally { proxy.close(); } }