Date   

Re: Providers ordering

Sergey Beryozkin
 

Continuing with the idea of the special treatment of the providers shipped with the spec implementations.
Rather than pursue a @DefaultProvider idea, how about treating the providers in the javax.* namespace as 'default' ones ?

Thus if say an MVC API ships its own CSRF exception mapper then it will be selected, unless the application has registered its own.

Moreover, perhaps this idea and the idea of using @Priority are not mutually exclusive. IMHO the former puts less 'pressure' on the application providers to make it right...

Sergey

On 21/05/17 16:19, Sergey Beryozkin wrote:
Hi Christian

Right, do you mean that both of these providers are custom as far as the JAX-RS implementation is concerned ?

Sure, I see what you mean now.

I guess my only doubt at this stage is, should the providers offered by MVC implementation (or some other *spec-implementaion* API) have a special treatment status, as far as JAX-RS is concerned ? Example, be annotated with some @DefaultProvider annotation (to be introduced in JAX-RS) ? In this case JAX-RS, seeing two MyObject exception mappers, will select the one which has no @DefaultProvider.

May be using @Priority is simpler, but it would require application mappers to know how to set their own @Priority to ensure it is high or low enough. The problem with @DefaultProvider is that it is probably too late as ex MVC API would need updated after 2.1 is out.

Cheers. Sergey

On 21/05/17 15:58, Christian Kaltepoth wrote:
Hi Sergey,

By the way, what is the actual point of ordering say 2 ExceptionMapper<MyObject> - would it go a bit too far without bringing any real benefit ?

Of course nobody will want to create two ExceptionMapper<MyObject> implementations in his application. It is more about the case that some framework provides a "default" exception mapper for a specific exception type and the developer should still be able to provide a custom one which is preferred by the JAX-RS implementation.

We had this case in JSR-371 (MVC 1.0): If the validation of a CSRF token fails, the MVC implementation throws a CsrfValidationException. The MVC implementation provides a default mapper ExceptionMapper<CsrfValidationException> which just sends a 403 status code. But the developer should be able to provide a custom exception mapper which does something else, like rendering some HTML page. However, this is currently not possible, because if there are two ExceptionMapper<CsrfValidationException> implementations discovered, there is no way to tell the JAX-RS implementation which one to choose.

Christian



--




Re: Providers ordering

Sergey Beryozkin
 

Hi Christian
On 21/05/17 18:22, Christian Kaltepoth wrote:
Hey Sergey,

thanks for your quick reply.

Thanks too,

Right, do you mean that both of these providers are custom as far as the JAX-RS implementation is concerned ?

Yes, exactly. In this case JAX-RS currently doesn't specify which one should be used.

 
Sure, I see what you mean now.

I guess my only doubt at this stage is, should the providers offered by MVC implementation (or some other *spec-implementaion* API) have a special treatment status, as far as JAX-RS is concerned ? Example, be annotated with some @DefaultProvider annotation (to be introduced in JAX-RS) ? In this case JAX-RS, seeing two MyObject exception mappers, will select the one which has no @DefaultProvider.

Not sure if something like @DefaultProvider is flexible enough. Maybe this "default provider" vs "custom provider" use case is just one special case? I mean, it is always possible to have multiple exception mappers on the classpath if they are provided by different libraries. And in this case it would be nice to have some clear rules on how to handle this situation.
 

May be using @Priority is simpler, but it would require application mappers to know how to set their own @Priority to ensure it is high or low enough.

For filters and interceptors there is already javax.ws.rs.Priorities which contains constants which can be used for ordering. So this could also be used for exception mappers and param providers.

I agree using @Priority is a viable option. But as I implied earlier, this approach (apart from solving the issue shown with MVC vs custom CSRF mapper) raises the question - why to support two ExceptionMapper<MyObject> or ParamConverters in general. Perhaps it does not really matter, but I guess we'd like to avoid supporting the solutions where the developers will start thinking about dropping 3 ExceptionMapper<MyObject>, and ordering them 1, 2, 3 and making each of them, say, 1 and 2, not to map, for 3 to do the final mapping :-).

