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

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

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

Comments

Projects
None yet
5 participants
@sbuettner
Contributor

sbuettner commented Mar 21, 2014

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

Set uri encoding to UTF-8 by default for Tomcat
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

Set uri encoding to UTF-8 by default for Tomcat
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

@snicoll snicoll closed this in 87321ed Mar 25, 2014

philwebb pushed a commit that referenced this issue Mar 25, 2014

Phillip Webb
Merge pull request #542 from snicoll/gh-540
* gh-540:
  Support Tomcat uri encoding (with UTF-8 default)
@sbuettner

This comment has been minimized.

Show comment
Hide comment
@sbuettner

sbuettner Mar 25, 2014

Contributor

👍

Contributor

sbuettner commented Mar 25, 2014

👍

jkubrynski added a commit to jkubrynski/spring-boot that referenced this issue Mar 27, 2014

Support Tomcat uri encoding (with UTF-8 default)
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

Support Tomcat uri encoding (with UTF-8 default)
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

This comment has been minimized.

Show comment
Hide comment
@LeRiton

LeRiton 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?

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

This comment has been minimized.

Show comment
Hide comment
@snicoll

snicoll Jun 4, 2014

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@LeRiton

LeRiton Jun 5, 2014

Thanks for the clarification!

LeRiton commented Jun 5, 2014

Thanks for the clarification!

mdeinum added a commit to mdeinum/spring-boot that referenced this issue Jun 6, 2014

Support Tomcat uri encoding (with UTF-8 default)
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

This comment has been minimized.

Show comment
Hide comment
@snicoll

snicoll Jun 27, 2014

Member

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

Member

snicoll commented Jun 27, 2014

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

@Farzan6118

This comment has been minimized.

Show comment
Hide comment
@Farzan6118

Farzan6118 May 9, 2016

append the following property in application.properties:

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

hope it helps

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