quarkus: UTF-8 encoding problem with MultiPart/RestEasy
Describe the bug I develop a rest API with MULTIPART_FORM. But I’m having problems with @Consumes charset. I sent some params to the controller which includes German characters. And it didn’t work as expected. The characters are not encoded properly, what can also be seen in debugging the properties in VSCode.
Some of the characters that cause the problem:
- ä, Ä, ü, Ü, ö, Ö, ß
Instead, I receive:
- ��
Expected behavior
- Receive all Umlaut, etc. UTF-8
To Reproduce Using httpie:
http -f POST localhost:8080/general content="Test-Ä" file@testFile.png
Response:
HTTP/1.1 200 OK
Content-Length: 11
Content-Type: text/plain;charset=UTF-8
Test-��
Ressource:
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
public class FeedbackResource {
@POST
@Path("/general")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.MULTIPART_FORM_DATA+";charset=UTF-8")
public String postForm(@MultipartForm final FeedbackBody feedback) {
return feedback.content;
}
}
Model:
package org.acme;
import org.jboss.resteasy.annotations.providers.multipart.PartType;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;
public class FeedbackBody {
private byte[] file;
public byte[] getFile() {
return file;
}
@FormParam("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public void setFile(byte[] file) {
this.file = file;
}
@FormParam("fileName")
@PartType(MediaType.TEXT_PLAIN)
public String fileName;
@FormParam("content")
@PartType(MediaType.TEXT_PLAIN+";charset=UTF-8")
public String content;
}
Configuration
# Add your application.properties here, if applicable.
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.5.1.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.5.1.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
Environment (please complete the following information):
- Output of
uname -a
orver
: Darwin Mac.local 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64 - Output of
java -version
: openjdk version “11.0.6” 2020-01-14 OpenJDK Runtime Environment GraalVM CE 19.3.1 (build 11.0.6+9-jvmci-19.3-b07) OpenJDK 64-Bit Server VM GraalVM CE 19.3.1 (build 11.0.6+9-jvmci-19.3-b07, mixed mode, sharing) - Quarkus version or git rev: 1.5.1.Final
- Build tool (ie. output of
mvnw --version
orgradlew --version
): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /Users/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3 Java version: 11.0.6, vendor: Oracle Corporation, runtime: /Users/christian/.sdkman/candidates/java/19.3.1.r11-grl Default locale: en_GB, platform encoding: UTF-8 OS name: “mac os x”, version: “10.15.5”, arch: “x86_64”, family: “mac”
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
I think we could hardcode it to UTF-8 and see if people want to make it configurable. UTF-8 is certainly a better default than the current situation.
I solved that issue by adding an Interceptor in my code
Thank you very much! It seems like only curl supports to specify the content type. I have added the
mime-type="type=text/plain;charset=utf-8"
in the form upload and everything works fine now!@batraz90 the problem is the browser don’t set the
content-type
for each body part like @Kondamon did with Alamofire lib. There’s a thread in the quarkus-dev ML to discuss the possibility to allow configure default charset when not specify or have a better default charset as UTF-8.I have used a framework that uses RFC2388 and RFC2045. Each bodyPart of the MultipartForm has it’s own header. For setting UTF-8 just for the
content
field from above it has to look like this (see bodyParts[2]):