That said, may be this example is hypothetical, and using @Priority just works, though I thought I'd suggest a 'default mapper' around javax.* idea too...  

Thanks, Sergey

 
The problem with @DefaultProvider is that it is probably too late as ex MVC API would need updated after 2.1 is out.

That wouldn't be a problem, because MVC will go final after JAX-RS and therefore could depend on JAX-RS 2.1.


Best regards

Christian



--



Re: Built-in proxy support in Client API?

Pavel Bucek
 

Hi Dennis,

thanks for the pull request; please don't hijack the topic - this one is about client proxy support. Feel free to start a new thread.

Regards,
Pavel


On 21/05/2017 11:05, Dennis Kieselhorst wrote:

Hi,

in my view there should be at least standardized constants for the properties in 2.1. I created a PR for the timeout stuff yesterday: https://github.com/jax-rs/api/pull/555

These properties can be used by convenience methods in ClientBuilder.

I can also create a PR for the proxy constants if the solution is agreed.

Regards

Dennis



Re: Built-in proxy support in Client API?

Dennis Kieselhorst
 

Hi Pavel,

I don't want to hijack the topic, I'm just saying that we can handle both cases in a common way.

Regards
Dennis


Re: Returning CompletionStage from the resource method

Pavel Bucek
 

Hi Sergey,

ad 1) the response processing will be done on the caller (completer) thread (so, completionStage#whenComplete(..), not #whenCompleteAsync(..)), simply because it works in a same way as when using AsyncResponse.

ad 2) good idea. I'm not sure whether we'll be able to do that now, but could you please file an issue? https://github.com/jax-rs/api/issues

Thanks,
Pavel


On 21/05/2017 13:47, Sergey Beryozkin wrote:

Hi Pavel

I'd leave it up to the implementation to decide.

The other thing I was thinking about. On the client side we have RxInvoker which supports not only CompletableFuture. Should we have something like RxResponse such that not only CompletableFuture is supported ?

Thanks, Sergey





Re: Providers ordering

Santiago Pericas-Geertsen
 


On May 21, 2017, at 5:03 AM, Pavel Bucek <pavel.bucek@...> wrote:

Hi Christian,

see chapter 4.2.4:


An implementation MUST support application-provided entity providers and MUST use those in preference to its own pre-packaged providers when either could handle the same request. More precisely, step 4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers.


Which i s the base of what I mentioned - there is one issue though - this is only about entity providers, not about ExceptionMappers, which are covered by chapter 4.3.

I believe we could include more general statement in chapter 4, which would say that application provided Providers have priority over build-ins (and maybe define what build-in is) OR we can say that implementation providers should have some concrete priority set - which could be simpler than formally defining built-in provider.

Santiago, others, what do you think?


 
 I agree. Naturally, user-defined providers should take precedence over built-in ones. Clearly, this statement is implicit rather than explicit and should be clarified —at least for some providers. That was always the intent.

 As for what is user-defined vs. built-in, I don’t thing that is hard to define: if it is registered using the JAX-RS API or discovered via class scanning (i.e. annotated with @Provider), then it is user-defined regardless of their physical location (library, container, etc.). Built-in ones should not be made available using those mechanisms. 

— Santiago

Thanks,
Pavel


On 21/05/2017 10:48, Christian Kaltepoth wrote:
Hi everyone,

I'm very happy to see that the issue of provider ordering is addressed in the upcoming JAX-RS release. Thanks a lot for your work on that.

I would like to point the EG to a discussion from one of the issues which was about whether the priority ordering should be used only for "custom providers" or for all providers (custom and built-in providers). See [1] for details. During the discussion Pavel mentioned that JAX-RS already mandates that custom providers are preferred over built-in providers. I didn't find this anywhere in the spec document, but maybe I just missed it.

