[bv-dev] [BVAL-251] Improve Bean Validation support for modularized environments

Hardy Ferentschik hardy at hibernate.org
Fri Apr 13 07:37:56 EDT 2012


Hi all,

I just wanted to revive this thread dealing with Bean Validation and OSGi - BVAL-251 [1]

I think there are several things we are discussing:

1. Adding OSGi meta information to META-INF (aka which packages are imported and exported)
2. Exporting ValidatorFactory (and Validator) as OSGi services 
3. Providing additional extension points to allow OSGi for example to e.g. register
    custom constraint implementations

Regarding #1 we have so far been talking about just adding the OSGi header information to 
the BV API jar. Given that it just exports its API and has  no other dependencies that should be fine.
I think most agree that we can just add this information.

We never discussed, though, whether it should be a requirement for BV implementations to also add this
meta information? Is this taking a step too far?

Regarding #2 AFAIU the biggest problem is that it requires some OSGi specific code
in the BV API jar. Basically, BV implementations would need to be able to register their implementation
and BV would need to then make them available. This enabling code could can either be in the API jar itself or 
be made available in a separate jar. Gunnar has already summed this up in a previous mail. 
There is also a very recent discussion on HV-570 [2] about this.

I think the first step is to decide whether BV should really specify this.  For me the only sensible approach would be
an additional ODGI enabling jar. Is this something the BV spec can and should address and provide? Or do we
leave this up to the BV implementations. 

Emmanuel, you mentioned that we might align CDI in regards to OSGi. Are there any news there?

--Hardy





[1] https://hibernate.onjira.com/browse/BVAL-251
[2] https://hibernate.onjira.com/browse/HV-570


On Jan 9, 2012, at 4:02 PM, Jagadish Prasath Ramu wrote:

