tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 24970] - charset appended to content-type even if not text/*
Date Fri, 04 Mar 2005 15:37:22 GMT
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=24970>.
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=24970





------- Additional Comments From Michiel.Meeuwissen@omroep.nl  2005-03-04 16:37 -------
I have a work-around in the form of a Filter. This filter uses a ResponseWrapper
to wrap getWriter:

 public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse, FilterChain filterChain) 
        throws java.io.IOException, ServletException {

        HttpServletResponseWrapper wrapper = new
HttpServletResponseWrapper((HttpServletResponse) servletResponse) {
                private String contentType;
                public void setContentType(String ct) {
                    contentType = ct;
                    super.setContentType(ct);
                }

                /**
                 * This is the essence of this whole thing. The idea
                 * is to fake the use of getOutputStream(). Then you
                 * are in byte-writing mode.  and charset's become
                 * irrelevant,and tomcat will not add one any more.
                 */
                
                public PrintWriter getWriter() throws IOException {
                    if (contentTypes.contains(contentType)) {
                        log.debug("Wrapping outputstream to avoid charset");
                        try {
                            // ISO-8859-1 is default for HTTP
                            return new PrintWriter(new BufferedWriter(new
OutputStreamWriter(getOutputStream(), "ISO-8859-1")));
                        } catch (UnsupportedEncodingException uee) {
                            // could not happen
                            return super.getWriter();
                        }
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug(" " + contentType + " is not contained by
" + contentTypes);
                        }
                        return super.getWriter();
                    }
                }
        };
        filterChain.doFilter(servletRequest, wrapper);
        
    }


So, you can configure a set of contentypes for which no charset is added and
which therefore must be in ISO-8859-1.



-- 
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: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message