eclipse-ee4j / eclipse-ee4j/jersey
ComponentProvider ... Contract type not supported
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I am currently trying to integrate Jersey (version 2.22.2) into a OSGi runtime based on Apache Felix. To be able to use Declarative Service references (@Reference) in my resources I need to control the resource lifecycle with OSGi instead of Jersey.
[Chapter 23.3\. Custom Life Cycle Management](https://jersey.java.net/documentation/latest/ioc.html#d0e17152) of the Jersey User Guide illustrates how the resource lifecycle can be taken control over by implementing the org.glassfish.jersey.server.spi.ComponentProvider SPI.
I did just that, but when I try to register my ComponentProvider implementation I get the following error:
> Contract interface org.glassfish.jersey.server.spi.ComponentProvider can not be registered for component class de.jena.servicehub.rs.OsgiResourceProvider: Contract type not supported.
I am registering all providers and and resources programmatically on a ResourceConfig instance which I use to initialize a ServletContainer instance. I have turned off classpath scanning and service discovery on my ResourceConfig.
```
.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
```
I scoured the (2.22.2 and current) Jersey source code for the source of this error and ended up at the org.glassfish.jersey.internal.inject.Providers class's isSupportedContract(Class) method. The method checks whether the contract class of the class to be registered (i.e. the implemented interface) is annotated with @Contract or if it is on one of two white lists. Neither is true for the ComponentProvider interface. Thus Jersey refuses to register my implementation.
I consider this a bug. ComponentProvider should be on the JAX_RS_PROVIDER_INTERFACE_WHITELIST.
#### Environment
OSGi R5 (Apache Felix)
#### Affected Versions
[2.22.2]
Contributor guide
Assessment
This issue has not been assessed yet.