/** Create a URI for redirecting request */ protected URI createRedirectUri( String servletpath, UserGroupInformation ugi, DatanodeID host, HttpServletRequest request, String tokenString) throws URISyntaxException { final String hostname = host instanceof DatanodeInfo ? ((DatanodeInfo) host).getHostName() : host.getHost(); final String scheme = request.getScheme(); final int port = "https".equals(scheme) ? (Integer) getServletContext().getAttribute("datanode.https.port") : host.getInfoPort(); final String filename = request.getPathInfo(); String dt = ""; if (tokenString != null) { dt = JspHelper.getDelegationTokenUrlParam(tokenString); } return new URI( scheme, null, hostname, port, servletpath, "filename=" + filename + "&ugi=" + ugi.getShortUserName() + dt, null); }
/** Create a redirection URL */ private URL createRedirectURL( String path, String encodedPath, HdfsFileStatus status, UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt) throws IOException { String scheme = request.getScheme(); final LocatedBlocks blks = nnproxy.getBlockLocations(status.getFullPath(new Path(path)).toUri().getPath(), 0, 1); final Configuration conf = NameNodeHttpServer.getConfFromContext(getServletContext()); final DatanodeID host = pickSrcDatanode(blks, status, conf); final String hostname; if (host instanceof DatanodeInfo) { hostname = host.getHostName(); } else { hostname = host.getIpAddr(); } int port = "https".equals(scheme) ? host.getInfoSecurePort() : host.getInfoPort(); String dtParam = ""; if (dt != null) { dtParam = JspHelper.getDelegationTokenUrlParam(dt); } // Add namenode address to the url params NameNode nn = NameNodeHttpServer.getNameNodeFromContext(getServletContext()); String addr = nn.getNameNodeAddressHostPortString(); String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr); return new URL( scheme, hostname, port, "/streamFile" + encodedPath + '?' + "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + dtParam + addrParam); }