diff --git a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java index 9a24e1fced7..93afbd56e84 100644 --- a/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java +++ b/plugins/transport/thrift/src/main/java/org/elasticsearch/thrift/ThriftRestImpl.java @@ -29,6 +29,7 @@ import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.StringRestResponse; import org.elasticsearch.rest.XContentRestResponse; import java.io.IOException; @@ -36,6 +37,8 @@ import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.rest.RestStatus.*; + /** * @author kimchy (shay.banon) */ @@ -54,7 +57,7 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface { } final CountDownLatch latch = new CountDownLatch(1); final AtomicReference ref = new AtomicReference(); - restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() { + boolean dispatched = restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() { @Override public void sendResponse(RestResponse response) { try { ref.set(convert(response)); @@ -64,6 +67,14 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface { latch.countDown(); } }); + if (!dispatched) { + try { + ref.set(convert(new StringRestResponse(BAD_REQUEST, "No handler found for uri [" + request.getUri() + "] and method [" + request.getMethod() + "]"))); + } catch (IOException e) { + // ignore, will not happen... (from convert) + } + latch.countDown(); + } try { latch.await(); return ref.get(); diff --git a/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java b/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java index a23c65215d7..c94bd4a4292 100644 --- a/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java +++ b/plugins/transport/thrift/src/test/java/org/elasticsearch/thrift/test/SimpleThriftTests.java @@ -87,6 +87,10 @@ public class SimpleThriftTests { request = new RestRequest(Method.GET, "/_cluster/health"); response = client.execute(request); assertThat(response.getStatus(), equalTo(Status.OK)); + + request = new RestRequest(Method.GET, "/bogusindex"); + response = client.execute(request); + assertThat(response.getStatus(), equalTo(Status.BAD_REQUEST)); } private Map parseBody(RestResponse response) throws IOException {