The one thing that still makes me think that the priority ordering should be used for all providers is that the definition of "built-in provider" is a bit blurry. What is a built-in provider? What about providers which are deployed as app server modules and therefore are provided out of the box by the container? Are they built-in or custom providers? Perhaps this should simply be clarified in the spec?

I would be happy to hear about other opinions.

Christian













2017-05-19 14:08 GMT+02:00 Pavel Bucek <pavel.bucek@...>:

Dear experts,

there is couple of filed issues related to provider ordering, namely:

https://github.com/jax-rs/api/issues/538
https://github.com/jax-rs/api/issues/537

We already do have them implemented in the RI and we discovered that we can do similar things for almost all providers (including readers/writers, ..), which don't have already defined @Priority handling (filters and interceptors do have that already).

For these providers, lover priority value means higher priority. For example, if you have following ExceptionMappers:



then "MySecondExceptionMapper" will be invoked when "MyException" is thrown.


@Provider
@Priority(300)
public static class MyFirstExceptionMapper implements ExceptionMapper<MyException> {
    // ...}

@Provider
@Priority(100)
public static class MySecondExceptionMapper implements ExceptionMapper<MyException> {
    // ...

}

@Provider
@Priority(200)
public static class MyThirdExceptionMapper implements ExceptionMapper<MyException> {
    // ...

}

Do you have any comments or suggestions before we incorporate that change into the spec document?

Thanks and regards, Pavel




--



Re: Providers ordering

Santiago Pericas-Geertsen
 


On May 21, 2017, at 7:42 AM, Sergey Beryozkin <sberyozkin@...> wrote:

Hi Pavel

Not sure it is relevant but it is not exactly the case with MessageBodyReader/Writers where the custom providers can still lose to built-in providers.

 Priority should only be used to break ties. Certain providers have well-defined selection algorithms, but in some cases the final set is not a singleton.

— Santiago

On 21/05/17 10:03, Pavel Bucek wrote:

Hi Christian,

see chapter 4.2.4:


An implementation MUST support application-provided entity providers and MUST use those in preference to its own pre-packaged providers when either could handle the same request. More precisely, step 4 in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer application-provided over pre-packaged entity providers.

Which i s the base of what I mentioned - there is one issue though - this is only about entity providers, not about ExceptionMappers, which are covered by chapter 4.3.

I believe we could include more general statement in chapter 4, which would say that application provided Providers have priority over build-ins (and maybe define what build-in is) OR we can say that implementation providers should have some concrete priority set - which could be simpler than formally defining built-in provider.

Santiago, others, what do you think?

Thanks,
Pavel


On 21/05/2017 10:48, Christian Kaltepoth wrote:
Hi everyone,

I'm very happy to see that the issue of provider ordering is addressed in the upcoming JAX-RS release. Thanks a lot for your work on that.

I would like to point the EG to a discussion from one of the issues which was about whether the priority ordering should be used only for "custom providers" or for all providers (custom and built-in providers). See [1] for details. During the discussion Pavel mentioned that JAX-RS already mandates that custom providers are preferred over built-in providers. I didn't find this anywhere in the spec document, but maybe I just missed it.

The one thing that still makes me think that the priority ordering should be used for all providers is that the definition of "built-in provider" is a bit blurry. What is a built-in provider? What about providers which are deployed as app server modules and therefore are provided out of the box by the container? Are they built-in or custom providers? Perhaps this should simply be clarified in the spec?

I would be happy to hear about other opinions.

Christian













2017-05-19 14:08 GMT+02:00 Pavel Bucek <pavel.bucek@...>:

Dear experts,

there is couple of filed issues related to provider ordering, namely:

https://github.com/jax-rs/api/issues/538
https://github.com/jax-rs/api/issues/537

We already do have them implemented in the RI and we discovered that we can do similar things for almost all providers (including readers/writers, ..), which don't have already defined @Priority handling (filters and interceptors do have that already).

For these providers, lover priority value means higher priority. For example, if you have following ExceptionMappers:



then "MySecondExceptionMapper" will be invoked when "MyException" is thrown.


@Provider
@Priority(300)
public static class MyFirstExceptionMapper implements ExceptionMapper<MyException> {
    // ...}

@Provider
@Priority(100)
public static class MySecondExceptionMapper implements ExceptionMapper<MyException> {
    // ...

}

@Provider
@Priority(200)
public static class MyThirdExceptionMapper implements ExceptionMapper<MyException> {
    // ...

}

Do you have any comments or suggestions before we incorporate that change into the spec document?

Thanks and regards, Pavel




--




#544: Localization & BeanValidation

Pavel Bucek
 

Dear experts,

we are working on improving integration with BeanValidation [1], and seems like if we choose to address this issue, the change will be slightly bigger than I anticipated.

In short, the issue is about providing Locale based on incoming request to the BV runtime, which can then choose it to provide localized error message. Since there is no way how to get a list of supported locales, we'd need to introduce a provider, which would register supported locales:

public interface SupportedLocaleProvider {
    
