Bengt,
Basically the problem is - JSR303 (also describes this) that it is up to the
container to
provide a Validator factory lookup, the bundle does this from the bundles
classpath.
In my test I "fudge" that by using a fragment, this attaches to the classpath
of the bundle doing the lookup.
I.e my suggestion is that you either provide a Service lookup factory method or
try a fragment.
provision(newBundle()
.add("META-INF/validation.xml",
BeanValidatorTest.class.getClassLoader().getResource("META-INF/validation.xml"))
.add("constraints-car.xml",
BeanValidatorTest.class.getClassLoader().getResource("constraints-car.xml"))
.set(Constants.BUNDLE_SYMBOLICNAME,
"validation-fragment")
.set(Constants.FRAGMENT_HOST,
"org.apache.servicemix.specs.jsr303-api-1.0.0")
.build(withBnd())),
Basically I built a new fragment bundle where I added the XML file needed so
that the Hibernate validator could do the lookup.
/je
On Oct 9, 2010, at 12:58 AM, Bengt Rodehav wrote:
> Thanks for your reply Johan.
>
> However, I'm not sure what you mean. Do you use the OSGi wrappers for
> hibernate-validator and jsr303 from ServiceMix like I do? Do you access the
> validation API from within OSGi like me or do you do it in a different way?
>
> /Bengt
>
> 2010/10/9 Johan Edstrom <[email protected]>
>
>> If you look under seijoed on github, I have a test there I started working
>> on where I attach the validation. XML as a fragment to hit the right
>> classloaders.
>>
>> I think that test is only missing student in a separate bundle both
>> validation and camel can see.
>>
>>
>> On Oct 8, 2010, at 15:41, Bengt Rodehav <[email protected]> wrote:
>>
>>> I'm using the servicemix packaging of hibernate-validator and jsr303:
>>>
>>> * <dependency>*
>>> * <groupId>org.apache.servicemix.specs</groupId>*
>>> *
>> <artifactId>org.apache.servicemix.specs.jsr303-api-1.0.0</artifactId>
>>> *
>>> * <version>1.5.0</version>*
>>> * </dependency>*
>>> *
>>> *
>>> * <dependency>*
>>> * <groupId>org.apache.servicemix.bundles</groupId>*
>>> *
>>>
>> <artifactId>org.apache.servicemix.bundles.hibernate-validator</artifactId>*
>>> * <version>4.1.0.Final_1</version>*
>>> * </dependency>*
>>>
>>> I use the validator "manually" (not automatically via JPA) as follows:
>>> *
>>> *
>>>
>>>> *public static Set<ConstraintViolation<?>> violations(Object theObject,
>>>> Class<?>... theGroups)*
>>>
>>> * throws ConstraintViolationException {*
>>>
>>> * /**
>>>
>>> * * Perform bean validation*
>>>
>>> * */*
>>>
>>> * ValidatorFactory factory =
>> Validation.buildDefaultValidatorFactory();
>>>> // Throws exception*
>>>
>>> * Validator validator = factory.getValidator();*
>>>
>>> * return (Set) validator.validate(theObject, theGroups);*
>>>
>>> * }*
>>>
>>>
>>> The line that creates the ValidatorFactory throws an exception when
>> called
>>> from wihin OSGi:
>>>
>>> javax.validation.ValidationException: Unable to find a default provider
>>>
>>> at
>>>>
>> javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
>>>
>>> at
>>>>
>> javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
>>>
>>> at validator.test1.impl.ServiceOne.createEntityOne(ServiceOne.java:17)
>>>
>>> at validator.test.itest.OsgiTest.createTest(OsgiTest.java:29)
>>>
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>
>>> at
>>>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>
>>> at
>>>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>
>>> at
>>>>
>> org.ops4j.pax.exam.junit.extender.impl.internal.CallableTestMethodImpl.injectContextAndInvoke(CallableTestMethodImpl.java:143)
>>>
>>> at
>>>>
>> org.ops4j.pax.exam.junit.extender.impl.internal.CallableTestMethodImpl.call(CallableTestMethodImpl.java:105)
>>>
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>
>>> at
>>>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>
>>> at
>>>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>
>>> at
>>>>
>> org.ops4j.pax.exam.rbc.internal.RemoteBundleContextImpl.remoteCall(RemoteBundleContextImpl.java:80)
>>>
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>
>>> at
>>>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>
>>> at
>>>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>
>>> at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
>>>
>>> at sun.rmi.transport.Transport$1.run(Transport.java:159)
>>>
>>> at java.security.AccessController.doPrivileged(Native Method)
>>>
>>> at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
>>>
>>> at
>> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
>>>
>>> at
>>>>
>> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
>>>
>>> at
>>>>
>> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
>>>
>>> at
>>>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>>
>>> at
>>>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>>
>>> at java.lang.Thread.run(Thread.java:619)
>>>
>>>
>>> When I run the same code outside of OSGi everything works. What am I
>> doing
>>> wrong?
>>>
>>> The test above used Pax-Exam with Felix 3.0.2 but it doesn't seem to
>> matter
>>> what OSGi container I use. I've tried different versions of Felix and
>>> Equinox but I get the same exception. I suspect I'm doing something wrong
>>> but I cannot see what. Can someone help me out?
>>>
>>> /Bengt
>>
Johan Edstrom
[email protected]
They that can give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety.
Benjamin Franklin, Historical Review of Pennsylvania, 1759