Reputation: 2406
Wildfly 8, Omnifaces 2.2, Primefaces 5.2, JSF 2.2.11 (Mojarra)
I am using Ominifaces
CharacterEncodingFilter
to ensure that file names are encoded correctly on server. Oddly if Primefaces using Jsf internal upload, the file name are not encoded. And if Primefaces use older approach with Appache Commons
it is ok.
Example: 'Hällo.jpg' becomes 'Hällo.jpg'
Web.xml configurations: Apache solution (correct):
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Jsf Upload (characters are not encoded). Other parameters are removed.
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
EDIT: due to answer this is a server bug. I've tried to configure the server:
<jboss-web>
<default-encoding>UTF-8</default-encoding>
</jboss-web>
and
<servlet-container name="default" default-encoding="UTF-8">
but it doesn't help.
Upvotes: 1
Views: 1358
Reputation: 1109292
I reproduced it, WildFly isn't at all considering request request body encoding for multipart/form-data
requests. You really have to configure it in server end (like as you would do for GET requests).
Open /standalone/configuration/standalone.xml
, peek the following line
<servlet-container name="default">
change it to
<servlet-container name="default" default-encoding="UTF-8">
and restart. This at least worked for me on WildFly 10.0.0. I created issue WFLY-6226 to let it consider request body encoding first so there's no need to edit standalone.xml
on that.
In WildFly 8.x (I tested 8.2.1) this unfortunately still won't work as it does not at all consider the above setting. Your best bet is to keep using Apache Commons FileUpload until you can upgrade WildFly.
If you really want to keep native upload, then you could consider to explicitly decode the broken filename to bytes using ISO-8859-1 and then re-encode it using UTF-8.
String fileName = new String(uploadedFile.getFileName().getBytes("ISO-8859-1"), "UTF-8");
This is however brittle and not portable as it would break when deployed to a server where this encoding problem doesn't manifest. So you really need to remember to revert the workaround when upgrading/migrating.
Upvotes: 1