Btw, Guillaume have written an excellent blog[1] to explain why we need OSGiLocator and how it works for SPI mechanism in OSGi container.

[1]http://gnodet.blogspot.com/2008/05/jee-specs-in-osgi.html

Freeman
On 2010-10-9, at 下午7:36, Bengt Rodehav wrote:

Willem,

That explains it. I did look through the code and noticed the service
locator but couldn't understand how it was used....

Thanks for your help Willem. I posted on the servicemix list to relieve you a bit since this problem should belong to Servicemix and not Camel (where I
originally posted). But of course, you were here as well :-)

/Bengt

2010/10/9 Willem Jiang <[email protected]>

Hi Bengt,

I checked the code of servicemix jsr303 bundle, it just include the
servicemix locator and doesn't use the service locator to find the provider
for you.

That explain why you get the below exception.


javax.validation.ValidationException: Unable to find a default provider

I will try to do a quick fix today.



On 10/9/10 6:41 AM, Bengt Rodehav 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



--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
       http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang



--
Freeman Fang

------------------------
blog: http://freemanfang.blogspot.com
twitter: http://twitter.com/freemanfang
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org

Reply via email to