#community-help

Typesense Java Client Okhttp Version Conflict

TLDR Ashish faced an error with Typesense Java okhttp version. Kishore Nallan helped identify the conflict with Spring Boot version, which updated okhttp to a compatible version.

Powered by Struct AI
40
8mo
Solved
Join the chat
Apr 11, 2023 (8 months ago)
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
12:52 PM
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
    at (ApiCall.java:134)
    at org.typesense.api.Collections.create(Collections.java:16)
    at com.pchf.audit.Test.main(Test.java:36)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:52 PM
That's a old version. The latest is 0.1.0
12:52
Kishore Nallan
12:52 PM
Can you try with the above and let me know?
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
12:54 PM
https://github.com/typesense/typesense-java here version is 0.0.10 as latest
12:57
Ashish
12:57 PM
still same error with 0.1.0
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:06 PM
I've not updated the releases page yet. Can you publish an example code with the error? I have integration tests against the java client which works fine.
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:14 PM
it was plain simple following code
01:14
Ashish
01:14 PM
public class Test {

    public static void main(String[] args) {
        List<Node> nodes = new ArrayList<>();
        nodes.add(
                new Node(
                        "https",       // For Typesense Cloud use https
                        "",  // For Typesense Cloud use 
                        "443"        // For Typesense Cloud use 443
                )
        );
        Configuration configuration = new Configuration(nodes, Duration.ofSeconds(2),"xxxx");
        Client client = new Client(configuration);
        List<Field> fields = new ArrayList<>();
        fields.add(new Field().name("countryName").type(FieldTypes.STRING));
        fields.add(new Field().name("capital").type(FieldTypes.STRING));
        fields.add(new Field().name("gdp").type(FieldTypes.INT32).facet(true).sort(true));

        CollectionSchema collectionSchema = new CollectionSchema();
        collectionSchema.name("Countries").fields(fields).defaultSortingField("gdp");

        try {
            client.collections().create(collectionSchema);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
01:18
Ashish
01:18 PM
following is the error
01:18
Ashish
01:18 PM
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
    at (ApiCall.java:134)
    at org.typesense.api.Collections.create(Collections.java:16)
    at com.pchf.audit.Test.main(Test.java:36)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:18 PM
Works perfectly fine for me
01:19
Kishore Nallan
01:19 PM
What version of Typesense server are you using?
01:19
Kishore Nallan
01:19 PM
Do you have another okhttp client dependency from another dep / directly?
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:20 PM
Typesense v0.24.1
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:21 PM
I think another dependency is pulling a different version of okhttp as discussed here: https://github.com/auth0/auth0-java/issues/324
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:21 PM
nope
Image 1 for nope
01:22
Ashish
01:22 PM
i dont have any other version of okhttp
01:22
Ashish
01:22 PM
[INFO] com.pchf:audit:jar:1.0-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.5.12:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.5.12:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.5.12:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.12:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  \- org.springframework:spring-core:jar:5.3.18:compile
[INFO] |     \- org.springframework:spring-jcl:jar:5.3.18:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.5.12:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.5.12:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-actuator:jar:2.5.12:compile
[INFO] |  |  \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.6:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.7.10:compile
[INFO] |     +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.5.12:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.5.12:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.6:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.5.12:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.60:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.60:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.60:compile
[INFO] |  +- org.springframework:spring-web:jar:5.3.18:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.3.18:compile
[INFO] |     \- org.springframework:spring-aop:jar:5.3.18:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.24:provided
[INFO] +- org.springframework.data:spring-data-mongodb:jar:3.3.5:compile
[INFO] |  +- org.springframework:spring-tx:jar:5.3.18:compile
[INFO] |  +- org.springframework:spring-context:jar:5.3.18:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.3.18:compile
[INFO] |  +- org.springframework:spring-expression:jar:5.3.18:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:2.5.10:compile
[INFO] |  +- org.mongodb:mongodb-driver-core:jar:4.2.3:compile
[INFO] |  |  \- org.mongodb:bson:jar:4.2.3:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] +- org.springframework.kafka:spring-kafka:jar:2.7.12:compile
[INFO] |  +- org.springframework:spring-messaging:jar:5.3.18:compile
[INFO] |  +- org.springframework.retry:spring-retry:jar:1.3.2:compile
[INFO] |  +- org.apache.kafka:kafka-clients:jar:2.7.2:compile
[INFO] |  |  +- com.github.luben:zstd-jni:jar:1.4.5-6:compile
[INFO] |  |  +- org.lz4:lz4-java:jar:1.7.1:compile
[INFO] |  |  \- org.xerial.snappy:snappy-java:jar:1.1.7.7:compile
[INFO] |  \- com.google.code.findbugs:jsr305:jar:3.0.2:runtime
[INFO] +- org.typesense:typesense-java:jar:0.1.0:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:runtime
[INFO] |  |  \- javax.activation:javax.activation-api:jar:1.2.0:runtime
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.6.1:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.6:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.12.6:compile
[INFO] |  +- io.swagger.core.v3:swagger-annotations:jar:2.0.0:runtime
[INFO] |  \- com.squareup.okhttp3:okhttp:jar:3.14.9:runtime
[INFO] |     \- com.squareup.okio:okio:jar:1.17.2:runtime
[INFO] +- com.google.code.gson:gson:jar:2.6.2:compile
[INFO] \- junit:junit:jar:3.8.1:test
01:23
Ashish
01:23 PM
find my entire dependency tree
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:23 PM
Typesense build.gradle has
implementation "com.squareup.okhttp3:okhttp:4.9.1"

I wonder why the dep tree shows 3.x
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:24 PM
can you check the dependency uploaded in repo
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:26 PM
For e..g see the dep tree of my example project:

+--- org.typesense:typesense-java:0.1.0
|    +--- javax.xml.bind:jaxb-api:2.3.1
|    |    \--- javax.activation:javax.activation-api:1.2.0
|    +--- com.fasterxml.jackson.core:jackson-databind:2.14.1
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.14.1
|    |    |    \--- com.fasterxml.jackson:jackson-bom:2.14.1
|    |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.14.1 (c)
|    |    |         +--- com.fasterxml.jackson.core:jackson-core:2.14.1 (c)
|    |    |         \--- com.fasterxml.jackson.core:jackson-databind:2.14.1 (c)
|    |    +--- com.fasterxml.jackson.core:jackson-core:2.14.1
|    |    |    \--- com.fasterxml.jackson:jackson-bom:2.14.1 (*)
|    |    \--- com.fasterxml.jackson:jackson-bom:2.14.1 (*)
|    +--- io.swagger.core.v3:swagger-annotations:2.0.0
|    +--- org.slf4j:slf4j-api:2.0.5
|    \--- com.squareup.okhttp3:okhttp:4.9.1
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:27 PM
try with maven once
01:28
Kishore Nallan
01:28 PM
Even for 0.0.10 the okhttp3 version uploaded is 4.x
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:30 PM
Image 1 for
01:33
Ashish
01:33 PM
even after removing the dependency from my local .m2 cache its downloading same version
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:34 PM
We have had many people using 0.0.10 for a while now, so this seems like an environment issue to me.
01:35
Kishore Nallan
01:35 PM
For the record, we have never used okhttp 3.x ever.
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
01:38 PM
tried in my friends new repo its same 3.x version
01:40
Ashish
01:40 PM
can you try in some other environment or server
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:41 PM
Can you post a full sample project? I can check it out and try it on a new computer.
01:42
Kishore Nallan
01:42 PM
Especially if you are using maven. I only use Gradle.
Apr 12, 2023 (8 months ago)
Ashish
Photo of md5-ac644febab046dd06d5444364892d361
Ashish
06:23 AM
got the issue so currently in my pom.xml i am using following parent version
06:23
Ashish
06:23 AM
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.12</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
06:23
Ashish
06:23 AM
its picking okhttp from this version
06:23
Ashish
06:23 AM
by upgrading this version okhttp version is also being upgraded
06:24
Ashish
06:24 AM
find my pom.xml
06:24
Ashish
06:24 AM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=""
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.12</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.pchf</groupId>
    <artifactId>audit</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>audit</name>

    <properties>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>3.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.typesense</groupId>
            <artifactId>typesense-java</artifactId>
            <version>0.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:37 AM
I see, yeah you have to fix the version

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3011 threads (79% resolved)

Join Our Community