Skip to content

Commit

Permalink
Don't allow null return from wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Dec 1, 2016
1 parent 43bf7af commit 65501a8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/main/java/org/elasticsearch/rest/RestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.rest;

import java.io.IOException;
import java.util.Objects;
import java.util.Set;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -148,19 +149,19 @@ public void dispatchRequest(final RestRequest request, final RestChannel channel
}
}

final RestHandler rawHandler = getHandler(request);
final RestHandler handler = handlerWrapper.apply(rawHandler);
final RestHandler handler = getHandler(request);

if (handler != null) {
handler.handleRequest(request, channel, client);
} else {
if (handler == null) {
if (request.method() == RestRequest.Method.OPTIONS) {
// when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added)
channel.sendResponse(new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
} else {
final String msg = "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]";
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, msg));
}
} else {
final RestHandler wrappedHandler = Objects.requireNonNull(handlerWrapper.apply(handler));
wrappedHandler.handleRequest(request, channel, client);
}
}
}
Expand Down

0 comments on commit 65501a8

Please sign in to comment.