I'm writing a Groovy script to start WireMock server during our CI process:
#!/usr/bin/env groovy
@Grapes([
@Grab(group = 'com.github.tomakehurst', module = 'wiremock', version = '2.5.0')
])
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.common.ConsoleNotifier
import com.github.tomakehurst.wiremock.common.SingleRootFileSource
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource
def wiremock = new WireMockServer(
WireMockConfiguration.wireMockConfig()
.dynamicPort()
.notifier(new ConsoleNotifier(true))
.disableRequestJournal()
.mappingSource(new JsonFileMappingsSource(new SingleRootFileSource(new File("mappings"))))
)
wiremock.start()
I have one simple mapping:
{
"request": {
"urlPattern": "/test",
"method": "GET"
},
"response": {
"status": 200,
"body": "42"
}
}
I can see that mapping in the /__admin
section:
{
"mappings": [
{
"id": "920e232f-ffbf-42b4-b6f2-1aece217c968",
"request": {
"urlPattern": "/test",
"method": "GET"
},
"response": {
"status": 200,
"body": "42"
},
"uuid": "920e232f-ffbf-42b4-b6f2-1aece217c968"
}
],
"meta": {
"total": 1
}
}
But when I hit that URL I get:
HTTP ERROR: 500
Problem accessing /test. Reason:
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;
WUT?
Looks like the version of Servlet API on the classpath is 2.4! But where does it come from? From the Groovy's installation: ${GROOVY_HOME}/lib/servlet-api-2.4.jar
!
I've removed that JAR from Groovy's lib
and WireMock responded me with the desired response.
How can I fix that? Obviously, I cannot modify Groovy installation on the CI server. Should I write my own groovy-starter.conf
? I don't like this idea.