2

I'm writing some integration tests for a Spring Boot application written in Kotlin. To stub some HTTP requests, I'm using WireMock via spring-cloud-contract-wiremock as dependency.

Some anonymized sample code from an integration test:

@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureWireMock
class MyIntegrationTest { 

    @Test
    fun `some test`() {
        mockEndpoint("url", 500, someResponseBodyInJson)

        mockMvc.perform(
            MockMvcRequestBuilders
                .post("url")
                .contentType(MediaType.APPLICATION_JSON.toString())
                .content(someRequestBodyInJson)
        )
            .andExpect(MockMvcResultMatchers.status().isInternalServerError)
    }

    private fun mockEndpoint(url: String, responseCode: Int, responseBody: String) {
        stubFor(
            WireMock.post(url).willReturn(
                WireMock.aResponse()
                    .withStatus(responseCode)
                    .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString())
                    .withBody(responseBody)
            )
        )
    }

}

While running these tests on my local machine, everything is working fine. On the CI/CD environment it's failing though with the following error:

java.lang.IllegalStateException: No Server ALPNProcessors!
at wiremock.org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory.<init>(ALPNServerConnectionFactory.java:52)

I did some searching and figured out is has to do with Jetty missing some things on the class path. I added the following dependency testImplementation("org.eclipse.jetty:jetty-alpn-server:11.0.7"), but the tests are still failing. The alpn-boot extension should not be necessary as JDK 11 is being used.

Anyone able to help me solve this? Do I need another dependency or am I looking in the wrong direction?

Kaj Nelissen
  • 915
  • 10
  • 29
  • Is that class actually `wiremock.org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory.` ? That looks like a shaded or relocated package/namespace, and not pure Jetty. – Joakim Erdfelt Nov 04 '21 at 16:08
  • Can you share what JDK version you're running on in CI? Is it different from the one you're running locally? – Tom Nov 09 '21 at 19:14

2 Answers2

2

Wiremock team addressed this in version 2.32, there's a ticket here. You need to specify a correct version for wiremock-jre8-standalone to override an older version pulled by Spring:

# Gradle
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.32.0'

#Maven
<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock-jre8-standalone</artifactId>
    <version>2.32.0</version>
    <scope>test</scope>
</dependency>
gmode
  • 3,601
  • 4
  • 31
  • 39
1

Downgrade to Jetty 9.4.x

Wiremock does not support Jetty 10 or Jetty 11.

Also, Spring does not support Jetty 11 (which uses Jakarta EE 9 and Servlet 5.0 on the new namespace jakarta.servlet)

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136