tarmogoyf
tarmogoyf

Reputation: 337

JettyReactiveClient NoClassDefFoundError in tests

Having an enhancement for logging convinience in WebClient we've added jetty reactive client:

  public Service () {
        SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
        HttpClient httpClient = new HttpClient(sslContextFactory) {
            @Override
            public Request newRequest(URI uri) {
                Request request = super.newRequest(uri);
                return enhance(request);
            }

        };

        this.webClient = WebClient.create().mutate()
                .clientConnector(new JettyClientHttpConnector(httpClient))
                .build();
    }


+--- org.eclipse.jetty:jetty-reactive-httpclient:3.0.4
|    +--- org.reactivestreams:reactive-streams:1.0.3
|    +--- org.eclipse.jetty:jetty-client:11.0.6 -> 9.4.44.v20210927
|    |    +--- org.eclipse.jetty:jetty-http:9.4.44.v20210927
|    |    |    +--- org.eclipse.jetty:jetty-util:9.4.44.v20210927
|    |    |    \--- org.eclipse.jetty:jetty-io:9.4.44.v20210927
|    |    |         \--- org.eclipse.jetty:jetty-util:9.4.44.v20210927
|    |    \--- org.eclipse.jetty:jetty-io:9.4.44.v20210927 (*)
|    \--- org.slf4j:slf4j-api:2.0.0-alpha1 -> 1.7.32

..and jetty dependency tree above showes all related jars. Build contains both 'implementation' and 'test-Implementation' of group: 'org.eclipse.jetty', name: 'jetty-reactive-client', version: "3.0.4" . It works fine but test with ok-http falls with :

org/eclipse/jetty/client/api/Request$Content
java.lang.NoClassDefFoundError: org/eclipse/jetty/client/ap/Request$Content

test :

    @SpringBootTest(classes = Service.class)
    @ActiveProfiles(profiles = {"test", "local"})
    class ServiceTest {
        @Autowired
        private Service service;
        @MockBean
        private LogHelper logHelper;
    
    
        private static MockWebServer mockBackEnd;
        private static ObjectMapper objectMapper;
}

( ommiting tests for brievety.) Any suggestions?

Upvotes: 1

Views: 4115

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49525

+--- org.eclipse.jetty:jetty-reactive-httpclient:3.0.4
|    +--- org.reactivestreams:reactive-streams:1.0.3
|    +--- org.eclipse.jetty:jetty-client:11.0.6 -> 9.4.44.v20210927

You have specified jetty-reactive-httpclient version 3.0.4

That requires Jetty 11 specific behaviors. You cannot downgrade Jetty arbitrarily like that.

As noted in the README for jetty-reactive-httpclient ...

https://github.com/jetty-project/jetty-reactive-httpclient/blob/1.1.x/README.md

Reactive Client Versions Java Min Version Jetty Min Version
1.1.x Java 8 Jetty 9.4.x
2.0.x Java 11 Jetty 10.0.x
3.0.x Java 11 Jetty 11.0.x

If you have to stick with Jetty 9 for whatever reason, then you should stick with the jetty-reactive-httpclient in the version range 1.1.x

Upvotes: 4

Related Questions