Groovy使用旧的servlet API污染类路径

时间:2017-01-23 22:10:15

标签: groovy wiremock

我正在编写Groovy脚本以在CI过程中启动WireMock服务器:

#!/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()

我有一个简单的映射:

{
    "request": {
        "urlPattern": "/test",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "body": "42"
    }
}

我可以在/__admin部分看到该映射:

{
    "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
    }
}

但是当我点击该网址时,我得到了:

HTTP ERROR: 500

Problem accessing /test. Reason:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;

WUT?

看起来类路径上的Servlet API版本是2.4!但是它来自哪里?从Groovy的安装:${GROOVY_HOME}/lib/servlet-api-2.4.jar

我已从Groovy的lib中移除了该JAR,而WireMock已回应我所需的回复。

我该如何解决?显然,我无法在CI服务器上修改Groovy安装。我应该自己编写groovy-starter.conf吗?我不喜欢这个主意。

0 个答案:

没有答案