Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MessageSourceAccessor bundle of messages

 
Luis Parente
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a problem with my resource bundle. For retrieve my messages I do the following:



and I use it in an exception like that:



In the method getMessage I have defined a string default

In mode debug I can see that username(args to substitute in string ) is not null and in my security_fr_FR.properties the value of code DigestAuthenticationFilter.usernameNotFound it's ok.



But, when the exception is throw, in my jsp the text in not correctly written: , the args is not replace the argument.

If I spell a wrong code String, the default string is used and the message is correctly written in my JSP. if username equals to TOTO.


Any idea please?


Thanks in advance.


 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure the context your are defining your SpringSecurityMessageSource is correct. Also I don't see you defining a locale. Try passing the correct locale into getMessage. You can also try setting the locale or verifying it is correct in the LocaleContextHolder.


 
Luis Parente
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response, but about the local, I think the default local is used or I make a mistake?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It uses the locale you pass in. If you do not provide a locale it will use the one on the LocaleContextHolder.
 
Luis Parente
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have modified the getMessage

catch(EmptyResultDataAccessException msgErr){
throw new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.usernameNotFound",
new Object[]{username}, "Utilisateur {0} non paramétré en base", LocaleContextHolder.getLocale()));


and LocaleContextHolder.getLocale() is equal 'fr_FR', but the problem continue.

Thanks in advance.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK well you can revert back to what you had. I just wanted to make sure that it was indeed defined correctly on the LocaleContextHolder. The MessageSourceAccessor class will pull it off of there for you so you don't need to pass it in.

I would go back to looking at context scoping. Perhaps your messagesource in the context is not available like you think it is. Try to call a different get message use this one.



With this constructor you are not providing a default message so it will throw a NoSuchMessageException if it is not found. If this happens you know there is an issue with being able to properly find it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic