I am using jersey for my project and tring to parse a URI from a string.
UriBuilder.fromUri(\"http://localhost:8000\").build();
The code is
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26</version>
<scope>test</scope>
</dependency>
I ran into issues with Java 8 and jersey-common 2.22.2 but 2.26 worked.
If you're using Maven, use the following dependency:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.22.2</version>
<scope>test</scope>
</dependency>
For Gradle, the following will work:
testCompile 'org.glassfish.jersey.core:jersey-common:2.22.2'
Developing against a Wildfly 10.1 runtime I didn't want to introduce Jersey into my builds. With Gradle I used
testRuntime "org.jboss.resteasy:resteasy-jaxrs:$versions.resteasy"
resteasy version is 3.0.19.Final. This jar contains
META-INF/services/javax.ws.rs.ext.RuntimeDelegate
with an entry
org.jboss.resteasy.spi.ResteasyProviderFactory
tl;dr if you're using jersey-client 1.x within an app that has a "provider" class also present, and you have rs-api-2.1.jar there, you need to add jersey-server 1.x or remove rs-api-2.1 if you happen to also have jsr311-api-1.1.1 present.
Appears this is what is happening:
Apparently jersey-client, when it is first coming up, tries to create a "mime map" of different mime types.
jersey-core 1.x ContextResolverFactory:
public void init(ProviderServices providersServices, InjectableProviderFactory ipf) {
Map<Type, Map<MediaType, List<ContextResolver>>> rs = new HashMap();
Set<ContextResolver> providers = providersServices.getProviders(ContextResolver.class);
Iterator i$ = providers.iterator();
while(i$.hasNext()) {
ContextResolver provider = (ContextResolver)i$.next();
List<MediaType> ms = MediaTypes.createMediaTypes((Produces)provider.getClass().getAnnotation(Produces.class));
...
So if there are any "providers" kicking around (ex: @Produces ({MediaType.WILDCARD})
), it tries to lookup their type and add it to the mime type lists. However, it does it the following:
if you have rs-api-2.1.jar:
private static RuntimeDelegate findDelegate() {
try {
Object delegate = FactoryFinder.find("javax.ws.rs.ext.RuntimeDelegate", "org.glassfish.jersey.internal.RuntimeDelegateImpl", RuntimeDelegate.class);
If you have the following other dependency, it appears to implement it slightly differently:
jsr311-api-1.1.1.jar:
private static RuntimeDelegate findDelegate() {
try {
Object delegate = FactoryFinder.find("javax.ws.rs.ext.RuntimeDelegate", "com.sun.ws.rs.ext.RuntimeDelegateImpl");
Jersey 1.x client happens to provide ./jersey-client-.19/com/sun/ws/rs/ext/RuntimeDelegateImpl.class
Whereas Jersey 1.x server provides:
./jersey-server-1.19/com/sun/jersey/server/impl/provider/RuntimeDelegateImpl.class
jersey 2.0 is "org.glassfish.jersey..." and provides "org.glassfish.jersey.internal.RuntimeDelegateImpl" (apparently sanely)
So it appears to me that rs-api-2.1
basically targets jersey 2.x by default. But happens to work with jersey-client 1.x if you also include jersey-server.
With jersey 2.x you don't need to include the "server to use the client" in such a weird way, seems to just work.
My hunch is either the API changed (you're not supposed to combine jersey 1.x with jsr-2? huh?), or maybe accidental flub, or bug, or poor design of jersey-client 1.x, who knows.
Adding things that happen to add "jersey 2.x" or "jersey-server 1.x" transitively also works.
These worked around the following runtime failure:
Caused by: java.lang.ExceptionInInitializerError: null
at com.sun.jersey.core.spi.factory.ContextResolverFactory.init(ContextResolverFactory.java:86)
at com.sun.jersey.api.client.Client.init(Client.java:340)
at com.sun.jersey.api.client.Client.access$000(Client.java:119)
at com.sun.jersey.api.client.Client$1.f(Client.java:192)
at com.sun.jersey.api.client.Client$1.f(Client.java:188)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:188)
at com.sun.jersey.api.client.Client.<init>(Client.java:171)
at redacted
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at org.familysearch.digitalarchive.aggregator.integration.ServiceAccountConfig$$EnhancerBySpringCGLIB$$a3409578.identityService(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 29 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:154)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:121)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:196)
at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
... 48 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:111)
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:209)
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:136)
... 51 common frames omitted
In my case the problem was for another Jar being used named: javax.ws.rs-api-2.0.jar
Removing that jar solved my problem.
The jar that I have used:
<include name="jersey-client-1.9.jar" />
<include name="jersey-core-1.9.jar" />
<include name="jersey-multipart-1.9.jar" />
compile 'org.springframework.boot:spring-boot-starter-jersey:1.2.0.RELEASE'
This worked for me!!!