DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=36172>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=36172 Summary: getCharacterEncoding destroys POST data Product: Tomcat 5 Version: Unknown Platform: Sun OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: Connector:Coyote AssignedTo: tomcat-dev@jakarta.apache.org ReportedBy: [EMAIL PROTECTED] It's a known problem that most web browsers don't indicate the encoding of the POST data in an HTTP request. If they fail to provide this information (i.e. request.getCharacterEncoding() == null), I would like to assume UTF-8. The problem is, calling getCharacterEncoding() destroys the POST data, I assume in an attempt to parse out an encoding or charset parameter. In any case, I can't find any specification of a contract that says the inputStream or getParameter*() may be invalid after getCharacterData() and this would rather seem like a bad idea anyway. Sample code for a servlet receiving form input via POST: if ( request.getCharacterEncoding() == null ) { request.setCharacterEncoding( "UTF-8" ); } out.println( "request encoding: " + request.getCharacterEncoding() ); out.println( "request content-type: " + request.getContentType() ); out.println( "request content len: " + request.getContentLength() ); out.println( "request parameters by Map" ); out.println( request.getParameterMap() ); The map printed is empty. If the if block is removed and the encoding is always set to UTF-8, the map is populated correctly. If the character encoding is not set (and getCharacterEncoding is not called but would return null), the map is also not correct. If working with the inputStream, read returns -1 under the same conditions that the map is empty. My server log contains the following entry for a logged Exception. Of course, no Exception is allowed to propogate to the level of my code. Unable to set request encoding java.io.UnsupportedEncodingException: hidden_value at sun.io.Converters.getConverterClass(Converters.java:215) at sun.io.Converters.newConverter(Converters.java:248) at sun.io.ByteToCharConverter.getConverter(ByteToCharConverter.java:64) at java.lang.StringCoding.decode(StringCoding.java:226) at java.lang.String.<init>(String.java:320) at java.lang.String.<init>(String.java:346) at org.apache.coyote.tomcat5.CoyoteRequest$1.run(CoyoteRequest.java:1560) at java.security.AccessController.doPrivileged(Native Method) at org.apache.coyote.tomcat5.CoyoteRequest.setCharacterEncoding(CoyoteRequest.java:1557) at com.sun.enterprise.web.connector.coyote.PECoyoteRequest.setRequestEncoding(PECoyoteRequest.java:151) at com.sun.enterprise.web.connector.coyote.PECoyoteRequest.getCharacterEncoding(PECoyoteRequest.java:76) at org.apache.coyote.tomcat5.CoyoteRequestFacade.getCharacterEncoding(CoyoteRequestFacade.java:298) at FormEchoServlet.echo(FormEchoServlet.java:51) at FormEchoServlet.doPost(FormEchoServlet.java:37) at javax.servlet.http.HttpServlet.service(HttpServlet.java:767) at javax.servlet.http.HttpServlet.service(HttpServlet.java:860) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAsPrivileged(Subject.java:500) at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282) at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257) at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403) at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55) I am using Sun's most current Application Server (Sun Java System Application Server Platform Edition 8.1_02 (build b06-fcs)) which uses Tomcat underneath. Calling request.toString results in: [EMAIL PROTECTED] If this issue is known, accept my apologies - I was unable to find any record of it. If there is a fix, please let me know so I can go pester Sun about getting it fix into their server. Many thanks, Chris -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]