Bug 28248

Summary: fmt:formatDate adds multiple content-language headers
Product: Taglibs Reporter: Antti Suanto <antti.suanto>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: major    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Antti Suanto 2004-04-07 07:39:10 UTC
When fmt:formatDate tag is used in jsp-page content-language header is added.
This is ok, but when formatDate tag is called multiple times, multiple
content-language headers are added. This causes that some browsers (including
IE) will not display the page.

The problem seems to be in SetLocaleSupport.getFormattingLocale which for some
reason calls setResponseLocale method and this sets content-language header.

This is tested with 1.0.3 and 1.0.5 versions.
Comment 1 Martin Cooper 2004-04-07 18:46:19 UTC
You filed this bug against the i18n taglib, but that taglib does not have 1.0.3 
and 1.0.5 versions. Did you mean the Standard taglib (i.e. JSTL)?
Comment 2 Martin Cooper 2004-04-07 18:50:01 UTC
*** Bug 28258 has been marked as a duplicate of this bug. ***
Comment 3 Antti Suanto 2004-04-08 05:42:31 UTC
Yes, sorry I selected wrong component. I meant standard taglib.
Comment 4 Antti Suanto 2004-04-08 07:23:49 UTC
I tested the tag with tomcat and no problems. So the problem seems to be in OC4J
(10g).
Comment 5 Felipe Leme 2004-05-12 00:27:07 UTC
CC'ing the taglibs-dev address to all Standard bugs. 
Comment 6 Justyna Horwat 2004-06-11 21:48:52 UTC
I tried to reproduce the problem with JSTL 1.0.5 and Tomcat 4.1.30 but was unsuccessful.

If it is a problem with the OC4J container, please bring this to Oracle's attention so they can fix the bug 
in their container.
Comment 7 Philippe Mouawad 2005-09-28 09:53:02 UTC
I'm facing the same problem on OC4J 10G (9.0.4.0.1).
What happens is that response.setLocale(locale); is called as many times as 
formatDate (or formatNumber) is in the JSP, thus it provokes a header overflow 
(I analysed the traffic with Ethereal and you see as much a 20 Content-Language 
headers in the response).
It works on Tomcat 4.1.30, but it is not a prove that it works  because may be 
Tomcat ignores all the response.setLocale but the first what Oracle does not do.
In the spec it it said that :
"Sets the locale of the response, setting the headers (including the Content-
Type's charset) as appropriate. This method should be called before a call to 
getWriter(). By default, the response locale is the default locale for the 
server." Nothing more.
Comment 8 Philippe Mouawad 2005-09-28 10:34:47 UTC
I checked Tomcat code of setHeader and it overwrites the header if it already 
exists but the call to setHeader("Content-Language", <value>) occurs 20 times: 
    public void setHeader(String name, String value) {

        if (isCommitted())
            return;

        if (included)
            return;     // Ignore any call from an included servlet

// This code overwrites
        ArrayList values = new ArrayList();
        values.add(value);
        synchronized (headers) {
            headers.put(name, values);
        }
// End of the code overwrites

        String match = name.toLowerCase();
        if (match.equals("content-length")) {
            int contentLength = -1;
            try {
                contentLength = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                ;
            }
            if (contentLength >= 0)
                setContentLength(contentLength);
        } else if (match.equals("content-type")) {
            setContentType(value);
        }

    }
Comment 9 Philippe Mouawad 2005-09-28 11:39:12 UTC
To be fully precise about the problem, I decompiled the OC4J implementation and 
the method setLocale() calls  addHeader("Content-Language", language);
not setHeader which explains the problem :

            public void setLocale(java.util.Locale locale)
            {
/*1805*/        if(locale == null || isIncluded)
/*1805*/            return;
/*1807*/        if(isCommitted() && locale != this.locale)
/*1808*/            throw new IllegalStateException("Response is already 
committed!");
/*1811*/        this.locale = locale;
/*1814*/        java.lang.String _charset = (java.lang.String)LOCALE_MAP.get
(locale.toString());
/*1815*/        if(_charset == null)
/*1816*/            _charset = (java.lang.String)LOCALE_MAP.get
(locale.getLanguage());
/*1819*/        if(outputFetchStatus == 2 && charset != null && !
_charset.equalsIgnoreCase(charset))
/*1823*/            throw new IllegalStateException("Output writer already 
acquired");
/*1827*/        if(contentType != null && (charset == null || !
charset.equalsIgnoreCase(_charset)))
                {
/*1831*/            contentType = 
com.evermind.server.http.EvermindHttpServletResponse.constructContentType
(contentType, _charset);
/*1832*/            contentTypeHeader = null;
                }
/*1836*/        charset = _charset;
/*1837*/        isCharsetSet = true;
/*1840*/        java.lang.String language = locale.getLanguage();
/*1841*/        if(language != null && language.length() > 0)
                {
/*1843*/            java.lang.String country = locale.getCountry();
/*1844*/            if(country != null && country.length() > 0)
/*1845*/                addHeader("Content-Language", language + "-" + country);
/*1847*/            else
/*1847*/                addHeader("Content-Language", language);
                }
            }
Comment 10 Martin Cooper 2005-09-28 18:54:49 UTC
This is an OC4J issue.