diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/CreateParentParam.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/CreateParentParam.java index eaa5e8d7e69..029efa04a05 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/CreateParentParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/CreateParentParam.java @@ -39,7 +39,7 @@ public class CreateParentParam extends BooleanParam { * @param str a string representation of the parameter value. */ public CreateParentParam(final String str) { - this(DOMAIN.parse(str)); + this(DOMAIN.parse(str == null ? DEFAULT : str)); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/OverwriteParam.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/OverwriteParam.java index 9610b93deed..d7f5fb0ded6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/OverwriteParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/OverwriteParam.java @@ -39,7 +39,7 @@ public class OverwriteParam extends BooleanParam { * @param str a string representation of the parameter value. */ public OverwriteParam(final String str) { - this(DOMAIN.parse(str)); + super(DOMAIN, DOMAIN.parse(str == null ? DEFAULT : str)); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java index 45b363ad3ee..925edcf1f79 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.text.MessageFormat; import java.util.Arrays; import java.util.Map; import java.util.Random; @@ -49,6 +50,7 @@ import org.apache.hadoop.hdfs.web.resources.NamenodeAddressParam; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Assert; import org.junit.Test; @@ -533,6 +535,44 @@ public class TestWebHdfsFileSystemContract extends FileSystemContractBaseTest { } } + public void testDatanodeCreateMissingParameter() throws IOException { + final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) fs; + final Path testDir = new Path(MessageFormat.format("/test/{0}/{1}", + TestWebHdfsFileSystemContract.class, + GenericTestUtils.getMethodName())); + assertTrue(webhdfs.mkdirs(testDir)); + + for (String dnCreateParam : new String[]{ + CreateFlagParam.NAME, + CreateParentParam.NAME, + OverwriteParam.NAME + }) { + final HttpOpParam.Op op = PutOpParam.Op.CREATE; + final Path newfile = new Path(testDir, "newfile_" + dnCreateParam); + final URL url = webhdfs.toUrl(op, newfile); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod(op.getType().toString()); + conn.setDoOutput(false); + conn.setInstanceFollowRedirects(false); + conn.connect(); + final String redirect = conn.getHeaderField("Location"); + conn.disconnect(); + + //remove createparent + WebHdfsFileSystem.LOG.info("redirect = " + redirect); + String re = "&" + dnCreateParam + "=[^&]*"; + String modified = redirect.replaceAll(re, ""); + WebHdfsFileSystem.LOG.info("modified = " + modified); + + //connect to datanode + conn = (HttpURLConnection)new URL(modified).openConnection(); + conn.setRequestMethod(op.getType().toString()); + conn.setDoOutput(op.getDoOutput()); + conn.connect(); + assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); + } + } + @Test public void testAccess() throws IOException, InterruptedException { Path p1 = new Path("/pathX");