Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Use StandardCharset instead of Charset.forName in ApiModule
Minor nit, use the StandardCharset constant for UTF-8 as opposed to creating it ourselves.

Reviewed at https://reviews.apache.org/r/65761/
  • Loading branch information
jordanly committed Feb 28, 2018
1 parent e3f496a commit e61d7d7b44f191c2960627b5fb4592fffdf9d8ca
Showing 2 changed files with 9 additions and 6 deletions.
@@ -13,7 +13,7 @@
*/
package org.apache.aurora.scheduler.http.api;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import javax.inject.Singleton;

import com.beust.jcommander.Parameter;
@@ -43,7 +43,7 @@ public class ApiModule extends ServletModule {
.create("application", "vnd.apache.thrift.json");
private static final MediaType THRIFT_JSON_UTF_8 = MediaType
.create("application", "vnd.apache.thrift.json")
.withCharset(Charset.forName("UTF-8"));
.withCharset(StandardCharsets.UTF_8);
private static final MediaType THRIFT_BINARY = MediaType
.create("application", "vnd.apache.thrift.binary");

@@ -13,6 +13,7 @@
*/
package org.apache.aurora.scheduler.http.api;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
@@ -103,18 +104,20 @@ public void testThriftJsonUtf8Accepted() throws Exception {
// We also want to ensure charset parsing is case-insensitive because different browsers have
// different default behaviors (Chrome and Safari will change charset to all uppercase, while
// Firefox may leave it lowercase.
String upperUTF8 = StandardCharsets.UTF_8.name().toUpperCase();
ClientResponse upperCaseUTF = getPlainRequestBuilder(ApiModule.API_PATH)
.type("application/vnd.apache.thrift.json; charset=UTF-8")
.accept("application/vnd.apache.thrift.json; charset=UTF-8")
.type("application/vnd.apache.thrift.json; charset=" + upperUTF8)
.accept("application/vnd.apache.thrift.json; charset=" + upperUTF8)
.post(ClientResponse.class, JSON_FIXTURE);
assertEquals(SC_OK, upperCaseUTF.getStatus());
assertEquals(
"application/vnd.apache.thrift.json",
upperCaseUTF.getHeaders().getFirst(CONTENT_TYPE));

String lowerUTF8 = StandardCharsets.UTF_8.name().toLowerCase();
ClientResponse lowerCaseUTF = getPlainRequestBuilder(ApiModule.API_PATH)
.type("application/vnd.apache.thrift.json; charset=utf-8")
.accept("application/vnd.apache.thrift.json; charset=utf-8")
.type("application/vnd.apache.thrift.json; charset=" + lowerUTF8)
.accept("application/vnd.apache.thrift.json; charset=" + lowerUTF8)
.post(ClientResponse.class, JSON_FIXTURE);
assertEquals(SC_OK, lowerCaseUTF.getStatus());
assertEquals(

0 comments on commit e61d7d7

Please sign in to comment.