obs-websocket-community-projects/obs-websocket-java

Maven artifact issue with `jetty-client`

dehidehidehi opened this issue · 4 comments

Hey there, had an issue starting up a Spring Boot 3 application using the obs websocket library.

Describe the bug

Only adding this to my maven pom.xml generates the following issue in Spring Boot 3.0.0:
Adding this to my pom:

        <dependency>
            <groupId>io.obs-websocket.community</groupId>
            <artifactId>client</artifactId>
            <version>2.0.0</version>
        </dependency>

Spring boot will complain at application startup:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.eclipse.jetty.websocket.client.DefaultHttpClientProvider.newHttpClient(DefaultHttpClientProvider.java:52)

The following method did not exist:

    'void org.eclipse.jetty.client.HttpClient.<init>(org.eclipse.jetty.util.ssl.SslContextFactory)'

The calling method's class, org.eclipse.jetty.websocket.client.DefaultHttpClientProvider, was loaded from the following location:

    jar:file:/home/dehi/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.4.49.v20220914/websocket-client-9.4.49.v20220914.jar!/org/eclipse/jetty/websocket/client/DefaultHttpClientProvider.class

The called method's class, org.eclipse.jetty.client.HttpClient, is available from the following locations:

    jar:file:/home/dehi/.m2/repository/org/eclipse/jetty/jetty-client/11.0.13/jetty-client-11.0.13.jar!/org/eclipse/jetty/client/HttpClient.class

The called method's class hierarchy was loaded from the following locations:

    org.eclipse.jetty.client.HttpClient: file:/home/dehi/.m2/repository/org/eclipse/jetty/jetty-client/11.0.13/jetty-client-11.0.13.jar
    org.eclipse.jetty.util.component.ContainerLifeCycle: file:/home/dehi/.m2/repository/org/eclipse/jetty/jetty-util/11.0.13/jetty-util-11.0.13.jar
    org.eclipse.jetty.util.component.AbstractLifeCycle: file:/home/dehi/.m2/repository/org/eclipse/jetty/jetty-util/11.0.13/jetty-util-11.0.13.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.eclipse.jetty.websocket.client.DefaultHttpClientProvider and org.eclipse.jetty.client.HttpClient

Code Sample

In a class annotated with Spring's @Configuration

    @Bean
    OBSRemoteController obsRemoteController() {
        return OBSRemoteController.builder()
                                  .host(host)
                                  .port(port)
                                  .password(password)
                                  .lifecycle()
                                  .onReady(this::onReady) // do when boot
                                  .and()
                                  .build();
    }

Expected behavior

Application should start successfully.

Resolution

Explicitely including a jetty-client dependency to avoid dependency clashes fixed it for me.

        <dependency>
            <groupId>io.obs-websocket.community</groupId>
            <artifactId>client</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-client</artifactId>
            <version>9.4.50.v20221201</version>
        </dependency>

image

Turns out this didn't fix the issue at all, and is causing a runtime error when establishing a connection to OBS.
This version of jetty-client is trying to instanciate an interface directly.

I've managed to establish a connection to OBS, but the solution was to override all jetty dependencies in my pom.xml:

        <dependency>
            <groupId>io.obs-websocket.community</groupId>
            <artifactId>client</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-client</artifactId>
            <version>9.4.49.v20220914</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-io</artifactId>
            <version>9.4.49.v20220914</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-http</artifactId>
            <version>9.4.49.v20220914</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>9.4.49.v20220914</version>
        </dependency>

Yep, that will be fixed in the next release. In the meantime, you can use the snapshot version.

api libs.websocket

Snapshot Maven repo is https://s01.oss.sonatype.org/content/repositories/snapshots and latest snapshot version is 2.0.1. Comes directly from develop branch of this repo