    List<Locale> getSupportedLocales();
}

If the application contains @Provider annotated subclass of this interface and there is a BV message to be produced, implementation would be required to do something like:

SupportedLocaleProvider supportedLocaleProvider = ...;
javax.ws.rs.Request request = ...;

List<Locale> locales = supportedLocaleProvider.getSupportedLocales();

javax.ws.rs.Variant.VariantListBuilder variantListBuilder = Variant.VariantListBuilder.newInstance();

List<Variant> vs = variantListBuilder.languages(locales.toArray(new Locale[]{})).build();
Variant v = request.selectVariant(vs);

(+ null checks, etc). If selected variant exists, then "v.getLanguage()" would be used as a Locale passed to BV runtime.

Please let us know what do you think about proposed solution of linked issue.

Also, the introduced interface might have more uses that just this (maybe too specific) case - any brainstorming ideas to what it could be used are welcomed.

Thanks and regards, Pavel

[1] https://github.com/jax-rs/api/issues/544


Re: #544: Localization & BeanValidation

Sergey Beryozkin
 

Hi Pavel

Where would usually the code wishing to pass the Locale get the list of supported locales from, without even getting JAX-RS involved ?

If there was some well-known mechanism then the JAX-RS runtime would just use it as opposed to having to deal with a new provider...

Cheers, Sergey

On 22/05/17 17:46, Pavel Bucek wrote:

Dear experts,

we are working on improving integration with BeanValidation [1], and seems like if we choose to address this issue, the change will be slightly bigger than I anticipated.

In short, the issue is about providing Locale based on incoming request to the BV runtime, which can then choose it to provide localized error message. Since there is no way how to get a list of supported locales, we'd need to introduce a provider, which would register supported locales:

public interface SupportedLocaleProvider {
    
