java - Getting Jersey 1.x and 2.x to coexist -
i've got dropwizard project (using jersey 2.x) need use library has dependency on jersey-client 1.x , i'm having trouble getting both coexist on classpath. looks happening hk2 finding implements providers javax.ws.rs.* , attempting instantiate them. when it's class jersey 1.x, dependency injection needs isn't there , end lots of errors like:
caused by: java.lang.illegalargumentexception: multipartconfig instance expected not present. have registered multipartconfigprovider class? @ com.sun.jersey.multipart.impl.multipartreaderclientside.<init>(multipartreaderclientside.java:107) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:408) @ org.glassfish.hk2.utilities.reflection.reflectionhelper.makeme(reflectionhelper.java:1107) @ org.jvnet.hk2.internal.clazzcreator.createme(clazzcreator.java:274) @ org.jvnet.hk2.internal.clazzcreator.create(clazzcreator.java:368)
is there way jersey 2.x/hk2 ignore in com.sun.jersey.* package space?
it looks default behavior org.glassfish.jersey.internal.servicefinder find service implementations via meta-inf/services on classpath. however, has setiteratorprovider method allows set alternate serviceiteratorprovider implementation. able solve problem giving implementation filters out class names com.sun.jersey.*
public class jersey2serviceiteratorprovider extends servicefinder.serviceiteratorprovider { servicefinder.defaultserviceiteratorprovider delegate = new servicefinder.defaultserviceiteratorprovider(); @override public <t> iterator<t> createiterator(class<t> service, string servicename, classloader loader, boolean ignoreonclassnotfound) { return delegate.createiterator(service, servicename, loader, ignoreonclassnotfound); } @override public <t> iterator<class<t>> createclassiterator(class<t> service, string servicename, classloader loader, boolean ignoreonclassnotfound) { final iterator<class<t>> delegateclassiterator = delegate.createclassiterator(service, servicename, loader, ignoreonclassnotfound); return iterators.filter(delegateclassiterator, input -> !input.tostring().startswith("class com.sun.jersey")); } }
Comments
Post a Comment