Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jaxrs-dev] Integrating JAX-RS, CDI and bean validation

Hi Christian,

2018-03-03 9:25 GMT+01:00 Christian Kaltepoth <christian@xxxxxxxxxxxx>:
Well. This would require modifications in CDI, BV and JAX-RS. This will be difficult to coordinate. Although this could be a nice solution from a platform perspective.

If this is the right way to do it, we should at least try. Otherwise we'll get a more complicated solution just because it is easier to do. Also specifying that a locale is available for injection in the request context of JAX-RS would already help even if the other specifications are not updated.
 
But I don't think CDI should be required for this. Actually it would be nice to have some SPI in Bean Validation which allows you to choose the locale which will be used by default (currently the system default locale, which is almost never what you actually want in a web application) without the need of providing a custom MessageInterpolator.

Your suggestion is somehow similar to what we defined in the MVC spec to cover this use case. Basically we defined the term "request locale" as the locale to use for all locale dependent operations. There is a default resolver which uses the "Accept-Language" header to resolve the request locale. But users can provide custom resolvers to change this default behavior. See chapter 8 in the MVC specification.
 
I totally agree with you that the default of using the server locale does not make a lot of sense. But regardless of what we decide, changing the default behavior will be less of a technical challenge, but a question of whether keeping the spec backwards compatible is more important than getting a better default behavior or not.

Regarding the CDI requirement: I guess we have to decide which way we are heading. Should this ticket https://github.com/eclipse-ee4j/jaxrs-api/issues/569 be implemented, we would definitly have a dependency on CDI and could then always depend on CDI.

On the other hand adding an interface like the LocaleResolver in MVC:

Locale resolveLocale(LocaleResolverContext context)

indicates more or less that we are not using dependency injection (CDI already defines the context we are in, so why define another LocaleResolverContext?).

So I think this is a strategic decission, that has to be made: What is the JAX-RS relation to CDI? Will it depend on it? Is it just an option?  I have no idea what others think about this or whether there is some kind consensus on how to proceed.

One way of working around this issue could perhaps be to split the specification: The main part that specifies the requirements JAX-RS has on the container in general terms e.g "a locale is provided in the context of the request" and a second part that specified the "binding" of these terms to a specific environment:
* CDI Binding: A producer method can be defined, injection is done using @Inject
* Standalone Binding: ContextResolver and LocaleResolver are used to retrieve the Locale, injection is done using @Context

Best regards,
  Niklas


 


Back to the top