(Code samples added) |
J.swiderski (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | By default some servers use the ISO-8859-1 encoding for request parameters and request body. What is more, changing the encoding for request body on such servers has no influence on the encoding of the request parameters. This may cause problems if you want to use international file names with '''CKFinder which expects request body and parameters to be encoded in UTF-8'''. To overcome this issue you can either set UTF-8 URI encoding on the server or if you do not have enough privileges to do that, you can adjust CKFinder to use same URI encoding as your server. <br /> | ||
+ | You will find more detailed instructions below. | ||
+ | |||
+ | ===JBOSS 6=== | ||
+ | JBOSS 6 is one of the servers that use ISO-8859-1 for parameter encoding. In order to change this value to UTF-8 you have to modify the <code>server.xml</code> file for the configuration you use. <br /> | ||
+ | As you probably know, JBOSS 6 comes with five different server configurations. To simplify the example let us assume that configuration '''<code>"all"</code>''' is used and you want to set UTF-8 only for that particular configuration. To achieve that you have to edit the <code><nowiki>JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml</nowiki></code> file and add the <code>URIEncoding="UTF-8"</code> attribute in the <code>Connector</code> element. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <Connector URIEncoding="UTF-8" protocol="HTTP/1.1" port="${jboss.web.http.port}" | ||
+ | address="${jboss.bind.address}" redirectPort="${jboss.web.https.port}" /> | ||
+ | </source> | ||
+ | |||
+ | ===JBOSS 7=== | ||
+ | By default this server uses ISO-8859-1 for parameter encoding. To change this to UTF-8, you have to modify the configuration file appropriate for the mode and configuration used.<br /> | ||
+ | As you probably know, JBOSS 7 can run in two modes ("domain" and "standalone") and can use various configurations. | ||
+ | To simplify the example let us assume that the server uses the standalone mode and default configuration. In order to set UTF-8 for URI encoding you have to edit the <code><nowiki>JBOSS_HOME/standalone/configuration/standalone.xml</nowiki></code> file and add a system property named <code>org.apache.catalina.connector.URI_ENCODING</code>,(with value set to UTF-8) to the <code>system-properties</code> element. <br /> | ||
+ | Below is the code that needs to be added to the configuration file you use: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <system-properties> | ||
+ | <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/> | ||
+ | </system-properties> | ||
+ | </source> | ||
+ | |||
+ | ===GlassFish 3.0=== | ||
+ | According to Glassfish 3.0 [http://docs.oracle.com/cd/E19798-01/821-1752/beafu/index.html documentation] default parameter encoding for requests is ISO-8859-1. To change this encoding to UTF-8 you have to use the sun-web.xml [http://docs.oracle.com/cd/E19798-01/821-1750/beaql/index.html file] with xml <code>parameter-encoding</code> element. This file has to be placed in the <code>WEB-INF</code> folder of your web application.<br /> | ||
+ | CKFinder sample web application comes with such a file. If you are using Glassfish 3.0, want to use UTF-8, and to integrate CKFinder in to your application then apart from files mentioned in the [http://docs.cksource.com/CKFinder_2.x/Developers_Guide/Java/Integration Integration] section, copy <code>sun-web.xml</code> as well. <br /> | ||
+ | Below is the code for the <code>sun-web.xml</code> file: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" | ||
+ | "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd"> | ||
+ | <sun-web-app> | ||
+ | <parameter-encoding default-charset="UTF-8" /> | ||
+ | </sun-web-app> | ||
+ | </source> | ||
+ | |||
+ | ===GlassFish 3.1+=== | ||
+ | By default this [http://docs.oracle.com/cd/E18930_01/html/821-2418/beaft.html#beafu server] uses ISO-8859-1 for parameter encoding. In order to change this to UTF-8, you have to use the <code>glassfish-web.xml</code> [http://docs.oracle.com/cd/E18930_01/html/821-2417/beaql.html#scrolltoc file] with xml <code>parameter-encoding</code> element. This file has to be placed in the <code>WEB-INF</code> folder of the web application. <br /> | ||
+ | CKFinder sample web application comes with such a file. If you are using Glassfish 3.1 or 4.0, want to use UTF-8, and to integrate CKFinder in to your application then apart from files mentioned in the [http://docs.cksource.com/CKFinder_2.x/Developers_Guide/Java/Integration Integration] section, copy <code>glassfish-web.xml</code> as well. <br /> | ||
+ | Below is the code for the <code>glassfish-web.xml</code> file: | ||
+ | <source lang="xml"> | ||
+ | <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" | ||
+ | "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"> | ||
+ | <glassfish-web-app> | ||
+ | <parameter-encoding default-charset="UTF-8" /> | ||
+ | </glassfish-web-app> | ||
+ | </source> | ||
+ | |||
+ | ===Tomcat=== | ||
According to [http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ], for handling HTTP requests by default Tomcat uses the ISO-8859-1 encoding. | According to [http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ], for handling HTTP requests by default Tomcat uses the ISO-8859-1 encoding. | ||
Starting with version 5 for all <code>GET</code> requests, when the encoding type used is different from the default one, the query parameters are not encoded in the same way as the request body. To be more specific, if you want to use the encoding other than the default ISO-8859-1 (like UTF-8, for example), the <code>HttpServletRequest.setCharacterEncoding("UTF-8")</code> method will only be applied to the request body, and not the URI. | Starting with version 5 for all <code>GET</code> requests, when the encoding type used is different from the default one, the query parameters are not encoded in the same way as the request body. To be more specific, if you want to use the encoding other than the default ISO-8859-1 (like UTF-8, for example), the <code>HttpServletRequest.setCharacterEncoding("UTF-8")</code> method will only be applied to the request body, and not the URI. | ||
− | In order to encode the query parameters just like the requests, you should use the <code>URIEncoding="UTF-8"</code> attribute in the <code>Connector</code> element of the <code>Server.xml</code> file. | + | In order to encode the query parameters just like the requests, you should use the <code>URIEncoding="UTF-8"</code> attribute in the <code>Connector</code> element of the <code>Server.xml</code> file: |
+ | <source lang="xml"> | ||
+ | <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> | ||
+ | </source> | ||
+ | |||
+ | ===Weblogic=== | ||
+ | This server follows J2EE specification when it comes to encoding. This means that if no encoding is specified then default ISO-8859-1 is set for everything (Servlets, JSP, Tag Files) except for XML format files.<br /> | ||
+ | Weblogic documentation provides a couple of ways for setting the encoding you want (UTF-8 in this case). There are server typical methods as well as general Servlet API methods. It seems the best way to set encoding in the WLS server is using [http://docs.oracle.com/javaee/7/api/javax/servlet/ServletRequest.html#setCharacterEncoding%28java.lang.String%29 setCharacterEncoding("UTF-8");] for requests and [http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setCharacterEncoding%28java.lang.String%29 setCharacterEncoding("UTF-8");] or [http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentType%28java.lang.String%29 setContentType("UTF-8");] for responses. | ||
+ | |||
+ | Please see this [http://otndnld.oracle.co.jp/document/products/wls/docs103/en/relnotes_ja.htmlotndnld.oracle.co.jp/document/products/wls/docs92/en/relnotes_ja.html link] (Web Components section) for more details on setting appropriate encoding on the server-side. | ||
+ | |||
+ | ===Jetty=== | ||
+ | All supported Jetty versions (7,8 and 9) use UTF-8 by default. Jetty [http://wiki.eclipse.org/Jetty/Howto/International_Characters#Characters_included_in_HTTP_requests documentation] states if no overriding character encoding is set on a request, Jetty uses UTF-8 encoding. | ||
+ | ===Alternative Solution (CKFinder Adjustment)=== | ||
'''By default, CKFinder uses the UTF-8 encoding, so you should stick to the guidelines presented above in order to make it work properly.''' | '''By default, CKFinder uses the UTF-8 encoding, so you should stick to the guidelines presented above in order to make it work properly.''' | ||
− | |||
− | |||
− | |||
− | If you cannot or do not want to set this parameter in the server configuration file, CKFinder will try to address this problem for you. This is why the <code>uriEncoding</code> configuration element was created in the <code>config.xml< | + | If you cannot or do not want to set this parameter in the server configuration file, CKFinder will try to address this problem for you. This is why the <code>uriEncoding</code> configuration element was created in the <code>config.xml<code> file. This parameter accepts the encoding of your query parameters. <br /> |
+ | For example, for Tomcat, JBoss, Glassfish, and Weblogic with their default configuration set (which is ISO-8859-1) you should set uriEncoding to ISO-8859-1 and CKFinder will convert the query parameters for you. | ||
− | |||
<source lang="xml"> | <source lang="xml"> | ||
<uriEncoding>ISO-8859-1</uriEncoding> | <uriEncoding>ISO-8859-1</uriEncoding> | ||
</source> | </source> | ||
− | |||
− |
Revision as of 21:45, 22 November 2013
By default some servers use the ISO-8859-1 encoding for request parameters and request body. What is more, changing the encoding for request body on such servers has no influence on the encoding of the request parameters. This may cause problems if you want to use international file names with CKFinder which expects request body and parameters to be encoded in UTF-8. To overcome this issue you can either set UTF-8 URI encoding on the server or if you do not have enough privileges to do that, you can adjust CKFinder to use same URI encoding as your server.
You will find more detailed instructions below.
Contents
JBOSS 6
JBOSS 6 is one of the servers that use ISO-8859-1 for parameter encoding. In order to change this value to UTF-8 you have to modify the server.xml
file for the configuration you use.
As you probably know, JBOSS 6 comes with five different server configurations. To simplify the example let us assume that configuration "all"
is used and you want to set UTF-8 only for that particular configuration. To achieve that you have to edit the JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml
file and add the URIEncoding="UTF-8"
attribute in the Connector
element.
<Connector URIEncoding="UTF-8" protocol="HTTP/1.1" port="${jboss.web.http.port}" address="${jboss.bind.address}" redirectPort="${jboss.web.https.port}" />
JBOSS 7
By default this server uses ISO-8859-1 for parameter encoding. To change this to UTF-8, you have to modify the configuration file appropriate for the mode and configuration used.
As you probably know, JBOSS 7 can run in two modes ("domain" and "standalone") and can use various configurations.
To simplify the example let us assume that the server uses the standalone mode and default configuration. In order to set UTF-8 for URI encoding you have to edit the JBOSS_HOME/standalone/configuration/standalone.xml
file and add a system property named org.apache.catalina.connector.URI_ENCODING
,(with value set to UTF-8) to the system-properties
element.
Below is the code that needs to be added to the configuration file you use:
<system-properties> <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/> </system-properties>
GlassFish 3.0
According to Glassfish 3.0 documentation default parameter encoding for requests is ISO-8859-1. To change this encoding to UTF-8 you have to use the sun-web.xml file with xml parameter-encoding
element. This file has to be placed in the WEB-INF
folder of your web application.
CKFinder sample web application comes with such a file. If you are using Glassfish 3.0, want to use UTF-8, and to integrate CKFinder in to your application then apart from files mentioned in the Integration section, copy sun-web.xml
as well.
Below is the code for the sun-web.xml
file:
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd"> <sun-web-app> <parameter-encoding default-charset="UTF-8" /> </sun-web-app>
GlassFish 3.1+
By default this server uses ISO-8859-1 for parameter encoding. In order to change this to UTF-8, you have to use the glassfish-web.xml
file with xml parameter-encoding
element. This file has to be placed in the WEB-INF
folder of the web application.
CKFinder sample web application comes with such a file. If you are using Glassfish 3.1 or 4.0, want to use UTF-8, and to integrate CKFinder in to your application then apart from files mentioned in the Integration section, copy glassfish-web.xml
as well.
Below is the code for the glassfish-web.xml
file:
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"> <glassfish-web-app> <parameter-encoding default-charset="UTF-8" /> </glassfish-web-app>
Tomcat
According to Tomcat FAQ, for handling HTTP requests by default Tomcat uses the ISO-8859-1 encoding.
Starting with version 5 for all GET
requests, when the encoding type used is different from the default one, the query parameters are not encoded in the same way as the request body. To be more specific, if you want to use the encoding other than the default ISO-8859-1 (like UTF-8, for example), the HttpServletRequest.setCharacterEncoding("UTF-8")
method will only be applied to the request body, and not the URI.
In order to encode the query parameters just like the requests, you should use the URIEncoding="UTF-8"
attribute in the Connector
element of the Server.xml
file:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
Weblogic
This server follows J2EE specification when it comes to encoding. This means that if no encoding is specified then default ISO-8859-1 is set for everything (Servlets, JSP, Tag Files) except for XML format files.
Weblogic documentation provides a couple of ways for setting the encoding you want (UTF-8 in this case). There are server typical methods as well as general Servlet API methods. It seems the best way to set encoding in the WLS server is using setCharacterEncoding("UTF-8"); for requests and setCharacterEncoding("UTF-8"); or setContentType("UTF-8"); for responses.
Please see this link (Web Components section) for more details on setting appropriate encoding on the server-side.
Jetty
All supported Jetty versions (7,8 and 9) use UTF-8 by default. Jetty documentation states if no overriding character encoding is set on a request, Jetty uses UTF-8 encoding.
Alternative Solution (CKFinder Adjustment)
By default, CKFinder uses the UTF-8 encoding, so you should stick to the guidelines presented above in order to make it work properly.
If you cannot or do not want to set this parameter in the server configuration file, CKFinder will try to address this problem for you. This is why the uriEncoding
configuration element was created in the config.xml<code> file. This parameter accepts the encoding of your query parameters.
For example, for Tomcat, JBoss, Glassfish, and Weblogic with their default configuration set (which is ISO-8859-1) you should set uriEncoding to ISO-8859-1 and CKFinder will convert the query parameters for you.
<uriEncoding>ISO-8859-1</uriEncoding>