Repository: aurora Updated Branches: refs/heads/master cb0faf831 -> 2054f1ee5
Adding support for Thrift JSON requests which defines UTF-8 as the charset for the Content-Type in the Request Headers This fixes the current UI brakage as Thrift is incorrectly rejected by the scheduler servlet as an unsupported media type. Test added to prevent regressions. Reviewed at https://reviews.apache.org/r/65649/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/2054f1ee Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/2054f1ee Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/2054f1ee Branch: refs/heads/master Commit: 2054f1ee586cf26d2729679c2cc23da8d3a5d768 Parents: cb0faf8 Author: Renan DelValle <re...@apache.org> Authored: Wed Feb 14 08:28:52 2018 -0800 Committer: Renan DelValle <re...@apache.org> Committed: Wed Feb 14 08:28:52 2018 -0800 ---------------------------------------------------------------------- .../aurora/scheduler/http/api/ApiModule.java | 3 +++ .../apache/aurora/scheduler/http/api/ApiIT.java | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/2054f1ee/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java b/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java index 91ff8d3..2820cda 100644 --- a/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java +++ b/src/main/java/org/apache/aurora/scheduler/http/api/ApiModule.java @@ -41,6 +41,8 @@ public class ApiModule extends ServletModule { private static final MediaType GENERIC_THRIFT = new MediaType("application", "x-thrift"); private static final MediaType THRIFT_JSON = new MediaType("application", "vnd.apache.thrift.json"); + private static final MediaType THRIFT_JSON_UTF_8 = + new MediaType("application", "vnd.apache.thrift.json", "UTF-8"); private static final MediaType THRIFT_BINARY = new MediaType("application", "vnd.apache.thrift.binary"); @@ -112,6 +114,7 @@ public class ApiModule extends ServletModule { InputConfig inputConfig = new InputConfig(GENERIC_THRIFT, ImmutableMap.of( GENERIC_THRIFT, jsonFactory, THRIFT_JSON, jsonFactory, + THRIFT_JSON_UTF_8, jsonFactory, APPLICATION_JSON_TYPE, jsonFactory, THRIFT_BINARY, binFactory )); http://git-wip-us.apache.org/repos/asf/aurora/blob/2054f1ee/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java b/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java index 10da43b..bfd117b 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java @@ -95,6 +95,26 @@ public class ApiIT extends AbstractJettyTest { } @Test + public void testThriftJsonUtf8Accepted() throws Exception { + expect(thrift.getRoleSummary()).andReturn(new Response()); + + replayAndStart(); + + // TODO(rdelvalle): If UTF-8 is not in caps, the accept method doesn't register a charset + // when building the request. The servlet accepts the charset in lower caps for now but + // might be worth resisting this oddity in the future to prevent regressions. + ClientResponse response = getPlainRequestBuilder(ApiModule.API_PATH) + .type("application/vnd.apache.thrift.json; charset=UTF-8") + .accept("application/vnd.apache.thrift.json; charset=UTF-8") + .post(ClientResponse.class, JSON_FIXTURE); + + assertEquals(SC_OK, response.getStatus()); + assertEquals( + "application/vnd.apache.thrift.json", + response.getHeaders().getFirst(CONTENT_TYPE)); + } + + @Test public void testUnknownContentTypeRejected() throws Exception { replayAndStart();