1

When I upload a file to the server, everything is fine. But if the name of the file contains cyrillic characters, on the server that filename appears with question marks.

I don't set any character encoding when I send request to the server.

I know that if you don't put any character encoding in the header when you make request, the default character encoding that RestEasy puts is us-ascii. I tried a couple of ways to change it:

  • With new String(filename.getBytes("US-ASCII"), "UTF-8") - didn't work;
  • I wrote ContainerRequestFilter, where I changed the ContentType of this request and I added charset=UTF-8 to the ContentType. It is set correctly but still doesn't work.

Could you please help! I would be very thankful!

Thanks!

Also posted on jboss.org forum

Tomaz Cerar
  • 5,761
  • 25
  • 32
Nikolay Traykov
  • 1,537
  • 17
  • 26

1 Answers1

5

Don't change the Content-Type but use a ContainerRequestFilter to overwrite the default charset property:

@Provider
public class CharsetFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
         requestContext.setProperty(InputPart.DEFAULT_CHARSET_PROPERTY, "UTF-8");
    }

}

Maybe you should check if there is a encoding provided and overwrite only if not.

lefloh
  • 10,653
  • 3
  • 28
  • 50
  • Ok, I understood. Let me try. Thank you! I will share the results in a minutes. – Nikolay Traykov Jan 19 '15 at 08:34
  • It didn't work. I saw the property InputPart.DEFAULT_CHARSET_PROPERTY and the documentation above it says that your code should work. Strange that it is not working. Thanks anyway. I will continue trying. – Nikolay Traykov Jan 19 '15 at 09:13
  • Could you please check if [this example on github](https://github.com/lefloh/resteasy-fileupload) is working for you? – lefloh Jan 19 '15 at 12:05
  • Thanks again lefloh! I saw the links but still don't have success. In my case the problem is that I can't set the header in the client (The UI developers can't). That's why I've tried with a filter and this is the only case that I can try. Still, no success.This is the code `@Provider public class CharsetFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { requestContext.setProperty(InputPart.DEFAULT_CHARSET_PROPERTY, "UTF-8"); } } ` – Nikolay Traykov Jan 19 '15 at 13:45
  • This should work so maybe there is another problem. Are you really getting UTF-8 or is your client sending content with a different encoding? You could try adding `` to the head of the document. – lefloh Jan 19 '15 at 14:52
  • Yes, I've checked that. I have. Could that be RestEasy configuration or Wildfly configuration? – Nikolay Traykov Jan 19 '15 at 14:55
  • Sorry, basically this should work and I don't have more ideas. – lefloh Jan 19 '15 at 15:02