You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have Spring-Boot application and integration tests using Cucumber and WireMock. When switching tests to parallel execution mode, I started to receive the following unclear exceptions during invocation of WireMock.stubFor(..):
com.github.tomakehurst.wiremock.common.JsonException:
{
"errors" : [ {
"code" : 10,
"source" : {
"pointer" : "/code"
},
"title" : "Error parsing JSON",
"detail" : "Unrecognized field \"code\" (class com.github.tomakehurst.wiremock.common.Errors), not marked as ignorable"
} ]
}
at com.github.tomakehurst.wiremock.common.JsonException.fromJackson(JsonException.java:53)
at com.github.tomakehurst.wiremock.common.Json.read(Json.java:60)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:519)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:489)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:466)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:146)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:414)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:409)
at com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:115)
at com.github.tomakehurst.wiremock.client.WireMock.stubFor(WireMock.java:119)
The stack trace is from version: com.github.tomakehurst:wiremock-jre8-standalone:2.33.0, but code logic inside HttpAdminClient with the latest version is the same.
WireMock was created from thread main in the following way:
After investigation, it was discovered that the response body during stub definition execution is {"code":"404.null.55","message":"Not Found"}. The issue was that request targeted the wrong port, it took a default port 8080 instead of configured 8000. It's due to WireMock.stubFor(..) is invoked from another thread (due to parallel execution mode by Cucumber). Due to implementation inside WireMock, it has thread local defaultInstance, which should be additionally configured with appropriate port from the invoked thread.
Port 8000 was configured for WireMock server and 8080 for Tomcat from Spring Boot test.
If there is no process on port 8080, it will throw HttpHostConnectException with url (including port number) as part of exception message, so it helps investigate various issues.
So I updated code to invoke WireMock.configureFor(8000); before each invocation of WireMock.stubFor(..) to guarantee that port is configured per each required thread, and it fixed the issue.
The initial exception that I faced as JsonException Unrecognized field 'code' is due to not properly handling 404 client error code inside HttpAdminClient, as this 404 error not from Wire Mock server, but might be from any other server (indeed it's a rare case, but still might happen).
It would be great to have an appropriate error description (with an explicitly specified url that includes port) instead of unclear JsonException for this use case.
Reproduction steps
Start Spring-Boot application on port 8080.
Then configure WireMock server without invoking configureFor(..);:
…descriptive-exception-message
Fixes#2665 - WireMock.stubFor throws descriptive exception message on 404 error code from non-WireMock server instead of unclear JsonException
Proposal
I have Spring-Boot application and integration tests using Cucumber and WireMock. When switching tests to parallel execution mode, I started to receive the following unclear exceptions during invocation of
WireMock.stubFor(..)
:The stack trace is from version:
com.github.tomakehurst:wiremock-jre8-standalone:2.33.0
, but code logic insideHttpAdminClient
with the latest version is the same.WireMock was created from thread
main
in the following way:Stub initialization:
After investigation, it was discovered that the response body during stub definition execution is
{"code":"404.null.55","message":"Not Found"}
. The issue was that request targeted the wrong port, it took a default port 8080 instead of configured 8000. It's due toWireMock.stubFor(..)
is invoked from another thread (due to parallel execution mode by Cucumber). Due to implementation insideWireMock
, it has thread localdefaultInstance
, which should be additionally configured with appropriate port from the invoked thread.Port 8000 was configured for
WireMock
server and 8080 for Tomcat from Spring Boot test.If there is no process on port 8080, it will throw
HttpHostConnectException
with url (including port number) as part of exception message, so it helps investigate various issues.So I updated code to invoke
WireMock.configureFor(8000);
before each invocation ofWireMock.stubFor(..)
to guarantee that port is configured per each required thread, and it fixed the issue.The initial exception that I faced as
JsonException Unrecognized field 'code'
is due to not properly handling 404 client error code inside HttpAdminClient, as this 404 error not from Wire Mock server, but might be from any other server (indeed it's a rare case, but still might happen).It would be great to have an appropriate error description (with an explicitly specified url that includes port) instead of unclear
JsonException
for this use case.Reproduction steps
Start Spring-Boot application on port 8080.
Then configure WireMock server without invoking
configureFor(..);
:When
stubFor(..)
is invoked:non-descriptive exception
JsonException
will be thrownReferences
I will provide proposed pull request
The text was updated successfully, but these errors were encountered: