You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2009/05/15 01:43:20 UTC
svn commit: r774965 - in /hadoop/core/trunk: ./
src/hdfs/org/apache/hadoop/hdfs/server/namenode/ src/webapps/datanode/
Author: szetszwo
Date: Thu May 14 23:43:20 2009
New Revision: 774965
URL: http://svn.apache.org/viewvc?rev=774965&view=rev
Log:
HADOOP-5820. Fix findbugs warnings for http related codes in hdfs.
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/JspHelper.java
hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/StreamFile.java
hadoop/core/trunk/src/webapps/datanode/browseBlock.jsp
hadoop/core/trunk/src/webapps/datanode/browseDirectory.jsp
hadoop/core/trunk/src/webapps/datanode/tail.jsp
Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu May 14 23:43:20 2009
@@ -582,6 +582,9 @@
HADOOP-5818. Revert the renaming from FSNamesystem.checkSuperuserPrivilege
to checkAccess by HADOOP-5643. (Amar Kamat via szetszwo)
+ HADOOP-5820. Fix findbugs warnings for http related codes in hdfs.
+ (szetszwo)
+
Release 0.20.1 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/JspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/JspHelper.java?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/JspHelper.java (original)
+++ hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/JspHelper.java Thu May 14 23:43:20 2009
@@ -21,7 +21,10 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
import java.net.Socket;
+import java.net.URL;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -391,4 +394,36 @@
+ "\n <tr><td id='col1'>Compiled:</td><td>" + VersionInfo.getDate() + " by " + VersionInfo.getUser() + " from " + VersionInfo.getBranch()
+ "\n</table></div>";
}
-}
+
+ /**
+ * Validate filename.
+ * @return null if the filename is invalid.
+ * Otherwise, return the validated filename.
+ */
+ public static String validatePath(String p) {
+ return p == null || p.length() == 0?
+ null: new Path(p).toUri().getPath();
+ }
+
+ /**
+ * Validate a long value.
+ * @return null if the value is invalid.
+ * Otherwise, return the validated Long object.
+ */
+ public static Long validateLong(String value) {
+ return value == null? null: Long.parseLong(value);
+ }
+
+ /**
+ * Validate a URL.
+ * @return null if the value is invalid.
+ * Otherwise, return the validated URL String.
+ */
+ public static String validateURL(String value) {
+ try {
+ return URLEncoder.encode(new URL(value).toString(), "UTF-8");
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Modified: hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/StreamFile.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/StreamFile.java?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/StreamFile.java (original)
+++ hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/StreamFile.java Thu May 14 23:43:20 2009
@@ -17,17 +17,25 @@
*/
package org.apache.hadoop.hdfs.server.namenode;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import java.io.*;
-import java.net.*;
-import org.apache.hadoop.fs.*;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.InetSocketAddress;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSInputStream;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.security.UnixUserGroupInformation;
-import org.apache.hadoop.conf.*;
public class StreamFile extends DfsServlet {
+ /** for java.io.Serializable */
+ private static final long serialVersionUID = 1L;
+
static InetSocketAddress nameNodeAddr;
static DataNode datanode = null;
private static final Configuration masterConf = new Configuration();
@@ -48,8 +56,9 @@
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- String filename = request.getParameter("filename");
- if (filename == null || filename.length() == 0) {
+ final String filename = JspHelper.validatePath(
+ request.getParameter("filename"));
+ if (filename == null) {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.print("Invalid input");
Modified: hadoop/core/trunk/src/webapps/datanode/browseBlock.jsp
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/webapps/datanode/browseBlock.jsp?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/src/webapps/datanode/browseBlock.jsp (original)
+++ hadoop/core/trunk/src/webapps/datanode/browseBlock.jsp Thu May 14 23:43:20 2009
@@ -24,17 +24,13 @@
import="java.io.*"
import="java.util.*"
import="java.net.*"
+
import="org.apache.hadoop.hdfs.*"
import="org.apache.hadoop.hdfs.server.namenode.*"
- import="org.apache.hadoop.hdfs.server.datanode.*"
import="org.apache.hadoop.hdfs.protocol.*"
- import="org.apache.hadoop.io.*"
- import="org.apache.hadoop.conf.*"
- import="org.apache.hadoop.net.DNS"
import="org.apache.hadoop.security.AccessToken"
import="org.apache.hadoop.security.AccessTokenHandler"
import="org.apache.hadoop.util.*"
- import="java.text.DateFormat"
%>
<%!
@@ -46,14 +42,11 @@
long startOffset = 0;
int datanodePort;
- String blockIdStr = null;
- long currBlockId = 0;
- blockIdStr = req.getParameter("blockId");
- if (blockIdStr == null) {
+ final Long blockId = JspHelper.validateLong(req.getParameter("blockId"));
+ if (blockId == null) {
out.print("Invalid input (blockId absent)");
return;
}
- currBlockId = Long.parseLong(blockIdStr);
String datanodePortStr = req.getParameter("datanodePort");
if (datanodePortStr == null) {
@@ -74,8 +67,9 @@
startOffset = 0;
else startOffset = Long.parseLong(startOffsetStr);
- String filename = req.getParameter("filename");
- if (filename == null || filename.length() == 0) {
+ final String filename = JspHelper.validatePath(
+ req.getParameter("filename"));
+ if (filename == null) {
out.print("Invalid input");
return;
}
@@ -102,7 +96,6 @@
DatanodeInfo chosenNode;
//URL for TAIL
LocatedBlock lastBlk = blocks.get(blocks.size() - 1);
- long blockId = lastBlk.getBlock().getBlockId();
try {
chosenNode = JspHelper.bestNode(lastBlk);
} catch (IOException e) {
@@ -124,7 +117,7 @@
out.print("<form action=\"/browseBlock.jsp\" method=GET>");
out.print("<b>Chunk size to view (in bytes, up to file's DFS block size): </b>");
- out.print("<input type=\"hidden\" name=\"blockId\" value=\"" + currBlockId +
+ out.print("<input type=\"hidden\" name=\"blockId\" value=\"" + blockId +
"\">");
out.print("<input type=\"hidden\" name=\"blockSize\" value=\"" +
blockSize + "\">");
@@ -147,10 +140,9 @@
out.println("\n<table>");
for (LocatedBlock cur : blocks) {
out.print("<tr>");
- blockId = cur.getBlock().getBlockId();
+ final String blockidstring = Long.toString(cur.getBlock().getBlockId());
blockSize = cur.getBlock().getNumBytes();
- String blk = "blk_" + Long.toString(blockId);
- out.print("<td>"+Long.toString(blockId)+":</td>");
+ out.print("<td>"+blockidstring+":</td>");
DatanodeInfo[] locs = cur.getLocations();
for(int j=0; j<locs.length; j++) {
String datanodeAddr = locs[j].getName();
@@ -160,7 +152,7 @@
fqdn = InetAddress.getByName(locs[j].getHost()).getCanonicalHostName();
String blockUrl = "http://"+ fqdn + ":" +
locs[j].getInfoPort() +
- "/browseBlock.jsp?blockId=" + Long.toString(blockId) +
+ "/browseBlock.jsp?blockId=" + blockidstring +
"&blockSize=" + blockSize +
"&filename=" + URLEncoder.encode(filename, "UTF-8")+
"&datanodePort=" + datanodePort +
@@ -191,20 +183,18 @@
if (namenodeInfoPortStr != null)
namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);
- String filename = req.getParameter("filename");
+ final String filename = JspHelper.validatePath(
+ req.getParameter("filename"));
if (filename == null) {
out.print("Invalid input (filename absent)");
return;
}
- String blockIdStr = null;
- long blockId = 0;
- blockIdStr = req.getParameter("blockId");
- if (blockIdStr == null) {
+ final Long blockId = JspHelper.validateLong(req.getParameter("blockId"));
+ if (blockId == null) {
out.print("Invalid input (blockId absent)");
return;
}
- blockId = Long.parseLong(blockIdStr);
final DFSClient dfs = new DFSClient(datanode.getNameNodeAddr(), JspHelper.conf);
@@ -226,14 +216,11 @@
}
}
- String blockGenStamp = null;
- long genStamp = 0;
- blockGenStamp = req.getParameter("genstamp");
- if (blockGenStamp == null) {
+ final Long genStamp = JspHelper.validateLong(req.getParameter("genstamp"));
+ if (genStamp == null) {
out.print("Invalid input (genstamp absent)");
return;
}
- genStamp = Long.parseLong(blockGenStamp);
String blockSizeStr;
long blockSize = 0;
@@ -307,10 +294,10 @@
}
else {
//we are in the same block
- nextBlockIdStr = blockIdStr;
+ nextBlockIdStr = blockId.toString();
nextStartOffset = startOffset + chunkSizeToView;
nextBlockSize = blockSize;
- nextGenStamp = blockGenStamp;
+ nextGenStamp = genStamp.toString();
}
String nextUrl = null;
if (nextBlockIdStr != null) {
@@ -361,11 +348,11 @@
}
else {
//we are in the same block
- prevBlockIdStr = blockIdStr;
+ prevBlockIdStr = blockId.toString();
prevStartOffset = startOffset - chunkSizeToView;
if (prevStartOffset < 0) prevStartOffset = 0;
prevBlockSize = blockSize;
- prevGenStamp = blockGenStamp;
+ prevGenStamp = genStamp.toString();
}
String prevUrl = null;
Modified: hadoop/core/trunk/src/webapps/datanode/browseDirectory.jsp
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/webapps/datanode/browseDirectory.jsp?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/src/webapps/datanode/browseDirectory.jsp (original)
+++ hadoop/core/trunk/src/webapps/datanode/browseDirectory.jsp Thu May 14 23:43:20 2009
@@ -24,16 +24,12 @@
import="java.io.*"
import="java.util.*"
import="java.net.*"
+
import="org.apache.hadoop.fs.*"
import="org.apache.hadoop.hdfs.*"
import="org.apache.hadoop.hdfs.server.namenode.*"
- import="org.apache.hadoop.hdfs.server.datanode.*"
import="org.apache.hadoop.hdfs.protocol.*"
- import="org.apache.hadoop.io.*"
- import="org.apache.hadoop.conf.*"
- import="org.apache.hadoop.net.DNS"
import="org.apache.hadoop.util.*"
- import="java.text.DateFormat"
%>
<%!
static final DataNode datanode = DataNode.getDataNode();
@@ -42,8 +38,8 @@
HttpServletRequest req,
HttpServletResponse resp)
throws IOException {
- String dir = req.getParameter("dir");
- if (dir == null || dir.length() == 0) {
+ final String dir = JspHelper.validatePath(req.getParameter("dir"));
+ if (dir == null) {
out.print("Invalid input");
return;
}
Modified: hadoop/core/trunk/src/webapps/datanode/tail.jsp
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/webapps/datanode/tail.jsp?rev=774965&r1=774964&r2=774965&view=diff
==============================================================================
--- hadoop/core/trunk/src/webapps/datanode/tail.jsp (original)
+++ hadoop/core/trunk/src/webapps/datanode/tail.jsp Thu May 14 23:43:20 2009
@@ -24,17 +24,13 @@
import="java.io.*"
import="java.util.*"
import="java.net.*"
+
import="org.apache.hadoop.hdfs.*"
import="org.apache.hadoop.hdfs.server.namenode.*"
- import="org.apache.hadoop.hdfs.server.datanode.*"
import="org.apache.hadoop.hdfs.protocol.*"
- import="org.apache.hadoop.io.*"
- import="org.apache.hadoop.conf.*"
- import="org.apache.hadoop.net.DNS"
import="org.apache.hadoop.security.AccessToken"
import="org.apache.hadoop.util.*"
import="org.apache.hadoop.net.NetUtils"
- import="java.text.DateFormat"
%>
<%!
@@ -42,13 +38,14 @@
public void generateFileChunks(JspWriter out, HttpServletRequest req)
throws IOException {
- String referrer = req.getParameter("referrer");
+ final String referrer = JspHelper.validateURL(req.getParameter("referrer"));
boolean noLink = false;
if (referrer == null) {
noLink = true;
}
- String filename = req.getParameter("filename");
+ final String filename = JspHelper.validatePath(
+ req.getParameter("filename"));
if (filename == null) {
out.print("Invalid input (file name absent)");
return;