diff --git a/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileChecksumServlets.java b/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileChecksumServlets.java index 13862bbe518..b7587c0dd1c 100644 --- a/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileChecksumServlets.java +++ b/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileChecksumServlets.java @@ -59,7 +59,7 @@ public class FileChecksumServlets { /** Create a redirection URL */ private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host, HttpServletRequest request, NameNode nn) - throws IOException, URISyntaxException { + throws IOException { final String hostname = host instanceof DatanodeInfo ? ((DatanodeInfo)host).getHostName() : host.getHost(); final String scheme = request.getScheme(); @@ -94,8 +94,6 @@ public class FileChecksumServlets { try { response.sendRedirect( createRedirectURL(ugi, datanode, request, namenode).toString()); - } catch(URISyntaxException e) { - throw new ServletException(e); } catch (IOException e) { response.sendError(400, e.getMessage()); } diff --git a/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileDataServlet.java b/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileDataServlet.java index 403d9aa7429..54b0ec64abc 100644 --- a/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileDataServlet.java +++ b/hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileDataServlet.java @@ -48,7 +48,7 @@ public class FileDataServlet extends DfsServlet { /** Create a redirection URL */ private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt) - throws IOException, URISyntaxException { + throws IOException { String scheme = request.getScheme(); final LocatedBlocks blks = nnproxy.getBlockLocations( status.getFullPath(new Path(path)).toUri().getPath(), 0, 1); @@ -121,12 +121,8 @@ public class FileDataServlet extends DfsServlet { HdfsFileStatus info = nn.getFileInfo(path); if (info != null && !info.isDir()) { - try { - response.sendRedirect(createRedirectURL(path, encodedPath, - info, ugi, nn, request, delegationToken).toString()); - } catch (URISyntaxException e) { - response.getWriter().println(e.toString()); - } + response.sendRedirect(createRedirectURL(path, encodedPath, + info, ugi, nn, request, delegationToken).toString()); } else if (info == null) { response.sendError(400, "File not found " + path); } else { diff --git a/hdfs/src/test/aop/org/apache/hadoop/hdfs/server/namenode/FileDataServletAspects.aj b/hdfs/src/test/aop/org/apache/hadoop/hdfs/server/namenode/FileDataServletAspects.aj index cbe34a8695b..6e74bca549c 100644 --- a/hdfs/src/test/aop/org/apache/hadoop/hdfs/server/namenode/FileDataServletAspects.aj +++ b/hdfs/src/test/aop/org/apache/hadoop/hdfs/server/namenode/FileDataServletAspects.aj @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hdfs.server.namenode; -import java.net.URI; -import java.net.URISyntaxException; +import java.net.URL; +import java.io.IOException; import javax.servlet.http.HttpServletRequest; @@ -30,18 +30,17 @@ import org.apache.hadoop.security.UserGroupInformation; public aspect FileDataServletAspects { static final Log LOG = FileDataServlet.LOG; - pointcut callCreateUri() : call (URI FileDataServlet.createUri( - String, HdfsFileStatus, UserGroupInformation, ClientProtocol, + pointcut callCreateUrl() : call (URL FileDataServlet.createRedirectURL( + String, String, HdfsFileStatus, UserGroupInformation, ClientProtocol, HttpServletRequest, String)); /** Replace host name with "localhost" for unit test environment. */ - URI around () throws URISyntaxException : callCreateUri() { - final URI original = proceed(); - LOG.info("FI: original uri = " + original); - final URI replaced = new URI(original.getScheme(), original.getUserInfo(), - "localhost", original.getPort(), original.getPath(), - original.getQuery(), original.getFragment()) ; - LOG.info("FI: replaced uri = " + replaced); + URL around () throws IOException : callCreateUrl() { + final URL original = proceed(); + LOG.info("FI: original url = " + original); + final URL replaced = new URL("http", "localhost", original.getPort(), + original.getPath() + '?' + original.getQuery()); + LOG.info("FI: replaced url = " + replaced); return replaced; } }