    List<Locale> getSupportedLocales();
}

If the application contains @Provider annotated subclass of this interface and there is a BV message to be produced, implementation would be required to do something like:

SupportedLocaleProvider supportedLocaleProvider = ...;
javax.ws.rs.Request request = ...;

List<Locale> locales = supportedLocaleProvider.getSupportedLocales();

javax.ws.rs.Variant.VariantListBuilder variantListBuilder = Variant.VariantListBuilder.newInstance();

List<Variant> vs = variantListBuilder.languages(locales.toArray(new Locale[]{})).build();
Variant v = request.selectVariant(vs);

(+ null checks, etc). If selected variant exists, then "v.getLanguage()" would be used as a Locale passed to BV runtime.

Please let us know what do you think about proposed solution of linked issue.

Also, the introduced interface might have more uses that just this (maybe too specific) case - any brainstorming ideas to what it could be used are welcomed.

Thanks and regards, Pavel

[1] https://github.com/jax-rs/api/issues/544



Re: ClientBuilder#executorService

 

Sounds good. On the other hand, we simply could say that a Java EE 8 Full Product MUST use the Managed Executor Service, other Java EE 8 Non-Full-Product Profiles SHOULD use the Managed Executor Service but MUST fallback to the Java SE 8 case if not supported.


Re: #544: Localization & BeanValidation

 

A JAX-RS application produces machine-readable information (XML, JSON, etc.), hence it does not support ANY human language by definition. BV provides machine-readable ConstraintViolations for this purpose; the message text plays no role in "real" REST, just like any message text of any Exception is of no interest to the end user. In a RESTful scenario, the translation of the BV exception is up to the front end designer, hence the CLIENT programmer (like MVC API, JSF, JavaFX) just as HE has to find nice and translated phrases for ANY OTHER exception already: Exceptions are INTERNAL and not to be forwarded 1:1 to the end user! So it is up to HIM to define the languages, while the text contained in a server's "error page" should stay in the same language always as it is NOT intended for the end user but for the programmer / administrator / devop! Hence how shall the author of a JAX-RS application ever decide which languages to support? JAX-RS does NOTHING with this information as you already said! In addition, what happens if the application programmer declares to define Chinese, but the BV implementation does not support Chinese? That won't work. I would rather say, this is solely a MVC feature and should not be defined by JAX-RS.


Re: Providers ordering

 

We should not mix up concerns here. @Priority should only beak tie. Whether or not to choose built-in vs. application-provided should be separately declarable. For example, in case A it might make sense that an appliation provides a simplistic fallback provider just in case the JAX-RS implementation does not provide support for a particular feature (like PDF support for example). On the other hand, the application might want to provide a superior, really-expensive, full-monty provider for PDF, which shall always override a possible existing built-in one. This example showcases that it MUST be up to the application programmer to declare precedence. But I won't use @Priority for that. It should be a separate annotation.


Re: Returning CompletionStage from the resource method

 

Won't that work what I proposed in the issue tracker:

Giving it a second thought I wonder whether Servlet's AsyncContext wouldn't provide what I proposed originally: A handle to the "original" executor (not in the sense of Executor class, but in the sense of separation of concerns).

The servlet could invoke JAX-RS using request.startAsync().start(r), where r first invokes JAX-RS, gets the resulting CompletionStage, and adds to that whenComplete((o,e) ->

{...; asyncContext.complete()}

);

I assume that AsyncContext.complete() will in turn send the HttpServletResponse using the Servlet's own thread pool.


Re: #544: Localization & BeanValidation

Gunnar Morling
 

Bean Validation spec lead here, thanks a lot for considering this feature!

> Since there is no way how to get a list of supported locales

Why is it that you need to get the list of locales? The Locale mechanism has fallback implemented which is used by Bean Validation. So e.g. say you have ValidationMessages.properties, ValidationMessages_en.properties and ValidationMessages_de.properties. If you request with "en" or "en_US", it'd take the second. If you request with "de", it'd take the last one. If you request with any other Locale, it'd take the first one. This all happens automatically.

> hence the CLIENT programmer (like MVC API, JSF, JavaFX) just as HE has to find nice and translated phrases for ANY OTHER exception already

I think there are good reasons for doing I18N on the server and on the client, it's not that one is always better than the other. E.g. doing it on the backend (i.e. JAX-RS) allows different clients to benefit from translations (say a JavaFX client as well as a web client using the same REST API). JSF btw. is integrating with Bean Validation already in the suggested way: it takes its current Locale and passes it to BV. I personally think JAX-RS could do it exactly in the same way: set up a Bean Validation message interpolator which takes the Locale from requests and passes this to calls of interpolate().

--Gunnar


Re: #544: Localization & BeanValidation

Santiago Pericas-Geertsen
 

Hi Gunnar,

