[Yanel-dev] weird locale-related exceptions

Paloma Gomez paloma.gomez at wyona.com
Wed Mar 21 12:22:10 CET 2007


Hi Josias,

Josias Thöny escribió:
> Hi Paloma,
>
> Paloma Gomez wrote:
>> Hi all,
>>
>> I keep getting the following exception message (see below) from time 
>> to time since a few days ago. At the beginning I thought it was my 
>> fault, since it seemed to be related to changes I had introduced and 
>> fixing the bugs these changes had introduced seem to solve the 
>> problem. However, after an update and with no changes in my tree, I 
>> keep getting it from time to time. The last time I got it was when I 
>> tried the following url:
>>
>> http://127.0.0.1:8080/yanel/yanel-website/en/about.html?yanel.resource.meta 
>>
>>
>> It seems to be caused by the setYanelOutput method in YanelServlet. I 
>> must leave now but I will look into it on monday and let you know 
>> about my findings.
>
> I suspect the error is caused by the i18n transformer:
>
> public I18nTransformer2(String messages, String language) {
>     currentLocale = new Locale(language);
>     messageBundle = ResourceBundle.getBundle(messages, currentLocale);
> }
>
> If the language is "es" but there is no spanish translation property 
> file, it will throw an exception. At least that's what I thought at 
> first. It doesn't seem to be quite as simple, though. When I request a 
> non-existing language, I don't get this error. I guess it also takes 
> the  default locale into account, which is "en" on my computer.
> I have no idea why you hit this error only sometimes and not always...

I have been looking into this problem and I have found more situations 
where I get this error:

1.  Requests containing ?yanel.resource.meta
2.  Requests for non-existent pages
3.  Requests for non-existent introspection files. I have found out that 
the PDF resource is not working any more. (Not only in my machine but 
also in the live server 
http://continuous-integration.yanel.wyona.org/test/use-cases/hello/pdf-sample2.pdf 
). I think this is a different bug that triggers the bug we are 
discussing (The  file introspection-.xml is requested -I think this file 
should not be requested since introspection does not make sense for pdf 
files - and setYanelOutput() is invoked triggering the language exception)
4. Requests containing ?yanel.meta.language=es, ?yanel.meta.language=fr

I have debugged a bit and

request.getHeader("Accept-Language");

returns

es-es,es;q=0.8,en-us;q=0.5,en;q=0.3

These exceptions are thrown whenever a non-existent language is 
requested either directly by issuing ?yanel.meta.language or indirectly 
(Accept-Language header).  For instance, ?yanel.meta.language=de does 
not trigger this exception. The problem is how the method setYanelOutput 
handles exceptions:

[code]
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
private void setYanelOutput(HttpServletRequest request, 
HttpServletResponse response, Document doc) throws ServletException {
        String path = request.getServletPath();
        String backToRealm = 
org.wyona.yanel.core.util.PathUtil.backToRealm(path);
     
        try {
            String yanelFormat = request.getParameter("yanel.format");
            if(yanelFormat != null && yanelFormat.equals("xml")) {

               [...]

            } else {

                [...]
                  
                // create i18n transformer:
                I18nTransformer2 i18nTransformer = new 
I18nTransformer2("global", getLanguage(request));

                [...]
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new ServletException(e.getMessage());
        }
    }

   /**
     * Get language with the following priorization: 1) 
yanel.meta.language query string parameter, 2) Accept-Language header, 
3) Default en
     */
    private String getLanguage(HttpServletRequest request) {
        String language = request.getParameter("yanel.meta.language");
        if (language == null) {
            language = request.getHeader("Accept-Language");          
            if (language != null) {
                int commaIndex = language.indexOf(",");
                if (commaIndex > 0) {
                    language = language.substring(0, commaIndex);
                }
                int dashIndex = language.indexOf("-");
                if (dashIndex > 0) {
                    language = language.substring(0, dashIndex);
                }
            }
        }
        if(language != null && language.length() > 0) return 
language;      
        return "en";
    }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I think we should  prevent this exception from being thrown by checking 
if the requested locale is available and otherwise requesting the 
default one (en). WDYT? I'll go on looking into a possible solution for 
this problem ( I have to familiarise myself with the I18nTransformer2 
first).

Regards,

Paloma

>
>
>>
>> Have a nice weekend,
>>
>> Paloma
>>
>> ---------------------------------------------------------------------------------------------------------------------- 
>>
>>
>> 11075 2007-03-16 17:55:37,707 [http-8080-Processor25] ERROR 
>> org.wyona.yanel.servlet.YanelServlet.setYanelOutput():1638  - Can't 
>> find bundle for base name global, locale es
>> java.util.MissingResourceException: Can't find bundle for base name 
>> global, locale es
>>    at 
>> java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836) 
>>
>>    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
>>   [...]
>> 11078 2007-03-16 17:55:37,710 [http-8080-Processor25] ERROR 
>> org.wyona.yanel.servlet.YanelServlet.doGet():240  - Can't find bundle 
>> for base name global, locale es
>> javax.servlet.ServletException: Can't find bundle for base name 
>> global, locale es
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.setYanelOutput(YanelServlet.java:1639) 
>>
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.getContent(YanelServlet.java:538)
>>    at org.wyona.yanel.servlet.YanelServlet.doGet(YanelServlet.java:237)
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.service(YanelServlet.java:180)
>>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>    at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) 
>>
>>    at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) 
>>
>>    [...]
>> 11083 2007-03-16 17:55:37,715 [http-8080-Processor25] ERROR 
>> org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/yanel].[YanelServlet].invoke():253  
>> - Servlet.service() para servlet YanelServlet lanzó excepción
>> javax.servlet.ServletException: Can't find bundle for base name 
>> global, locale es
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.setYanelOutput(YanelServlet.java:1639) 
>>
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.getContent(YanelServlet.java:538)
>>    at org.wyona.yanel.servlet.YanelServlet.doGet(YanelServlet.java:237)
>>    at 
>> org.wyona.yanel.servlet.YanelServlet.service(YanelServlet.java:180)
>>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>    at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) 
>>
>> [...]
>> --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
>>
>>
>>
>>
>>
>> _______________________________________________
>> Yanel-development mailing list
>> Yanel-development at wyona.com
>> http://wyona.com/cgi-bin/mailman/listinfo/yanel-development
>>
>
>
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://wyona.com/cgi-bin/mailman/listinfo/yanel-development
>
>




More information about the Yanel-development mailing list