org.glassfish.jersey.internal.RuntimeDelegateImpl NOT FOUND

后端 未结 6 2072
暗喜
暗喜 2020-12-29 20:20

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

6条回答
  •  我在风中等你
    2020-12-29 21:04

    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>> rs = new HashMap();
        Set providers = providersServices.getProviders(ContextResolver.class);
        Iterator i$ = providers.iterator();
    
        while(i$.hasNext()) {
          ContextResolver provider = (ContextResolver)i$.next();
          List 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.(Client.java:188)
        at com.sun.jersey.api.client.Client.(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()
        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.(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
    

提交回复
热议问题