 Other than message interpolation, is there any other scenario where locale information is important in BV? What comes to mind is a string that contains a representation of a locale-specific date format, for example. 

 Pavel and I were discussing locale support included but not limited to message interpolation. I think you’re right about the fallback for messages.

— Santiago

On May 24, 2017, at 11:54 AM, Gunnar Morling via Groups.Io <gunnar.morling@...> wrote:

Bean Validation spec lead here, thanks a lot for considering this feature!

> Since there is no way how to get a list of supported locales

Why is it that you need to get the list of locales? The Locale mechanism has fallback implemented which is used by Bean Validation. So e.g. say you have ValidationMessages.properties, ValidationMessages_en.properties and ValidationMessages_de.properties. If you request with "en" or "en_US", it'd take the second. If you request with "de", it'd take the last one. If you request with any other Locale, it'd take the first one. This all happens automatically.

> hence the CLIENT programmer (like MVC API, JSF, JavaFX) just as HE has to find nice and translated phrases for ANY OTHER exception already

I think there are good reasons for doing I18N on the server and on the client, it's not that one is always better than the other. E.g. doing it on the backend (i.e. JAX-RS) allows different clients to benefit from translations (say a JavaFX client as well as a web client using the same REST API). JSF btw. is integrating with Bean Validation already in the suggested way: it takes its current Locale and passes it to BV. I personally think JAX-RS could do it exactly in the same way: set up a Bean Validation message interpolator which takes the Locale from requests and passes this to calls of interpolate().

--Gunnar


Re: Providers ordering

Santiago Pericas-Geertsen
 

Hi Markus,

 The precedence of application-defined vs. built-in providers has already been established and cannot be changed at this point (but should be clarified better as mentioned by others). Conceptually, we have two ordered sets and we only consider the built-in set iff the application-defined set is empty after filtering.

