Hi. The Servlet 2.4 spec says that ServletResponse now gets two more methods, (from sections 5.4, 14.2.22) Namely;
String getContentType(); void setCharacterEncoding(String charset) To implement this, I patched 3 repositories jakarta-servletapi-5, jakarta-tomcat-connectors, jakarta-tomcat-catalina I tested the "connectors" patch against 4.0 and my changes don't seem to break 4.0 (and so dont require messing with forking connectors.) Cheers, -bob P.S. The servletapi is still sprinkled with tabs. I tried to preserve the current tabbing (and not change all to spaces per jakarta rule(?))
? apipatch.txt Index: src/share/javax/servlet/ServletResponse.java =================================================================== RCS file: /home/cvspublic/jakarta-servletapi-5/src/share/javax/servlet/ServletResponse.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ServletResponse.java --- src/share/javax/servlet/ServletResponse.java 16 Jul 2002 16:38:40 -0000 1.1.1.1 +++ src/share/javax/servlet/ServletResponse.java 1 Aug 2002 16:03:09 -0000 @@ -122,6 +122,16 @@ public String getCharacterEncoding(); + /** + * Overrides the name of the character encoding used in the body + * of the request. This method must be called prior to reading + * request parameters or reading input using getReader(). + * + * @param charset String containing the name of the chararacter encoding. + * + */ + + public void setCharacterEncoding(String charset); /** @@ -223,6 +233,24 @@ */ public void setContentType(String type); + + /** + * Returns the MIME type of the body of the request, or null if + * the type is not known. For HTTP servlets, same as the value of + * the CGI variable CONTENT_TYPE. + * + * @return a String containing the name of the MIME type of the + * request, or null if the type is not known + * + * <p> The content type may include the type of character + * encoding used, for example, <code>text/html; charset=ISO-8859-4</code>. + * + * @see #getOutputStream + * @see #getWriter + * + */ + + public String getContentType(); /** Index: src/share/javax/servlet/ServletResponseWrapper.java =================================================================== RCS file: /home/cvspublic/jakarta-servletapi-5/src/share/javax/servlet/ServletResponseWrapper.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ServletResponseWrapper.java --- src/share/javax/servlet/ServletResponseWrapper.java 16 Jul 2002 16:38:40 -0000 1.1.1.1 +++ src/share/javax/servlet/ServletResponseWrapper.java 1 Aug 2002 16:03:10 -0000 @@ -74,7 +74,7 @@ * * @author Various * @version $Version$ - * @since v 2.3 + * @since v 2.3 * * @see javax.servlet.ServletResponse * @@ -117,16 +117,25 @@ this.response = response; } - /** - * The default behavior of this method is to return getCharacterEncoding() + /** + * The default behavior of this method is to call setCharacterEncoding(String +charset) * on the wrapped response object. */ + public void setCharacterEncoding(String charset) { + this.response.setCharacterEncoding(charset); + } + + /** + * The default behavior of this method is to return getCharacterEncoding() + * on the wrapped response object. + */ public String getCharacterEncoding() { return this.response.getCharacterEncoding(); } + /** * The default behavior of this method is to return getOutputStream() * on the wrapped response object. @@ -162,6 +171,15 @@ public void setContentType(String type) { this.response.setContentType(type); + } + + /** + * The default behavior of this method is to return getContentType() + * on the wrapped response object. + */ + + public String getContentType() { + return this.response.getContentType(); } /** Index: src/share/javax/servlet/http/HttpServlet.java =================================================================== RCS file: /home/cvspublic/jakarta-servletapi-5/src/share/javax/servlet/http/HttpServlet.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 HttpServlet.java --- src/share/javax/servlet/http/HttpServlet.java 16 Jul 2002 16:38:40 -0000 1.1.1.1 +++ src/share/javax/servlet/http/HttpServlet.java 1 Aug 2002 16:03:12 -0000 @@ -890,8 +890,14 @@ didSetContentLength = true; } + public void setCharacterEncoding(String charset) + { resp.setCharacterEncoding(charset); } + public void setContentType(String type) { resp.setContentType(type); } + + public String getContentType() + { return resp.getContentType(); } public ServletOutputStream getOutputStream() throws IOException { return noBody; }
Index: catalina/src/share/org/apache/catalina/connector/ResponseBase.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ResponseBase.java --- catalina/src/share/org/apache/catalina/connector/ResponseBase.java 18 Jul 2002 16:47:57 -0000 1.1.1.1 +++ catalina/src/share/org/apache/catalina/connector/ResponseBase.java 1 Aug 2002 15:43:46 -0000 @@ -877,6 +877,38 @@ } + /* + * Overrides the name of the character encoding used in the body + * of the request. This method must be called prior to reading + * request parameters or reading input using getReader(). + * + * @param charset String containing the name of the chararacter encoding. + */ + public void setCharacterEncoding(String charset) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + this.encoding = charset; + + int start = contentType.indexOf("charset="); + if ( start != -1 ) { + + int end = contentType.indexOf(';', start+8); + if (end >= 0) + contentType = contentType.substring(0,start+8) + +charset+contentType.substring(end-1); + else + contentType = contentType.substring(0,start+8) + +charset; + + } + } + + /** * Set the Locale that is appropriate for this response, including Index: catalina/src/share/org/apache/catalina/connector/ResponseFacade.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 ResponseFacade.java --- catalina/src/share/org/apache/catalina/connector/ResponseFacade.java 18 Jul 2002 16:47:57 -0000 1.1.1.1 +++ catalina/src/share/org/apache/catalina/connector/ResponseFacade.java 1 Aug 2002 15:43:46 -0000 @@ -188,6 +188,15 @@ } + public void setCharacterEncoding(String charset) { + + if (isCommitted()) + return; + + response.setCharacterEncoding(charset); + + } + public void setContentType(String type) { @@ -198,6 +207,11 @@ } + public String getContentType() { + + return response.getContentType(); + + } public void setBufferSize(int size) {
Index: coyote/src/java/org/apache/coyote/Response.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java,v retrieving revision 1.11 diff -u -r1.11 Response.java --- coyote/src/java/org/apache/coyote/Response.java 9 Apr 2002 18:19:27 -0000 1.11 +++ coyote/src/java/org/apache/coyote/Response.java 1 Aug 2002 15:44:25 -0000 @@ -443,6 +443,35 @@ } + /* + * Overrides the name of the character encoding used in the body + * of the request. This method must be called prior to reading + * request parameters or reading input using getReader(). + * + * @param charset String containing the name of the chararacter encoding. + */ + public void setCharacterEncoding(String charset) { + + if (isCommitted()) + return; + + characterEncoding = charset; + + String type = this.contentType; + int start = type.indexOf("charset="); + if ( start != -1 ) { + int end = type.indexOf(';', start+8); + if (end >= 0) + type = type.substring(0,start+8) + +charset+type.substring(end-1); + else + type = type.substring(0,start+8) + +charset; + this.contentType = type; + + } + } + public String getCharacterEncoding() { return characterEncoding; } Index: coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java,v retrieving revision 1.18 diff -u -r1.18 CoyoteResponse.java --- coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java 28 Jun 2002 11:25:54 -0000 1.18 +++ coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java 1 Aug 2002 15:44:27 -0000 @@ -717,6 +717,24 @@ } + /* + * Overrides the name of the character encoding used in the body + * of the request. This method must be called prior to reading + * request parameters or reading input using getReader(). + * + * @param charset String containing the name of the chararacter encoding. + */ + public void setCharacterEncoding(String charset) { + + if (isCommitted()) + return; + + if (included) + return; // Ignore any call from an included servlet + + coyoteResponse.setCharacterEncoding(charset); + } + /** * Set the Locale that is appropriate for this response, including * setting the appropriate character encoding.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>