Error while using jersey-client - No generator was provided

32 Views Asked by At

This is the error code which I am getting, Looks like some conflicting jar is throwing the error but not sure what is the reason or which conflict version is giving the error. Attaching the dependency tree along with.

java.lang.IllegalStateException: No generator was provided and there is no default generator registered
    at shaded.xyz.org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:285)
    at shaded.xyz.org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:245)
    at shaded.xyz.org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.createLocator(AbstractHk2InjectionManager.java:90)
    at shaded.xyz.org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.<init>(AbstractHk2InjectionManager.java:62)
    at shaded.xyz.org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.<init>(ImmediateHk2InjectionManager.java:38)
    at shaded.xyz.org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory$Hk2InjectionManagerStrategy$1.createInjectionManager(Hk2InjectionManagerFactory.java:55)
    at shaded.xyz.org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory.create(Hk2InjectionManagerFactory.java:73)
    at shaded.xyz.org.glassfish.jersey.internal.inject.InjectionManagerFactory.create(InjectionManagerFactory.java:32)
    at shaded.xyz.org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:44)
    at shaded.xyz.org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:413)
    at shaded.xyz.org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
    at shaded.xyz.org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:820)
    at shaded.xyz.org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:176)
    at shaded.xyz.org.glassfish.jersey.client.ClientRequest.getInjectionManager(ClientRequest.java:567)
    at shaded.xyz.org.glassfish.jersey.client.JerseyWebTarget.onBuilder(JerseyWebTarget.java:371)
    at shaded.xyz.org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:199)
    at shaded.xyz.org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:38)
    at com.xyz.ec.ac.rest.RestClient.getBuilder(RestClient.scala:60)

This is the code which is giving the error at this point RestClient.getBuilder(RestClient.scala:60)

import org.slf4j.{Logger, LoggerFactory}

import java.util.concurrent.TimeUnit
import javax.ws.rs.client.{Client, ClientBuilder, Entity, Invocation}
import javax.ws.rs.core.{Feature, MediaType, Response}
import scala.util.{Failure, Success, Try}

abstract class RestClient(conf: RestConf) {

  // some ac services require this property
  val METHOD_OVERRIDE = "X-HTTP-Method-Override"
  val logger: Logger = LoggerFactory.getLogger(getClass)
  val client: Client = createClient

  def postWithRetries(url: String, body: String): Response = {
    retry(conf.retries)(post(url, body))
  }

  def post(url: String,
           body: String,
           headers: Map[String, String]): Response = {

    val builder = getBuilder(url, headers)
    val entity = Entity.entity(body, MediaType.APPLICATION_JSON_TYPE)
    builder.post(entity, classOf[Response])
  }

  def post(url: String,
           body: String): Response = {
    post(url, body, Map.empty)
  }

  def getWithRetries(url: String, headers: Map[String, String]): Response = {
    retry(conf.retries)(get(url, headers))
  }

  def get(url: String): Response = {
    get(url, Map.empty)
  }

  def get(url: String,
          headers: Map[String, String]): Response = {

    val builder = getBuilder(url, headers)
    builder.get(classOf[Response])
  }

  private def getBuilder(url: String, headers: Map[String, String]): Invocation.Builder = {

    val feature = getFeature

    if (feature.isDefined){
      client.register(feature.get, -1)
    }

    val builder = client
      .target(url)
      .request()
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header("Content-Type", MediaType.APPLICATION_JSON_TYPE)

    headers.foreach(x => builder.header(x._1, x._2))

    builder
  }

  def close(): Unit ={
    client.close()
  }

  @annotation.tailrec
  private def retry[T](n: Int)(f: => T): T = {
    Try(f) match {
      case Success(x) => x
      case _ if n > 1 =>
        val m = n - 1
        logger.warn(s"failed to make request. attempting request number ${conf.retries - m}")
        retry(m)(f)
      case Failure(e) =>
        logger.error(s"failed to make request after ${conf.retries} attempts", e)
        throw e
    }
  }

  private def createClient: Client = {
    ClientBuilder.newBuilder()
      .readTimeout(conf.readTimeout, TimeUnit.MILLISECONDS)
      .connectTimeout(conf.connectionTimeout, TimeUnit.MILLISECONDS)
      .build()
  }

  def getFeature: Option[Feature]
}

The above code is giving issue.Below is dependency tree

    [INFO] +- com.google.inject:guice:jar:7.0.0:compile
    [INFO] |  +- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile
    [INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
    [INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.1.1:compile
    [INFO] +- net.codingwell:scala-guice_2.11:jar:4.2.11:compile
    [INFO] +- org.glassfish.hk2:hk2-utils:jar:2.6.1:compile
    [INFO] |  \- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:compile
    [INFO] +- org.glassfish.hk2:hk2-locator:jar:2.6.1:compile
    [INFO] |  +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.6.1:compile
    [INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.4:compile
    [INFO] |  \- org.javassist:javassist:jar:3.22.0-CR2:compile
    [INFO] +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.25.1:compile
    [INFO] +- org.glassfish.jersey.inject:jersey-hk2:jar:2.41:compile
    [INFO] |  \- org.glassfish.jersey.core:jersey-common:jar:2.41:compile
    [INFO] |     \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
    [INFO] +- org.glassfish.hk2:hk2-api:jar:2.6.1:compile
    [INFO] +- org.glassfish.jersey.security:oauth1-client:jar:2.36:compile
    [INFO] |  \- org.glassfish.jersey.security:oauth1-signature:jar:2.36:compile
    [INFO] +- com.typesafe:config:jar:1.4.0:compile
    [INFO] +- org.glassfish.jersey.core:jersey-client:jar:2.4.1:compile
    [INFO] |  \- org.glassfish.hk2.external:javax.inject:jar:2.2.0-b21:compile
    [INFO] +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.7.3:compile
    [INFO] |  +- org.apache.hadoop:hadoop-yarn-common:jar:2.7.3:compile
    [INFO] |  |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.7.3:compile
    [INFO] |  |  +- javax.xml.bind:jaxb-api:jar:2.2.2:compile
    [INFO] |  |  |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
    [INFO] |  |  |  \- javax.activation:activation:jar:1.1:compile
    [INFO] |  |  +- org.apache.commons:commons-compress:jar:1.4.1:compile
    [INFO] |  |  |  \- org.tukaani:xz:jar:1.0:compile
    [INFO] |  |  +- commons-lang:commons-lang:jar:2.6:compile
    [INFO] |  |  +- javax.servlet:servlet-api:jar:2.5:compile
    [INFO] |  |  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
    [INFO] |  |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
    [INFO] |  |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
    [INFO] |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.13:compile
    [INFO] |  |  +- org.codehaus.jackson:jackson-xc:jar:1.9.13:compile
    [INFO] |  |  +- commons-cli:commons-cli:jar:1.2:compile
    [INFO] |  |  +- commons-io:commons-io:jar:2.4:compile
    [INFO] |  |  +- com.sun.jersey:jersey-server:jar:1.9:compile
    [INFO] |  |  |  \- asm:asm:jar:3.1:compile
    [INFO] |  |  \- com.sun.jersey:jersey-json:jar:1.9:compile
    [INFO] |  |     +- org.codehaus.jettison:jettison:jar:1.1:compile
    [INFO] |  |     \- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
0

There are 0 best solutions below