This quick start demonstrates the use of JBoss Logging Tools to create internationalized loggers, exceptions, and generic messages; and then provide localizations for them. This is done using a simple JAX-RS service. Translations in French(fr-FR), German(de-DE), and Swedish (sv-SE) are provided courtesy of http://translate.google.com for demonstration. My apologies if they are less than ideal translations.
The different methods of the JAX-RS service can be access using the URLs below:
rest/greetings/name
Example: rest/greetings/Harold
Simple use of localized messages (with parameter) and logging.
rest/greetings/locale/name
Example: rest/greetings/fr-FR/Harold
Demonstrates how to obtain a message bundle for a specified locale and how to throw a
localized exceptions. Note that the localized exception is a wrapper around
WebApplicationException
.
fr-FR-POSIX-FOO
) it throws a WebApplicationException
(404) using
a localizable sub-class of WebApplicationException
.
Note that WebApplicationException
cannot be directly localized by JBoss Logging
Tools using the @Message
annotation due to the message parameter being ignored by
WebApplicationException
's constructors. Cases like this can be worked around by
creating a sub-class with a constructor that does deal with the message parameter.
rest/greetings/crashme or rest/greetings/fr-FR/crashme
The name "crashme' demonstrates how to throw a localized exception with another exception specified as the cause. This is a completely contrived example.
rest/dates/daysuntil/targetDate
Example: rest/dates/daysuntil/2020-12-25
Demonstrates how to pass parameters through to the constructor of a localized exception, and how to specify an exception as a cause of a log message.