looker-open-source / sdk-codegen

One SDK to rule them all, and in the codegen bind them
MIT License
228 stars 192 forks source link

issue with io.ktor.client.engine.okhttp when using in Java Spring application #1324

Closed vinay-murkpudi closed 1 year ago

vinay-murkpudi commented 1 year ago

As guided in JavaMavenExample followed steps, able to communicate with Looker from a java file. When trying to run on Spring/SpringBoot application it's throwing below error.

java.lang.NoSuchFieldError: Companion   
    at io.ktor.client.engine.okhttp.OkHttpEngineKt.convertToOkHttpBody(OkHttpEngine.kt:203)
    at io.ktor.client.engine.okhttp.OkHttpEngineKt.convertToOkHttpRequest(OkHttpEngine.kt:192)

[06 Jun 2023 09:47:58,598][INFO ][ProfilerAspect,qtp436756852-20] - Going to call the LookerServiceEndpointImpl.get() method    
java.lang.NoClassDefFoundError: io/ktor/http/HttpMethod 
    at com.looker.rtl.HttpMethod.<clinit>(Transport.kt:94)
    at com.looker.sdk.LookerSDK.me(methods.kt:20791)
    at com.looker.sdk.LookerSDK.me$default(methods.kt:9112)
    at com.looker.sdk.LookerSDK.me(methods.kt)
    at com.contextweb.openapi.commons.processor.impl.LookerProcessorImpl.runCallMe(LookerProcessorImpl.java:56)

got above errors, when using some of the SDK methods

  sdk.ok(sdk.me()) 
  sdk.create_query
  sdk.run_query
<ktorVersion>1.5.0</ktorVersion>  // tried with many different version 1.4.2, 2.0.0 

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.cdimascio</groupId>
        <artifactId>java-dotenv</artifactId>
        <version>5.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.github.cdimascio</groupId>
        <artifactId>dotenv-kotlin</artifactId>
        <version>6.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-jackson</artifactId>
        <version>${ktorVersion}</version>
    </dependency>
    <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-okhttp</artifactId>
        <version>${ktorVersion}</version>
    </dependency>
    <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-json</artifactId>
        <version>${ktorVersion}</version>
    </dependency>
    <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-gson</artifactId>
        <version>${ktorVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.ini4j</groupId>
        <artifactId>ini4j</artifactId>
        <version>0.5.4</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlinx</groupId>
        <artifactId>kotlinx-coroutines-reactor</artifactId>
    </dependency>
    <dependency>
        <groupId>com.looker</groupId>
        <artifactId>kotlin-sdk</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/looker-kotlin-sdk.jar</systemPath>
    </dependency>
</dependencies>
vinay-murkpudi commented 1 year ago

found problem, and below is the fix:

This is an issue with SpringBoot, inside our spring project pom.xml

+- <artifactId>spring-boot-starter-parent</artifactId>
|  +- <artifactId>spring-boot-dependencies</artifactId>
|  |  +-  <okhttp3.version>3.14.9</okhttp3.version>

force a compatible okHTTP version in your project by adding the following dependency:

<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp</artifactId>
  <version>4.9.0</version>
</dependency>