Skip to content

Commit

Permalink
[REEF-781] Fix NPE on receiving filename query without arguments
Browse files Browse the repository at this point in the history
This fixes NullPointerException cases in `filename` query handling code
of HttpServerReefEventHandler.

JIRA:
  [REEF-781](https://issues.apache.org/jira/browse/REEF-781)

Pull Request:
  Closes apache#520
  • Loading branch information
dongjoon-hyun committed Sep 23, 2015
1 parent 0d9dc4f commit 877d87e
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.reef.util.logging.LoggingScopeFactory;
import org.apache.reef.util.logging.LoggingScopeImpl;
import org.apache.reef.wake.EventHandler;

import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -169,17 +170,17 @@ public void onHttpRequest(
final List names = parsedHttpRequest.getQueryMap().get("filename");
if (names == null || names.size() == 0) {
response.getWriter().println(String.format("File name is not provided"));
}

final String fileName = (String)names.get(0);
if (!fileName.equals(driverStdoutFile) && !fileName.equals(driverStderrFile)) {
response.getWriter().println(String.format("Unsupported file names: [%s] ", fileName));
}
try {
final byte[] outputBody = readFile((String) names.get(0)).getBytes(StandardCharsets.UTF_8);
response.getOutputStream().write(outputBody);
} catch(final IOException e) {
response.getWriter().println(String.format("Cannot find the log file: [%s].", fileName));
} else {
final String fileName = (String) names.get(0);
if (!fileName.equals(driverStdoutFile) && !fileName.equals(driverStderrFile)) {
response.getWriter().println(String.format("Unsupported file names: [%s] ", fileName));
}
try {
final byte[] outputBody = readFile((String) names.get(0)).getBytes(StandardCharsets.UTF_8);
response.getOutputStream().write(outputBody);
} catch (final IOException e) {
response.getWriter().println(String.format("Cannot find the log file: [%s].", fileName));
}
}
break;
default:
Expand Down Expand Up @@ -275,7 +276,7 @@ private void writeEvaluatorInfoWebOutput(
* Get all evaluator ids and send it back to response as JSON.
*/
private void writeEvaluatorsJsonOutput(final HttpServletResponse response) throws IOException {
LOG.log(Level.INFO, "HttpServerReefEventHandler getEvaluators is called");
LOG.log(Level.INFO, "HttpServerReefEventHandler writeEvaluatorsJsonOutput is called");
try {
final EvaluatorListSerializer serializer =
Tang.Factory.getTang().newInjector().getInstance(EvaluatorListSerializer.class);
Expand All @@ -297,7 +298,7 @@ private void writeEvaluatorsJsonOutput(final HttpServletResponse response) throw
*/
private void writeEvaluatorsWebOutput(final HttpServletResponse response) throws IOException {

LOG.log(Level.INFO, "HttpServerReefEventHandler getEvaluators is called");
LOG.log(Level.INFO, "HttpServerReefEventHandler writeEvaluatorsWebOutput is called");

final PrintWriter writer = response.getWriter();

Expand All @@ -324,6 +325,9 @@ private void writeEvaluatorsWebOutput(final HttpServletResponse response) throws
* Write Driver Info as JSON string to Response.
*/
private void writeDriverJsonInformation(final HttpServletResponse response) throws IOException {

LOG.log(Level.INFO, "HttpServerReefEventHandler writeDriverJsonInformation invoked.");

try {
final DriverInfoSerializer serializer =
Tang.Factory.getTang().newInjector().getInstance(DriverInfoSerializer.class);
Expand All @@ -350,7 +354,7 @@ private void writeResponse(final HttpServletResponse response, final String data
*/
private void writeDriverWebInformation(final HttpServletResponse response) throws IOException {

LOG.log(Level.INFO, "HttpServerReefEventHandler writeDriverInformation invoked.");
LOG.log(Level.INFO, "HttpServerReefEventHandler writeDriverWebInformation invoked.");

final PrintWriter writer = response.getWriter();

Expand Down

0 comments on commit 877d87e

Please sign in to comment.