-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KNOWAGE-8144 Update #888
KNOWAGE-8144 Update #888
Conversation
No longer catching an exception as requested. Informing the user in case file does not exist.
response.getOutputStream().flush(); | ||
} catch (Throwable t) { | ||
logger.error("Error getting file", t); | ||
if (!file.exists()) { | ||
writeBackToClient(404, "Error getting file with name, not found", false, null, "text/plain"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put "File not found" as message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated message.
FileInputStream fis = new FileInputStream(file); | ||
HttpServletResponse response = getHttpResponse(); | ||
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\";"); | ||
byte[] content = SpagoBIUtilities.getByteArrayFromInputStream(fis); | ||
response.setContentLength(content.length); | ||
response.getOutputStream().write(content); | ||
response.getOutputStream().flush(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part must be inserted within an else block:
if (!file.exists()) {
writeBackToClient...
}{
return file content
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included said chunk of code to else block.
Updated file check with else block so it stops execution in case file is not found.
if (!file.exists()) { | ||
writeBackToClient(404, "File not found.", false, null, "text/plain"); | ||
} else { | ||
FileInputStream fis = new FileInputStream(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed the try-with-resources block, stream will stay open intead of being closed (every stream must be closed).
Use:
try (FileInputStream fis = new FileInputStream(file)) {
HttpServletResponse response = getHttpResponse();
response.setHeader("Content-Disposition", "attachment; filename="" + file.getName() + "";");
byte[] content = SpagoBIUtilities.getByteArrayFromInputStream(fis);
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapped the code with try block.
Wrapped requested code with try block.
No longer catching an exception as requested.
Informing the user in case file does not exist.