HDFS-14242. OIV WebImageViewer: NPE when param op is not specified. Contributed by Siyao Meng.
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
parent
d3de8e162b
commit
6aa63452b3
|
@ -85,10 +85,15 @@ class FSImageHandler extends SimpleChannelInboundHandler<HttpRequest> {
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
|
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
|
||||||
|
// check path. throw exception if path doesn't start with WEBHDFS_PREFIX
|
||||||
|
String path = getPath(decoder);
|
||||||
final String op = getOp(decoder);
|
final String op = getOp(decoder);
|
||||||
|
// check null op
|
||||||
|
if (op == null) {
|
||||||
|
throw new IllegalArgumentException("Param op must be specified.");
|
||||||
|
}
|
||||||
|
|
||||||
final String content;
|
final String content;
|
||||||
String path = getPath(decoder);
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case "GETFILESTATUS":
|
case "GETFILESTATUS":
|
||||||
content = image.getFileStatus(path);
|
content = image.getFileStatus(path);
|
||||||
|
|
|
@ -624,6 +624,25 @@ public class TestOfflineImageViewer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWebImageViewerNullOp() throws Exception {
|
||||||
|
WebImageViewer viewer = new WebImageViewer(
|
||||||
|
NetUtils.createSocketAddr("localhost:0"));
|
||||||
|
try {
|
||||||
|
viewer.initServer(originalFsimage.getAbsolutePath());
|
||||||
|
int port = viewer.getPort();
|
||||||
|
|
||||||
|
// null op
|
||||||
|
URL url = new URL("http://localhost:" + port +
|
||||||
|
"/webhdfs/v1/");
|
||||||
|
// should get HTTP_BAD_REQUEST. NPE gets HTTP_INTERNAL_ERROR
|
||||||
|
verifyHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, url);
|
||||||
|
} finally {
|
||||||
|
// shutdown the viewer
|
||||||
|
viewer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWebImageViewerSecureMode() throws Exception {
|
public void testWebImageViewerSecureMode() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
|
|
Loading…
Reference in New Issue