> Hi Emmanuel, Kevin :
> 
> Please find a reference on defining OSGi header and version numbers in
> the manifest file of api .jars. 
> 
> https://wikis.oracle.com/display/GlassFish/Maven+Versioning+Rules
> 
> Thanks,
> -Jagadish
> 
> On Mon, 2012-01-02 at 17:47 +0100, Emmanuel Bernard wrote:
>> Sorry for the long slack off.
>> 
>> 
>> OSGi is generally not my field but here are a few comments on what
>> Gunnar and Kevin have said:
>> 
>> 
>> - we can definitely experiment with Hibernate Validator and offer some
>> OOTB support for OSGi and other modularity solutions.
>> - we can consider the API JAR provided by the RI team and add the OSGi
>> headers if that's the correct solution but I don't feel like adding
>> them in the spec document proper
>> - we should align with what the CDI group does wrt OSGi headers
>> especially since CDI will be an optional dependency of BV
>> - can someone flesh out a more concrete proposal and push it
>> to http://beanvalidation.org/proposals/BVAL-251 ? Kevin do you want to
>> take the lead?
>> 
>> 
>> Emmanuel
>> 
>> On 3 nov. 2011, at 12:13, Kevin Pollet wrote:
>> 
>>> Hi,
>>> 
>>> On 1 November 2011 15:36, Emmanuel Bernard <emmanuel at hibernate.org>
>>> wrote:
>>>        Two points. 
>>> 
>>> 
>>>        CDI will be a dependency of Bean Validation (see topic on
>>>        injection). 
>>> 
>>> 
>>>        What does not work today in the following code in a modular
>>>        environment?
>>> 
>>> 
>>>        Validation 
>>>            .byDefaultProvider() 
>>>                .providerResolver( myOSGiResolver ) 
>>>             .configure() 
>>>             .buildValidatorFactory(); 
>>> 
>>> 
>>> The dependency to CDI will be optional, right? 
>>> 
>>> 
>>> In this case that dependency should be declared as optional in the
>>> OSGi headers. By doing that, if CDI cannot be used in an OSGI
>>> environment this will not affect BV.
>>> 
>>> 
>>> AFAIK, the following things doesn't work with that approach (not
>>> exhaustive):
>>> 
>>> 
>>> * loading of validation and constraint mapping files
>>> * loading of ValidationMessages.properties
>>> * I've not tested it but I think the loading of the class specified
>>> in the xml files doesn't work
>>> 
>>> 
>>> The problem here is that the implementation use the TCCL or the
>>> classloader of one of its class to load resources or classes. That
>>> approach cannot work in a modular environment. For example in OSGi
>>> the TCCL is not set to the right classloader and the implementation
>>> classloader can't access another bundle resources or classes (if
>>> they are not imported).
>>> 
>>> 
>>> IMHO, BV should specify a mechanism used by implementations to load
>>> resources and classes. The default implementation should work out of
>>> the box in Java EE and this mechanism can be customized by users
>>> which want to work in a modular environement. 
>>> 
>>> 
>>> Maybe an implementation of such mechanism can be provided for OSGi
>>> or JBoss modules by the RI?
>>> 
>>> 
>>> WDYT?
>>> 
>>> 
>>> --Kevin
>>> 
>>> 
>>>        On 31 oct. 2011, at 17:13, Gunnar Morling
>>>        <gunnar.morling at googlemail.com> wrote:
>>> 
>>> 
>>> 
>>>>> So all JARs must be OSGi-ified before they can be used?
>>>>> [...]
>>>>> I'm asking because declaring dependencies means that all
>>>>> dependent JSRs (and
>>>>> the JDK) will need to be OSGi-ified as well. I'd rather
>>>>> see that coordinated
>>>>> by the Java EE expert group.
>>>> 
>>>> In case of BV we would have to add the OSGi headers to the
>>>> JAR to make
>>>> it usable under OSGi. As Kevin says there is no relation
>>>> to the JDK
>>>> here, and AFAIK the BV API doesn't have any other
>>>> additional
>>>> dependencies. So adding these headers wouldn't be a
>>>> problem IMO (each
>>>> OSGi bundle is still a standard JAR which can be used in
>>>> any other
>>>> environment).
>>>> 
>>>> Another thing is the bootstrapping, i.e. how BV
>>>> implementations are
>>>> found. Searching for resources such as
>>>> META-INF/services/j.v.ValidationProvider doesn't work in
>>>> OSGi (I don't
>>>> know about JBoss modules). This kind of things is in OSGi
>>>> typically
>>>> solved using services, that means in the BV bundle would
>>>> be the
>>>> definition of a service interface (we already have this
>>>> with
>>>> ValidationProvider) while BV providers would register
>>>> implementations
>>>> of this service. In the BV API Jar we still would need
>>>> some glue
>>>> code/meta-data to obtain references to these
>>>> implementations.
>>>> 
>>>> Personally I feel adding the headers would be ok for the
>>>> "official"
>>>> API Jar as it's rather un-intrusive, but the bootstrapping
>>>> stuff might
>>>> be too much. One idea might be to provide separate
>>>> "enabler" modules
>>>> for the different module systems around, e.g. there could
>>>> be a
>>>> bv-osgi.jar which takes the raw API jar and makes it
>>>> usable under OSGi
>>>> (it could also offer j.v.Validator as OSGi service etc.).
>>>> 
>>>> --Gunnar
>>>> 
>>>> 2011/10/28 Emmanuel Bernard <emmanuel at hibernate.org>:
>>>>> So all JARs must be OSGi-ified before they can be used?
>>>>> Is there any way to
>>>>> keep this information outside? Do you know of any other
>>>>> JSR published JAR
>>>>> that also expose its OSGi headers?
>>>>> I'm asking because declaring dependencies means that all
>>>>> dependent JSRs (and
>>>>> the JDK) will need to be OSGi-ified as well. I'd rather
>>>>> see that coordinated
>>>>> by the Java EE expert group. There is also the problem
>>>>> of supporting them
>>>>> forever(tm).
>>>>> On 27 oct. 2011, at 22:52, Kevin Pollet wrote:
>>>>> 
>>>>> Hi experts,
>>>>> IMHO, making Bean Validation ready for the modular world
>>>>> is a great thing!
>>>>> A first step might be to provide the module meta-datas
>>>>> (OSGi headers,
>>>>> …). For OSGi, those meta-datas can be added to the jar
>>>>> Manifest within the
>>>>> maven build with the maven-bundle-plugin. The advantage
>>>>> is that the api can
>>>>> be deployed in an OSGi container out of the box. For
>>>>> JBoss Modules the
>>>>> descriptor reside alongside its content but we can
>>>>> provide it.
>>>>> WDYT?
>>>>> --Kevin




More information about the beanvalidation-dev mailing list