This is an automated email from the ASF dual-hosted git repository.

leventov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 91e3cf7  add charset UTF-8 to log api (#6709)
91e3cf7 is described below

commit 91e3cf7196ced5a5f9e0128ffc040104dff897a3
Author: dongyifeng <[email protected]>
AuthorDate: Wed Dec 12 23:31:04 2018 +0800

    add charset UTF-8 to log api (#6709)
    
    When I retrieve the task log in browser, the Chinese characters all end up 
as garbage.
    
![image](https://user-images.githubusercontent.com/1322134/49502749-bd614080-f8b0-11e8-839e-07f7117eebfd.png)
    After adding charset UTF-8, it was correct.
    
![image](https://user-images.githubusercontent.com/1322134/49502804-dc5fd280-f8b0-11e8-916b-bda8f1e7f318.png)
---
 codestyle/checkstyle.xml                           |  6 +++++
 .../indexing/overlord/http/OverlordResource.java   |  3 ++-
 .../druid/indexing/worker/http/WorkerResource.java |  3 ++-
 .../apache/druid/server/http/HttpMediaType.java    | 27 ++++++++++++++++++++++
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/codestyle/checkstyle.xml b/codestyle/checkstyle.xml
index d6ef3e8..d42b705 100644
--- a/codestyle/checkstyle.xml
+++ b/codestyle/checkstyle.xml
@@ -198,6 +198,12 @@
       <property name="message" value="Use 
org.apache.druid.common.config.NullHandling.nullToEmptyIfNeeded instead"/>
     </module>
 
+    <module name="Regexp">
+      <property name="format" value='@Produces\(\"text/plain\"\)'/>
+      <property name="illegalPattern" value="true"/>
+      <property name="message" value="Use 
org.apache.druid.server.http.HttpMediaType#TEXT_PLAIN_UTF8 instead"/>
+    </module>
+
     <module name="PackageName">
       <property name="format" value="^org.apache.druid.*$"/>
     </module>
diff --git 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
index fd7fae4..0e230db 100644
--- 
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
+++ 
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java
@@ -58,6 +58,7 @@ import org.apache.druid.java.util.common.Intervals;
 import org.apache.druid.java.util.common.StringUtils;
 import org.apache.druid.java.util.common.logger.Logger;
 import org.apache.druid.metadata.EntryExistsException;
+import org.apache.druid.server.http.HttpMediaType;
 import org.apache.druid.server.http.security.ConfigResourceFilter;
 import org.apache.druid.server.http.security.DatasourceResourceFilter;
 import org.apache.druid.server.http.security.StateResourceFilter;
@@ -953,7 +954,7 @@ public class OverlordResource
 
   @GET
   @Path("/task/{taskid}/log")
-  @Produces("text/plain")
+  @Produces(HttpMediaType.TEXT_PLAIN_UTF8)
   @ResourceFilters(TaskResourceFilter.class)
   public Response doGetLog(
       @PathParam("taskid") final String taskid,
diff --git 
a/indexing-service/src/main/java/org/apache/druid/indexing/worker/http/WorkerResource.java
 
b/indexing-service/src/main/java/org/apache/druid/indexing/worker/http/WorkerResource.java
index bef73ce..5251321 100644
--- 
a/indexing-service/src/main/java/org/apache/druid/indexing/worker/http/WorkerResource.java
+++ 
b/indexing-service/src/main/java/org/apache/druid/indexing/worker/http/WorkerResource.java
@@ -34,6 +34,7 @@ import 
org.apache.druid.indexing.worker.WorkerCuratorCoordinator;
 import org.apache.druid.indexing.worker.WorkerTaskMonitor;
 import org.apache.druid.java.util.common.StringUtils;
 import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.http.HttpMediaType;
 import org.apache.druid.server.http.security.ConfigResourceFilter;
 import org.apache.druid.server.http.security.StateResourceFilter;
 import org.apache.druid.tasklogs.TaskLogStreamer;
@@ -179,7 +180,7 @@ public class WorkerResource
 
   @GET
   @Path("/task/{taskid}/log")
-  @Produces("text/plain")
+  @Produces(HttpMediaType.TEXT_PLAIN_UTF8)
   @ResourceFilters(StateResourceFilter.class)
   public Response doGetLog(
       @PathParam("taskid") String taskid,
diff --git 
a/server/src/main/java/org/apache/druid/server/http/HttpMediaType.java 
b/server/src/main/java/org/apache/druid/server/http/HttpMediaType.java
new file mode 100644
index 0000000..6f69c3a
--- /dev/null
+++ b/server/src/main/java/org/apache/druid/server/http/HttpMediaType.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.http;
+
+import javax.ws.rs.core.MediaType;
+
+public class HttpMediaType
+{
+  public static final String TEXT_PLAIN_UTF8 = MediaType.TEXT_PLAIN + "; 
charset=UTF-8";
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to