Problems with UTF-8 ( using @MultipartForm )
inkimannen Oct 14, 2014 3:54 AMHello,
I have an application using RESTeasy, and my problems is - I do not get the ÖÄÅ-characters right.
I am debugging the class, so the problem is my RESTeasy-code.
My dependecies in maven look like this.
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- <version>3.0.6.Final</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-multipart-provider</artifactId>
- <version>2.3.1.GA</version>
- </dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.5.Final</version>
</dependency>
One of my classes has the following :
public class FileUploadForm implements Serializable {
private static final long serialVersionUID = 1L;
@FormParam("mediaUUID")
private String mediaUUID;
@FormParam("selectedFile")
@PartType("application/octet-stream")
private byte[] fileData;
@FormParam("owner")
private String owner;
And my RESTful-service has the following :
- @POST
- @Path("/upload-file")
- @Consumes(MediaType.MULTIPART_FORM_DATA)
- @Produces("text/plain")
- public Response createNewFile(@MultipartForm FileUploadForm form) throws IOException {
- String owner = form.getOwner()
If I send in "Owner" with the name "Özz" then I get some gibberish as in "?zz" when debugging line 6.
Following some leads when googling -> RESTEasy JAX-RS
I create the following :
@Provider @ServerInterceptor public class ContentTypeSetterPreProcessorInterceptor implements PreProcessInterceptor { public ServerResponse
preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException { request.setAttribute(InputPart.DEFAULT_CHARSET_PROPERTY, "UTF-8"); return null; } }
Then I decorate my createNewFile with 'ContentTypeSetterPreProcessorInterceptor' class as in:
@POST
@Path("/upload-file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@Interceptors(ContentTypeSetterPreProcessorInterceptor.class)
public Response createNewFile(@MultipartForm FileUploadForm form) throws IOException
I am calling this restful-service from the following jsp-file:
<form action="media/upload-file" method="post" enctype="multipart/form-data"
accept-charset="UTF-8">
And when debugging I can see that I am in the preProcess-method.
But that does not change a thing ....
Is there any way, a good way, to work-around this problem.
I have ofcourse more than the 'owner' that I am concerned about.
Hope that you can give me a hand.
regards, i