dev@jersey.java.net

Re: [Jersey] How to internationalize the Response.Status?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 10 Sep 2010 12:00:18 +0200

Hi,

I think this would require changes to the 311 implementation (no API
changes required), to defer to l10n property files, presuming that you
want to localize based on the locale set in the server environment.

If we want to return according to the most acceptable language then
that is a little tricker, and usually the accept-language applies to
the representation and not to the reason phrase.

In this case i think your best approach is to define your own reason
phrase strings and implement a localized version of StatusType,
instances of which can be set on Response.

Note that there is a limitation on Jersey setting the reason phrase
because of a restriction in the Servlet API. It can only be set when a
HttpServletResponse.sendError is called, and cannot be set when a
response entity is also to be required.

Paul.

On Sep 9, 2010, at 6:37 PM, exxos wrote:

> Hi,
>
> The question is more related to JSR-311, but I'm wondering what
> could be the best approach to internationalize the messages defined
> in the enum Reponse.Status.
>
> For example:
>
> Response.Status.INTERNAL_ERROR_SERVER.getString()
> returns "Internal Server Error" (RFC 2616)
>
> I noticed that Tomcat by default does it, but it is based on your
> installation. For my part, I tested a french version and if a
> WebApplicationExceptionResponse
> .Status.INTERNAL_ERROR_SERVER.getStatusCode()) is thwon, you get
> the default Tomcat display of "Error Code 500 - Internal Error
> Server" is something that looks like: "Le serveur a rencontré une
> erreur interne () qui l'a empêché de satisfaire la requête".
> This is minimalistic but interesting.
>
> This need comes after putting in place a ExceptionMapper that
> catches all RuntimeExceptions.
> The mapper is now in charge to answer in a correct format (as best
> as it can) to the end user.
>
> I'm talking here about default HTTP status messages, when the
> database (internationlization) cannot achive it.
> One of the basic solution, could be to create a new Enum?
> Or maybe this is not a real problem and after all, if the error
> message does not exist in database, the default language is
> "English" and the one returned by the
> Reponse.Status.XXXX.getString() ? Finally, what's the best/
> acceptable appraoch?
> Thank you for your advises.
>
> Regards,
> exxos.