pierred 00/12/22 06:19:15 Modified: src/share/org/apache/jasper Tag: tomcat_32 EmbededServletOptions.java JspC.java Options.java src/share/org/apache/jasper/compiler Tag: tomcat_32 Compiler.java src/share/org/apache/jasper/resources Tag: tomcat_32 messages.properties src/share/org/apache/tomcat/request Tag: tomcat_32 JspInterceptor.java Log: Bug fix: bug report #269 -- java.io.UnsupportedEncodingException when processing JSP From the bug report: "A "java.io.UnsupportedEncodingException: UTF8" is thrown when generating the servlet for a JSP file when the Kaffe VM is used. The "UTF8" encoding name is hardcoded in the Compiler class as the encoding for the generated servlet source code file. I believe the reason for using "UTF8" as opposed to "UTF-8" (note the dash) is that this is the only name supported in JDK 1.1. I suggest adding an init parameter to JspServlet for setting the encoding name when "UTF8" doesn't work." Given that there are several possible representations of Unicode data (UTF-8, UTF-16, UTF-32), and given that the supported encodings vary between different implementations of the Java platform, the best way to tackle this is probably as suggested by Hans. Submitted by: Hans Bergsten ( [EMAIL PROTECTED] ) Revision Changes Path No revision No revision 1.4.2.1 +14 -4 jakarta-tomcat/src/share/org/apache/jasper/EmbededServletOptions.java Index: EmbededServletOptions.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/EmbededServletOptions.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- EmbededServletOptions.java 2000/05/26 18:55:09 1.4 +++ EmbededServletOptions.java 2000/12/22 14:19:10 1.4.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/EmbededServletOptions.java,v 1.4 2000/05/26 18:55:09 costin Exp $ - * $Revision: 1.4 $ - * $Date: 2000/05/26 18:55:09 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/EmbededServletOptions.java,v 1.4.2.1 2000/12/22 14:19:10 pierred Exp $ + * $Revision: 1.4.2.1 $ + * $Date: 2000/12/22 14:19:10 $ * * ==================================================================== * @@ -135,6 +135,11 @@ */ public String jspCompilerPath = null; + /** + * Java platform encoding to generate the JSP + * page servlet. + */ + private String javaEncoding; /** * Are we keeping generated code around? @@ -207,6 +212,10 @@ return jspCompilerPath; } + public String getJavaEncoding() { + return javaEncoding; + } + /** * Create an EmbededServletOptions object using data available from * ServletConfig and ServletContext. @@ -309,7 +318,8 @@ Logger.FATAL); } } - + + this.javaEncoding = config.getInitParameter("javaEncoding"); } } 1.15.2.2 +7 -3 jakarta-tomcat/src/share/org/apache/jasper/JspC.java Index: JspC.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -u -r1.15.2.1 -r1.15.2.2 --- JspC.java 2000/07/12 16:04:20 1.15.2.1 +++ JspC.java 2000/12/22 14:19:10 1.15.2.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.15.2.1 2000/07/12 16:04:20 shemnon Exp $ - * $Revision: 1.15.2.1 $ - * $Date: 2000/07/12 16:04:20 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.15.2.2 2000/12/22 14:19:10 pierred Exp $ + * $Revision: 1.15.2.2 $ + * $Date: 2000/12/22 14:19:10 $ * * ==================================================================== * @@ -198,6 +198,10 @@ public String getJspCompilerPath() { // we don't compile, so this is meanlingless return null; + } + + public String getJavaEncoding() { + return "UTF-8"; } public String getClassPath() { 1.11.2.1 +9 -3 jakarta-tomcat/src/share/org/apache/jasper/Options.java Index: Options.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Options.java,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -r1.11 -r1.11.2.1 --- Options.java 2000/05/26 18:55:10 1.11 +++ Options.java 2000/12/22 14:19:11 1.11.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Options.java,v 1.11 2000/05/26 18:55:10 costin Exp $ - * $Revision: 1.11 $ - * $Date: 2000/05/26 18:55:10 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/Options.java,v 1.11.2.1 2000/12/22 14:19:11 pierred Exp $ + * $Revision: 1.11.2.1 $ + * $Date: 2000/12/22 14:19:11 $ * * ==================================================================== * @@ -125,4 +125,10 @@ * ProtectionDomain for this JSP Context when using a SecurityManager */ public Object getProtectionDomain(); + + /** + * Java platform encoding to generate the JSP + * page servlet. + */ + public String getJavaEncoding(); } No revision No revision 1.19.2.3 +36 -9 jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java Index: Compiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.19.2.2 retrieving revision 1.19.2.3 diff -u -r1.19.2.2 -r1.19.2.3 --- Compiler.java 2000/08/28 17:48:24 1.19.2.2 +++ Compiler.java 2000/12/22 14:19:12 1.19.2.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.19.2.2 2000/08/28 17:48:24 rubys Exp $ - * $Revision: 1.19.2.2 $ - * $Date: 2000/08/28 17:48:24 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.19.2.3 2000/12/22 14:19:12 pierred Exp $ + * $Revision: 1.19.2.3 $ + * $Date: 2000/12/22 14:19:12 $ * * ==================================================================== * @@ -66,6 +66,7 @@ import java.io.PrintWriter; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; +import java.io.OutputStreamWriter; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.Constants; @@ -143,8 +144,11 @@ // XXX - There are really three encodings of interest. String jspEncoding = "8859_1"; // default per JSP spec - String javaEncoding = "UTF8"; // perhaps debatable? + // We try UTF8 by default. If it fails, we use the java encoding + // specified for JspServlet init parameter "javaEncoding". + String javaEncoding = "UTF8"; + // This seems to be a reasonable point to scan the JSP file // for a 'contentType' directive. If it found then the set // the value of 'jspEncoding to reflect the value specified. @@ -166,11 +170,34 @@ jspEncoding ); - ServletWriter writer = - (new ServletWriter - (new PrintWriter - (new java.io.OutputStreamWriter( - new FileOutputStream(javaFileName),javaEncoding)))); + OutputStreamWriter osw; + try { + osw = new OutputStreamWriter( + new FileOutputStream(javaFileName),javaEncoding); + } catch (java.io.UnsupportedEncodingException ex) { + // Try to get the java encoding from the "javaEncoding" + // init parameter for JspServlet. + javaEncoding = ctxt.getOptions().getJavaEncoding(); + if (javaEncoding != null) { + try { + osw = new OutputStreamWriter( + new FileOutputStream(javaFileName),javaEncoding); + } catch (java.io.UnsupportedEncodingException ex2) { + // no luck :-( + throw new JasperException( + Constants.getString("jsp.error.invalid.javaEncoding", + new Object[] { + "UTF8", + javaEncoding, + })); + } + } else { + throw new JasperException( + Constants.getString("jsp.error.needAlternateJavaEncoding", + new Object[] { "UTF8" })); + } + } + ServletWriter writer = new ServletWriter(new PrintWriter(osw)); ctxt.setReader(reader); ctxt.setWriter(writer); No revision No revision 1.17.2.7 +3 -1 jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties Index: messages.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties,v retrieving revision 1.17.2.6 retrieving revision 1.17.2.7 diff -u -r1.17.2.6 -r1.17.2.7 --- messages.properties 2000/11/06 04:08:15 1.17.2.6 +++ messages.properties 2000/12/22 14:19:13 1.17.2.7 @@ -1,4 +1,4 @@ -# $Id: messages.properties,v 1.17.2.6 2000/11/06 04:08:15 larryi Exp $ +# $Id: messages.properties,v 1.17.2.7 2000/12/22 14:19:13 pierred Exp $ # # Default localized string information # Localized this the Default Locale as is en_US @@ -211,3 +211,5 @@ jspc.error.emptyWebApp=-webapp requires a trailing file argument jsp.error.no.more.content=End of content reached while more parsing required: unterminated tag or tag nesting error? jsp.error.unterminated.user.tag=Unterminated user-defined tag: ending tag {0} not found or incorrectly nested +jsp.error.invalid.javaEncoding=Invalid java encodings. Tried {0} and then {1}. Both failed. +jsp.error.needAlternateJavaEncoding=Default java encoding {0} is invalid on your java platform. An alternate can be specified via the 'javaEncoding' parameter of JspServlet. No revision No revision 1.3.2.1 +10 -0 jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/JspInterceptor.java Index: JspInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/JspInterceptor.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- JspInterceptor.java 2000/06/30 20:21:41 1.3 +++ JspInterceptor.java 2000/12/22 14:19:14 1.3.2.1 @@ -524,6 +524,16 @@ public String getJspCompilerPath() { return jspCompilerPath; } + + /** + * FIXME: see how compiler.Compiler handles javaEncoding + * and implement that behavior in this class when it + * is 'enabled' (pierred). This has been added only so the + * code compiles. + */ + public String getJavaEncoding() { + return "FIXME: NOT IMPLEMENTED"; + } }