3

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.

madhead
  • 31,729
  • 16
  • 153
  • 201
  • Can you just exclude it (http://docs.groovy-lang.org/latest/html/documentation/grape.html#Grape-ExcludingTransitiveDependencies) and include the correct one? – cjstehno Jan 24 '17 at 14:00
  • @cjstehno, how can I do that? It's not Grapes dependency, it's a built-in groovy library. – madhead Jan 24 '17 at 21:28
  • @madhead, have you been able to solve this? – r0b0 Apr 24 '18 at 15:21
  • 1
    @r0b0, actually, no. I just remember that I had to make monkey-patching of Groovy's installation. Very strange issue, shame on the Groovy authors. – madhead Apr 26 '18 at 12:04

0 Answers0