public static Credentials getDTfromRemote(String nnAddr, String renewer) throws IOException { DataInputStream dis = null; try { StringBuffer url = new StringBuffer(); if (renewer != null) { url.append(nnAddr) .append(GetDelegationTokenServlet.PATH_SPEC) .append("?") .append(GetDelegationTokenServlet.RENEWER) .append("=") .append(renewer); } else { url.append(nnAddr).append(GetDelegationTokenServlet.PATH_SPEC); } if (LOG.isDebugEnabled()) { LOG.debug("Retrieving token from: " + url); } URL remoteURL = new URL(url.toString()); SecurityUtil.fetchServiceTicket(remoteURL); URLConnection connection = remoteURL.openConnection(); InputStream in = connection.getInputStream(); Credentials ts = new Credentials(); dis = new DataInputStream(in); ts.readFields(dis); for (Token<?> token : ts.getAllTokens()) { token.setKind(HftpFileSystem.TOKEN_KIND); token.setService( new Text( SecurityUtil.buildDTServiceName( remoteURL.toURI(), DFSConfigKeys.DFS_HTTPS_PORT_DEFAULT))); } return ts; } catch (Exception e) { throw new IOException("Unable to obtain remote token", e); } finally { if (dis != null) dis.close(); } }