|
@@ -277,40 +277,33 @@ public class RestControllerTests extends ESTestCase {
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
}
|
|
|
|
|
|
- public void testDispatchWorksWithPlainText() {
|
|
|
+ public void testDispatchFailsWithPlainText() {
|
|
|
String content = randomAsciiOfLengthBetween(1, BREAKER_LIMIT.bytesAsInt());
|
|
|
FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
.withContent(new BytesArray(content), null).withPath("/foo")
|
|
|
.withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("text/plain"))).build();
|
|
|
- AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
|
|
|
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() {
|
|
|
@Override
|
|
|
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
|
|
channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean supportsPlainText() {
|
|
|
- return true;
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
assertFalse(channel.getSendResponseCalled());
|
|
|
restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
- assertWarnings("Plain text request bodies are deprecated. Use request parameters or body in a supported format.");
|
|
|
}
|
|
|
|
|
|
- public void testDispatchWorksWithAutoDetection() {
|
|
|
+ public void testDispatchUnsupportedContentType() {
|
|
|
FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
.withContent(new BytesArray("{}"), null).withPath("/")
|
|
|
.withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("application/x-www-form-urlencoded"))).build();
|
|
|
- AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
|
|
|
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
|
|
|
assertFalse(channel.getSendResponseCalled());
|
|
|
restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
- assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.");
|
|
|
}
|
|
|
|
|
|
public void testDispatchWorksWithNewlineDelimitedJson() {
|
|
@@ -361,10 +354,10 @@ public class RestControllerTests extends ESTestCase {
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
}
|
|
|
|
|
|
- public void testDispatchWithContentStreamAutoDetect() {
|
|
|
+ public void testDispatchWithContentStreamNoContentType() {
|
|
|
FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
.withContent(new BytesArray("{}"), null).withPath("/foo").build();
|
|
|
- AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK);
|
|
|
+ AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() {
|
|
|
@Override
|
|
|
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
|
@@ -380,48 +373,11 @@ public class RestControllerTests extends ESTestCase {
|
|
|
assertFalse(channel.getSendResponseCalled());
|
|
|
restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
- assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.");
|
|
|
}
|
|
|
|
|
|
public void testNonStreamingXContentCausesErrorResponse() throws IOException {
|
|
|
- // auto detect
|
|
|
FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
- .withContent(YamlXContent.contentBuilder().startObject().endObject().bytes(), null).withPath("/foo").build();
|
|
|
- AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
- restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() {
|
|
|
- @Override
|
|
|
- public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
|
|
- channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean supportsContentStream() {
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- assertFalse(channel.getSendResponseCalled());
|
|
|
- restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
- assertTrue(channel.getSendResponseCalled());
|
|
|
-
|
|
|
- assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.");
|
|
|
-
|
|
|
- // specified
|
|
|
- fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
.withContent(YamlXContent.contentBuilder().startObject().endObject().bytes(), XContentType.YAML).withPath("/foo").build();
|
|
|
- channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
- assertFalse(channel.getSendResponseCalled());
|
|
|
- restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
- assertTrue(channel.getSendResponseCalled());
|
|
|
- }
|
|
|
-
|
|
|
- public void testStrictModeContentStream() {
|
|
|
- restController = new RestController(
|
|
|
- Settings.builder().put(HttpTransportSettings.SETTING_HTTP_CONTENT_TYPE_REQUIRED.getKey(), true).build(),
|
|
|
- Collections.emptySet(), null, null, circuitBreakerService);
|
|
|
- FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
|
|
|
- .withContent(new BytesArray("{}"), null).withPath("/foo")
|
|
|
- .build();
|
|
|
AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE);
|
|
|
restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() {
|
|
|
@Override
|
|
@@ -459,7 +415,6 @@ public class RestControllerTests extends ESTestCase {
|
|
|
assertFalse(channel.getSendResponseCalled());
|
|
|
restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY));
|
|
|
assertTrue(channel.getSendResponseCalled());
|
|
|
- assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.");
|
|
|
}
|
|
|
|
|
|
public void testDispatchBadRequest() {
|
|
@@ -519,7 +474,7 @@ public class RestControllerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
private static final class AssertingChannel extends AbstractRestChannel {
|
|
|
-
|
|
|
+
|
|
|
private final RestStatus expectedStatus;
|
|
|
private final AtomicReference<RestResponse> responseReference = new AtomicReference<>();
|
|
|
|
|
@@ -533,15 +488,15 @@ public class RestControllerTests extends ESTestCase {
|
|
|
assertEquals(expectedStatus, response.status());
|
|
|
responseReference.set(response);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
RestResponse getRestResponse() {
|
|
|
return responseReference.get();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boolean getSendResponseCalled() {
|
|
|
return getRestResponse() != null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private static final class ExceptionThrowingChannel extends AbstractRestChannel {
|