Thrift transport handling unexpected URI hangs, closes #1484.
This commit is contained in:
parent
f28c11b31c
commit
0c384af9bf
|
@ -29,6 +29,7 @@ import org.elasticsearch.rest.RestChannel;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
import org.elasticsearch.rest.StringRestResponse;
|
||||||
import org.elasticsearch.rest.XContentRestResponse;
|
import org.elasticsearch.rest.XContentRestResponse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -36,6 +37,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.elasticsearch.rest.RestStatus.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (shay.banon)
|
* @author kimchy (shay.banon)
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +57,7 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface {
|
||||||
}
|
}
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final AtomicReference<org.elasticsearch.thrift.RestResponse> ref = new AtomicReference<org.elasticsearch.thrift.RestResponse>();
|
final AtomicReference<org.elasticsearch.thrift.RestResponse> ref = new AtomicReference<org.elasticsearch.thrift.RestResponse>();
|
||||||
restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() {
|
boolean dispatched = restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() {
|
||||||
@Override public void sendResponse(RestResponse response) {
|
@Override public void sendResponse(RestResponse response) {
|
||||||
try {
|
try {
|
||||||
ref.set(convert(response));
|
ref.set(convert(response));
|
||||||
|
@ -64,6 +67,14 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface {
|
||||||
latch.countDown();
|
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 {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
return ref.get();
|
return ref.get();
|
||||||
|
|
|
@ -87,6 +87,10 @@ public class SimpleThriftTests {
|
||||||
request = new RestRequest(Method.GET, "/_cluster/health");
|
request = new RestRequest(Method.GET, "/_cluster/health");
|
||||||
response = client.execute(request);
|
response = client.execute(request);
|
||||||
assertThat(response.getStatus(), equalTo(Status.OK));
|
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<String, Object> parseBody(RestResponse response) throws IOException {
|
private Map<String, Object> parseBody(RestResponse response) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue