I have an AngularJS app trying to submit a form to a Java backend deployed in a Tomcat 7.0.54. My AngularJS app seems to be submitting the form correctly. This is the content type header as recored by Chrome's inspector:
Content-Type:application/json;charset=UTF-8
The request payload, once again as recorded by Chrome's inspector, is:
{"newProject":{"title":"título","deadline":"30/Maio/2014", .....
That is, the AngularJS app is putting the request correctly in the wire. However, I',m unable to read this payload correctly in the server side. Characters like "í" are being printed as "?".
Just for the purpose of testing I modified my second filter in the chain (the first is Spring Security) for printing the content of the request. This is to be sure that neither my server side application nor any of the frameworks I'm using are interfering in my data.
@Override
public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException {
try {
HttpServletRequest hsr = (HttpServletRequest)request;
if( "POST".equalsIgnoreCase( hsr.getMethod() ) && "http://localhost:8080/profile/createproject".equalsIgnoreCase( hsr.getRequestURL().toString() ) ) {
hsr.setCharacterEncoding( "UTF-8" );
BufferedReader reader = new BufferedReader( new InputStreamReader( request.getInputStream(), "UTF-8" ) );
System.out.println( reader.readLine() );
}
chain.doFilter( request, response );
} finally {
MDC.remove( CHAVE_ID_REQUEST );
}
}
Even reading the request in the second filter of the chain I'm getting "t?tulo" instead of "título". If the same AngularJS app submits to a node backend, then the payload is correctly read and printed in the terminal.
Does anyone have any glue about the reason Tomcat can't read my UTF-8 request correctly?