Skip to content

Set URI encoding for embedded containers to UTF-8 #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sbuettner opened this issue Mar 21, 2014 · 6 comments
Closed

Set URI encoding for embedded containers to UTF-8 #540

sbuettner opened this issue Mar 21, 2014 · 6 comments
Assignees
Milestone

Comments

@sbuettner
Copy link

Please set the default encoding for the embedded containers to UTF-8. Otherwise there are issues with extracting characters like german umlauts from the uri for example when using the @RequestParam annotation. Currently i have to register my own connector customizer:

new TomcatConnectorCustomizer() {
  @Override
  public void customize(Connector connector) {
    connector.setURIEncoding("UTF-8");
  }
}
@snicoll snicoll self-assigned this Mar 21, 2014
snicoll added a commit to snicoll/spring-boot that referenced this issue Mar 21, 2014
This commit introduces an extra 'server.tomcat.uri-encoding'
property used to configure the URI encoding for the embedded
tomcat container.

This defaults to 'UTF-8' instead of what tomcat uses by
default (i.e. 'ISO-8859-1'). Note that Jetty uses 'UTF-8' by default
but can only be customized through the use of a system property so
this new setting only applies for Tomcat.

Fixes spring-projectsgh-540
snicoll added a commit to snicoll/spring-boot that referenced this issue Mar 21, 2014
This commit introduces an extra 'server.tomcat.uri-encoding'
property used to configure the URI encoding for the embedded
tomcat container.

This defaults to 'UTF-8' instead of what tomcat uses by
default (i.e. 'ISO-8859-1'). Note that Jetty uses 'UTF-8' by default
but can only be customized through the use of a system property so
this new setting only applies for Tomcat.

Fixes spring-projectsgh-540
@philwebb philwebb added this to the 1.0.0.RELEASE milestone Mar 25, 2014
philwebb pushed a commit that referenced this issue Mar 25, 2014
* gh-540:
  Support Tomcat uri encoding (with UTF-8 default)
@sbuettner
Copy link
Author

👍

jkubrynski pushed a commit to jkubrynski/spring-boot that referenced this issue Mar 27, 2014
Introduce an extra `server.tomcat.uri-encoding` property used to
configure the URI encoding for the embedded tomcat container.

Defaults to `UTF-8` instead of the usual tomcat default of `ISO-8859-1`.

Fixes spring-projectsgh-540
gigfork pushed a commit to boostrack/spring-boot that referenced this issue Apr 21, 2014
Introduce an extra `server.tomcat.uri-encoding` property used to
configure the URI encoding for the embedded tomcat container.

Defaults to `UTF-8` instead of the usual tomcat default of `ISO-8859-1`.

Fixes spring-projectsgh-540
gigfork pushed a commit to boostrack/spring-boot that referenced this issue Apr 21, 2014
@LeRiton
Copy link

LeRiton commented Jun 4, 2014

I don' want to open another issue for this same case, since this one has been closed ans @snicoll proposal at #542 was supposed to fix this issue.

I'm experiencing the exact same issue using SB 1.0.2.RELEASE with a simple dummy project.

Project has spring-boot-starter-web and spring-boot-starter-thymeleaf dependencies and use spring-boot-maven-plugin for run, defaulting to Tomcat.

Messages submitted through basic form

<form action="/" method="POST">
    <p>New message: <input type="text" name="text" /></p>
    <p><input type="submit" value="Submit" /> </p>
</form>

are facing this encoding issue, despite Tomcat's default encoding UTF-8 provided in this thread. Thymeleaf's template and HTML page encoding are UTF-8 too.

This could be fixed by adding

    @Bean
    public Filter characterEncodingFilter() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return characterEncodingFilter;
    }

to application, witch makes me think that server encoding still doesn't match default. Using server.tomcat.uri-encoding doesn't fix encoding.

Am I missing something?

@snicoll
Copy link
Member

snicoll commented Jun 4, 2014

What this commit does is changing the way Tomcat parse URIs. If you have a form with a body, it's a different matter and you should specify it in your request.

There are a couple of issues that are somewhat related to this. A request to change the default in Spring from ISO-8859-1 to UTF-8 (SPR-11779) and a bug that could occur if you set the body encoding as it is now used as the URI encoding by Spring (SPR-11474)

Both are currently scheduled for the next release but if you don't want to set the body encoding or if you want to enforce UTF-8, your current filter is the recommended approach.

@LeRiton
Copy link

LeRiton commented Jun 5, 2014

Thanks for the clarification!

mdeinum pushed a commit to mdeinum/spring-boot that referenced this issue Jun 6, 2014
Introduce an extra `server.tomcat.uri-encoding` property used to
configure the URI encoding for the embedded tomcat container.

Defaults to `UTF-8` instead of the usual tomcat default of `ISO-8859-1`.

Fixes spring-projectsgh-540
@snicoll
Copy link
Member

snicoll commented Jun 27, 2014

@LeRiton we further discussed this matter and there's a specific issue in boot now (see #1182)

@Farzan6118
Copy link

Farzan6118 commented May 9, 2016

append the following property in application.properties:

spring.datasource.connection-properties=useUnicode=true;characterEncoding=utf-8;

hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants