解决文件不存在时出现的异常
This commit is contained in:
@@ -46,21 +46,28 @@ public class FileAction extends Action {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File file = getFileByPath(request.getPath());
|
File file = null;
|
||||||
Logger.debug("Client [{}] get file [{}]", request.getIp(), file.getPath());
|
try {
|
||||||
|
file = getFileByPath(request.getPath());
|
||||||
|
} catch (Exception e) {
|
||||||
|
response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// 隐藏文件,跳过
|
// 隐藏文件或不存在,跳过
|
||||||
if (file.isHidden() || !file.exists()) {
|
if (file == null || file.isHidden() || !file.exists()) {
|
||||||
response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!");
|
response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 非文件,跳过
|
// 非文件,跳过
|
||||||
if (false == file.isFile()) {
|
if (!file.isFile()) {
|
||||||
response.sendError(HttpResponseStatus.FORBIDDEN, "403 Forbidden!");
|
response.sendError(HttpResponseStatus.FORBIDDEN, "403 Forbidden!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.debug("Client [{}] get file [{}]", request.getIp(), file.getPath());
|
||||||
|
|
||||||
// Cache Validation
|
// Cache Validation
|
||||||
String ifModifiedSince = request.getHeader(HttpHeaderNames.IF_MODIFIED_SINCE.toString());
|
String ifModifiedSince = request.getHeader(HttpHeaderNames.IF_MODIFIED_SINCE.toString());
|
||||||
if (StrUtil.isNotBlank(ifModifiedSince)) {
|
if (StrUtil.isNotBlank(ifModifiedSince)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user