DIY & Music & Guitar & Beer & Tech

Using non US ASCII (ANSI X3.4-1986) chars/symbols in URL:s

In case that non US ASCII symbols are used in (e.g. redirect) URL:s, tomcat is not going to be able to process these ‘out of the box’. Example of such a use-case is redirects and callback from external servers to your servers with parameters with non US ASCII chars (e.g. swedish letters å,ö,ä etc.). Simple way to fix this is to define explicitly in server connectors usage of UTF-8 encoding for all URL:s, add URIEncoding=”UTF-8″ to your connectors. Something like this:

   <!-- A "Connector" represents an endpoint by which requests are received
        and responses are returned. Documentation at :
        Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
        Java AJP  Connector: /docs/config/ajp.html
        APR (HTTP/AJP) Connector: /docs/apr.html
        Define a non-SSL HTTP/1.1 Connector on port 8080
   -->
    <Connector port="8***" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" URIEncoding="UTF-8"/>

    <!-- A "Connector" using the shared thread pool-->
    <Connector executor="tomcatThreadPool"
              port="8***" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" URIEncoding="UTF-8"/>

This is to be added/changed in tomcats …/conf/server.xml file. Don’t mind port settings marked as ‘8***’ it’s not really defined as that – here just as an example.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.