HDFS-8741. Proper error msg to be printed when invalid operation type is given to WebHDFS operations. Contributed by Surendra Singh Lilhore.
This commit is contained in:
parent
fad766e1d2
commit
3536ce031c
@ -72,7 +72,16 @@ public String toQueryString() {
|
||||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public DeleteOpParam(final String str) {
|
||||
super(DOMAIN, DOMAIN.parse(str));
|
||||
super(DOMAIN, getOp(str));
|
||||
}
|
||||
|
||||
private static Op getOp(String str) {
|
||||
try {
|
||||
return DOMAIN.parse(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(str + " is not a valid " + Type.DELETE
|
||||
+ " operation.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +111,16 @@ public String toQueryString() {
|
||||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public GetOpParam(final String str) {
|
||||
super(DOMAIN, DOMAIN.parse(str));
|
||||
super(DOMAIN, getOp(str));
|
||||
}
|
||||
|
||||
private static Op getOp(String str) {
|
||||
try {
|
||||
return DOMAIN.parse(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(str + " is not a valid " + Type.GET
|
||||
+ " operation.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +80,16 @@ public String toQueryString() {
|
||||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public PostOpParam(final String str) {
|
||||
super(DOMAIN, DOMAIN.parse(str));
|
||||
super(DOMAIN, getOp(str));
|
||||
}
|
||||
|
||||
private static Op getOp(String str) {
|
||||
try {
|
||||
return DOMAIN.parse(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(str + " is not a valid " + Type.POST
|
||||
+ " operation.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +107,16 @@ public String toQueryString() {
|
||||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public PutOpParam(final String str) {
|
||||
super(DOMAIN, DOMAIN.parse(str));
|
||||
super(DOMAIN, getOp(str));
|
||||
}
|
||||
|
||||
private static Op getOp(String str) {
|
||||
try {
|
||||
return DOMAIN.parse(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(str + " is not a valid " + Type.PUT
|
||||
+ " operation.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,7 @@
|
||||
import org.apache.hadoop.fs.permission.AclEntry;
|
||||
import org.apache.hadoop.fs.permission.FsPermission;
|
||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||
import org.apache.hadoop.test.GenericTestUtils;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -503,4 +504,44 @@ public void testStoragePolicyParam() {
|
||||
p = new StoragePolicyParam("COLD");
|
||||
Assert.assertEquals("COLD", p.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpOpParams() {
|
||||
try {
|
||||
new PostOpParam("TEST");
|
||||
Assert
|
||||
.fail("Construct the PostOpParam with param value 'TEST' should be"
|
||||
+ " failed.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"TEST is not a valid POST operation.", e);
|
||||
}
|
||||
try {
|
||||
new PutOpParam("TEST");
|
||||
Assert
|
||||
.fail("Construct the PutOpParam with param value 'TEST' should be"
|
||||
+ " failed.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"TEST is not a valid PUT operation.", e);
|
||||
}
|
||||
try {
|
||||
new DeleteOpParam("TEST");
|
||||
Assert
|
||||
.fail("Construct the DeleteOpParam with param value 'TEST' should be"
|
||||
+ " failed.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"TEST is not a valid DELETE operation.", e);
|
||||
}
|
||||
try {
|
||||
new GetOpParam("TEST");
|
||||
Assert
|
||||
.fail("Construct the GetOpParam with param value 'TEST' should be"
|
||||
+ " failed.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
GenericTestUtils.assertExceptionContains(
|
||||
"TEST is not a valid GET operation.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user