 In my view, the introduction of @Priority should only apply to application-defined providers —which are in fact the ones that developers can add annotations to.

— Santiago
 

On May 23, 2017, at 1:59 PM, Markus KARG <markus@...> wrote:

We should not mix up concerns here. @Priority should only beak tie. Whether or not to choose built-in vs. application-provided should be separately declarable. For example, in case A it might make sense that an appliation provides a simplistic fallback provider just in case the JAX-RS implementation does not provide support for a particular feature (like PDF support for example). On the other hand, the application might want to provide a superior, really-expensive, full-monty provider for PDF, which shall always override a possible existing built-in one. This example showcases that it MUST be up to the application programmer to declare precedence. But I won't use @Priority for that. It should be a separate annotation.



Re: Providers ordering

 

I do not see that we cannot change this. If we decide that a new, optional annotation will modify the precedence, this would be perfectly backwards compatible, as all non-annotated code will still work correctly.


Re: #544: Localization & BeanValidation

 

If we want to support I18N on the JAX-RS server, it only would be straightforward to not only translation BV messages, but we also have to provide similar services to ALL providers, too. For example, why should it be correct that BV is supported, but custom exception providers are not, also custom MBWs (like for PDF) are not? I mean, content is content, and a service should be available to ALL sources of content, not just to BV.

 

From: jaxrs-spec@javaee.groups.io [mailto:jaxrs-spec@javaee.groups.io] On Behalf Of Gunnar Morling via Groups.Io
Sent: Mittwoch, 24. Mai 2017 17:54
To: jaxrs-spec@javaee.groups.io
Subject: Re: [jaxrs] #544: Localization & BeanValidation

 

Bean Validation spec lead here, thanks a lot for considering this feature!

> Since there is no way how to get a list of supported locales

Why is it that you need to get the list of locales? The Locale mechanism has fallback implemented which is used by Bean Validation. So e.g. say you have ValidationMessages.properties, ValidationMessages_en.properties and ValidationMessages_de.properties. If you request with "en" or "en_US", it'd take the second. If you request with "de", it'd take the last one. If you request with any other Locale, it'd take the first one. This all happens automatically.

> hence the CLIENT programmer (like MVC API, JSF, JavaFX) just as HE has to find nice and translated phrases for ANY OTHER exception already

I think there are good reasons for doing I18N on the server and on the client, it's not that one is always better than the other. E.g. doing it on the backend (i.e. JAX-RS) allows different clients to benefit from translations (say a JavaFX client as well as a web client using the same REST API). JSF btw. is integrating with Bean Validation already in the suggested way: it takes its current Locale and passes it to BV. I personally think JAX-RS could do it exactly in the same way: set up a Bean Validation message interpolator which takes the Locale from requests and passes this to calls of interpolate().

--Gunnar


Re: #544: Localization & BeanValidation

Pavel Bucek
 

We are still not exactly sure how / whether it should be put into place.

JAX-RS implementation has to have list of supported locales, because there is a defined algorithm, which chooses effective locale for the response. Note that Accept-Language is a list of languages, not a single one. Thus we'd need to somehow get a list of supported languages and invoke algorithm which computes effective language/Locale for the response entity.

If there would be BV API which could do that, it would be great (I mean - if there would be a way how to pass a list of possible locales and let BV runtime to do the rest).

Introducing new interface like SupportedLocaleProvider is viable option, but when I try to get into a "user role", I would expect something more from that - maybe adding Language header to the response. That is certainly possible, but again problematic, since there is no guarantee that the response entity will respect that (and JAX-RS would need to provide a way how to obtain computed Language).

Also, seems like one of the main motivations for doing this is to provide support for MVC - and if there is Provider priority, this could be handled on MVC side (including BV, if MVC chooses to use it)..

Regards,
Pavel


On 25/05/2017 08:56, Markus KARG wrote:

If we want to support I18N on the JAX-RS server, it only would be straightforward to not only translation BV messages, but we also have to provide similar services to ALL providers, too. For example, why should it be correct that BV is supported, but custom exception providers are not, also custom MBWs (like for PDF) are not? I mean, content is content, and a service should be available to ALL sources of content, not just to BV.

 

From: jaxrs-spec@javaee.groups.io [mailto:jaxrs-spec@javaee.groups.io] On Behalf Of Gunnar Morling via Groups.Io
Sent: Mittwoch, 24. Mai 2017 17:54
To: jaxrs-spec@javaee.groups.io
Subject: Re: [jaxrs] #544: Localization & BeanValidation

 

Bean Validation spec lead here, thanks a lot for considering this feature!

> Since there is no way how to get a list of supported locales

Why is it that you need to get the list of locales? The Locale mechanism has fallback implemented which is used by Bean Validation. So e.g. say you have ValidationMessages.properties, ValidationMessages_en.properties and ValidationMessages_de.properties. If you request with "en" or "en_US", it'd take the second. If you request with "de", it'd take the last one. If you request with any other Locale, it'd take the first one. This all happens automatically.

> hence the CLIENT programmer (like MVC API, JSF, JavaFX) just as HE has to find nice and translated phrases for ANY OTHER exception already

I think there are good reasons for doing I18N on the server and on the client, it's not that one is always better than the other. E.g. doing it on the backend (i.e. JAX-RS) allows different clients to benefit from translations (say a JavaFX client as well as a web client using the same REST API). JSF btw. is integrating with Bean Validation already in the suggested way: it takes its current Locale and passes it to BV. I personally think JAX-RS could do it exactly in the same way: set up a Bean Validation message interpolator which takes the Locale from requests and passes this to calls of interpolate().

--Gunnar



Re: #544: Localization & BeanValidation

Sergey Beryozkin
 

Can those providers which need it, ex, BV exception mappers, depend on the existing injectable Configuration interface to ensure the locales or other info can be accessed in a portable way ?

Cheers, Sergey