Commit b2f1b394 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Avoid sending an error after a (partial) response.

Also take out some unused code.

Fixes #24823.
parent 7dce6a5f
# Changes in version ????
* Minor changes
- Avoid sending an error after a (partial) response.
# Changes in version 1.0.3 - 2017-12-20
* Major changes
......
......@@ -56,26 +56,16 @@ public class ResearchStatsServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String requestUri = request.getRequestURI();
if (requestUri.equals("/metrics/stats/")) {
this.writeDirectoryListing(request, response);
File statsFile = this.determineStatsFile(request);
if (statsFile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else if (!statsFile.exists()) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} else {
File statsFile = this.determineStatsFile(request);
if (statsFile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} else if (!this.writeStatsFile(statsFile, response)) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
this.writeStatsFile(statsFile, response);
}
}
private void writeDirectoryListing(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", "/?type=dt&level=ad");
}
private File determineStatsFile(HttpServletRequest request) {
String requestedStatsFile = request.getRequestURI();
if (requestedStatsFile.endsWith(".csv")) {
......@@ -93,11 +83,8 @@ public class ResearchStatsServlet extends HttpServlet {
}
}
private boolean writeStatsFile(File statsFile,
private void writeStatsFile(File statsFile,
HttpServletResponse response) throws IOException, ServletException {
if (!statsFile.exists()) {
return false;
}
response.setContentType("text/csv");
response.setHeader("Content-Length", String.valueOf(
statsFile.length()));
......@@ -112,10 +99,7 @@ public class ResearchStatsServlet extends HttpServlet {
while ((length = bis.read(buffer)) > 0) {
bos.write(buffer, 0, length);
}
} catch (IOException e) {
return false;
}
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment