please find the details curl --location '<http://l...
# wiremock-java
m
please find the details curl --location 'http://localhost:8090/wiremock/boarding/test/boarding/paymentmethod/PAYPAL/merchantBoarding' \ --header 'X-WP-Diagnostic-CorrelationId: e469be84-91e8-4274-97d6-b5da3aa479c0' \ --header 'X-WP-Jwt: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imp3dCJ9.eyJzdWIiOiJXUEdfU1lTVEVNIiwidmVyIjoiMi4wIiwibGx0IjoxNTU2MDA1ODUwLCJpc3MiOiJXUEciLCJhc2wiOjEsInNpcCI6IjEyNy4wLjAuMSIsImlhdCI6MTU1NjAwNTg1MCwic3R5cCI6NSwicmVxIjoiZTQ2OWJlODQtOTFlOC00Mjc0LTk3ZDYtYjVkYTNhYTQ3OWMwIn0.LSUhT5baZnL8RGasm5NepTTB0LBvLFlGTPhapg4QXwCE0kWjvZWH_wYWPDJoxLo2XIRaRBBzp-lmQ2B5RzecySfGXK1LUYd5udZzkhmgI6IoJpD2JoZa-iE0Bv6C4ICaAxmouHFNhhc7E13aR6DhSq2iZr247dHsOwyDhZwd2Fh_JuwCRE8EwP5uUPEkZOQUiSiXcfKgUCSluvxcNbBIw8j8eAVleAMI_rMECVLH5kOWNubitSawpfjmoBNY5zsmrIrcYuLJPFpQDvEbxHp1j7m26Ffqz4MBAeEaLDi1YH7n48TCWb250uv_AwHMBeRtO8e2cu1XFthON1qTRQ5t4g' \ --header 'X-WP-Diagnostic-CallerId: WPG_SYSTEM' \ --header 'X-WP-Timestamp: 1519653386' \ --header 'Content-Type: application/v1+json' \ --header 'Accept: application/v4+json' \ --data '{ "name": "test" }' Rlocalhost/127.0.0.18091] Handler is being applied: {uri=http://localhost:8091/boarding/paymentmethod/PAYPAL/merchantBoarding, method=POST} 2024-04-15T164221.071+05:30 DEBUG 67508 --- [ctor-http-nio-4] r.n.http.client.HttpClientOperations : [648781da-1, L/127.0.0.162667 - Rlocalhost/127.0.0.18091] Received response (auto-read:false) : RESPONSE(decodeResult: success, version: HTTP/1.1) HTTP/1.1 404 Not Found Content-Length: <filtered> 2024-04-15T164221.105+05:30 DEBUG 67508 --- [ctor-http-nio-4] r.n.http.client.HttpClientOperations : [648781da-1, L/127.0.0.162667 - Rlocalhost/127.0.0.18091] Received last HTTP packet
t
I would expect this to return a 404 since the request body JSON isn’t the structure expected by the
matchesJsonPath
expression
If you send your original body, what happens?
Copy code
{
  "name": {
    "first": "Dave",
    "last": "Minion!"
  }
}
m
same 404
I am thinking the dependency is supported or not
Copy code
<dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock-standalone</artifactId>
<!--            <version>3.4.2</version>-->
            <version>3.0.0-beta-1</version>
        </dependency>
        <dependency>
            <groupId>org.wiremock</groupId>
            <artifactId>wiremock-webhooks-extension</artifactId>
            <version>2.30.0</version>
        </dependency>
t
I would suggest sticking with the latest (3.5.2) rather than an old beta version.
What output are you seeing in the response body when you get the 404?
m
its blank
t
OK, that suggests that something more fundamental is going wrong like you’re not actually hitting WireMock. If you were you’d see a “Request not matched” report.
m
its hitting server and printing the log
my local
if I remove the "matchesJsonPath" . i am getting the response
the issue with "matchesJsonPath" attribute
its not working after upgrading the dependency with 3.0.0-beta-1 version
t
I tried your stub on v3.5.2 and it matched the body JSON you originally sent
If the issue was with matching the response body returned from WireMock would contain a non-match report
If it’s blank then that implies the response isn’t being returned from WireMock
m
<dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock</artifactId> <version>2.27.2</version> </dependency>
for this version everything working
t
Can you enable verbose logging on WireMock and capture the output? This should also show the diff report
m
how to do that
t
Wherever you’re starting
WireMockServer
or using the JUnit extension, in the
wireMockConfig()
builder part add `.notifier(new ConsoleNotifier(true))`;
m
ok. added let me try
curl --location 'http://localhost:8090/wiremock/boarding/test/boarding/paymentmethod/PAYPAL/merchantBoarding' \ --header 'X-WP-Diagnostic-CorrelationId: e469be84-91e8-4274-97d6-b5da3aa479c0' \ --header 'X-WP-Jwt: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imp3dCJ9.eyJzdWIiOiJXUEdfU1lTVEVNIiwidmVyIjoiMi4wIiwibGx0IjoxNTU2MDA1ODUwLCJpc3MiOiJXUEciLCJhc2wiOjEsInNpcCI6IjEyNy4wLjAuMSIsImlhdCI6MTU1NjAwNTg1MCwic3R5cCI6NSwicmVxIjoiZTQ2OWJlODQtOTFlOC00Mjc0LTk3ZDYtYjVkYTNhYTQ3OWMwIn0.LSUhT5baZnL8RGasm5NepTTB0LBvLFlGTPhapg4QXwCE0kWjvZWH_wYWPDJoxLo2XIRaRBBzp-lmQ2B5RzecySfGXK1LUYd5udZzkhmgI6IoJpD2JoZa-iE0Bv6C4ICaAxmouHFNhhc7E13aR6DhSq2iZr247dHsOwyDhZwd2Fh_JuwCRE8EwP5uUPEkZOQUiSiXcfKgUCSluvxcNbBIw8j8eAVleAMI_rMECVLH5kOWNubitSawpfjmoBNY5zsmrIrcYuLJPFpQDvEbxHp1j7m26Ffqz4MBAeEaLDi1YH7n48TCWb250uv_AwHMBeRtO8e2cu1XFthON1qTRQ5t4g' \ --header 'X-WP-Diagnostic-CallerId: WPG_SYSTEM' \ --header 'X-WP-Timestamp: 1519653386' \ --header 'Content-Type: application/v1+json' \ --header 'Accept: application/v4+json' \ --data '{ "name": "test" }'
2024-04-15 180007.862 Warning: JSON path expression '"$[?(@.name == 'test')]' failed to match document '["{ \r\n \"name\": \"te' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 25: null' 2024-04-15 180007.875 Warning: JSON path expression '"$[?(@.name == 'test')]' failed to match document '["{ \r\n \"name\": \"te' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 25: null' 2024-04-15 180007.875 Warning: JSON path expression '"$[?(@.name == 'test')]' failed to match document '["{ \r\n \"name\": \"te' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 25: null' 2024-04-15 180007.876 Request was not matched ======================= ----------------------------------------------------------------------------------------------------------------------- | Closest stub | Request | ----------------------------------------------------------------------------------------------------------------------- | POST | POST [regex] | /boarding/paymentmethod/PAYPAL/merchantBoarding /boarding/paymentmethod/([A-Z]{3,50})/merchantBoarding | | "$[?(@.name == 'test')] | ["{ \r\n \"name\": \"te <<<<< Body does not match | ----------------------------------------------------------------------------------------------------------------------- 2024-04-15T180007.908+05:30 DEBUG 32944 --- [ctor-http-nio-4] r.n.http.client.HttpClientOperations : [1baf3a6e-1, L/127.0.0.152886 - Rlocalhost/127.0.0.18091] Received response (auto-read:false) : RESPONSE(decodeResult: success, version: HTTP/1.1) HTTP/1.1 404 Not Found Content-Type: <filtered> Transfer-Encoding: <filtered>
t
It looks like you’re sending malformed (incomplete) JSON in the request here.
I’ve tried this setup locally with the latest WireMock version and it’s works fine
m
than not sure
I am sending everything right
Copy code
{
  "name": "test"
}
its very simple JSON
t
According to the error from your log WireMock is only recieving
{ "name": "te
If you make the request directly to WireMock from Postman can you get it to work?
This was for this stub:
m
through postman also not working
t
Can you share the log and response output you got via postman?
m
Logs : 2024-04-15T190620.225+05:30 DEBUG 77392 --- [ctor-http-nio-4] r.netty.http.client.HttpClientConnect : [82aa07ac-1, L/127.0.0.158735 - Rlocalhost/127.0.0.18091] Handler is being applied: {uri=http://localhost:8091/boarding/paymentmethod/PAYPAL/merchantBoarding, method=POST} 2024-04-15 190620.231 Warning: JSON path expression '$[?(@.name == 'test')]' failed to match document '["{\r\n \"name\": \"t' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 21: null' 2024-04-15 190620.232 Request received: 127.0.0.1 - POST /boarding/paymentmethod/PAYPAL/merchantBoarding Accept: [application/v4+json] X-WP-Diagnostic-CorrelationId: [e469be84-91e8-4274-97d6-b5da3aa479c0] User-Agent: [PostmanRuntime/7.37.3] Connection: [keep-alive] Host: [localhost:8090] Accept-Encoding: [gzip, deflate, br] Forwarded: [host=localhost:8090] X-WP-Diagnostic-CallerId: [WPG_SYSTEM] X-WP-Timestamp: [1519653386] X-WP-Jwt: [eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imp3dCJ9.eyJzdWIiOiJXUEdfU1lTVEVNIiwidmVyIjoiMi4wIiwibGx0IjoxNTU2MDA1ODUwLCJpc3MiOiJXUEciLCJhc2wiOjEsInNpcCI6IjEyNy4wLjAuMSIsImlhdCI6MTU1NjAwNTg1MCwic3R5cCI6NSwicmVxIjoiZTQ2OWJlODQtOTFlOC00Mjc0LTk3ZDYtYjVkYTNhYTQ3OWMwIn0.LSUhT5baZnL8RGasm5NepTTB0LBvLFlGTPhapg4QXwCE0kWjvZWH_wYWPDJoxLo2XIRaRBBzp-lmQ2B5RzecySfGXK1LUYd5udZzkhmgI6IoJpD2JoZa-iE0Bv6C4ICaAxmouHFNhhc7E13aR6DhSq2iZr247dHsOwyDhZwd2Fh_JuwCRE8EwP5uUPEkZOQUiSiXcfKgUCSluvxcNbBIw8j8eAVleAMI_rMECVLH5kOWNubitSawpfjmoBNY5zsmrIrcYuLJPFpQDvEbxHp1j7m26Ffqz4MBAeEaLDi1YH7n48TCWb250uv_AwHMBeRtO8e2cu1XFthON1qTRQ5t4g] Postman-Token: [86a72979-f19e-403c-bb72-454e289b5a47] Content-Length: [22] Content-Type: [application/v1+json] ["{\r\n \"name\": \"t Matched response definition: (no response definition configured) Response: HTTP/1.1 404 (no headers) 2024-04-15 190620.233 Admin request received: 127.0.0.1 - POST /not-matched Accept: [application/v4+json] X-WP-Diagnostic-CorrelationId: [e469be84-91e8-4274-97d6-b5da3aa479c0] User-Agent: [PostmanRuntime/7.37.3] Connection: [keep-alive] Host: [localhost:8090] Accept-Encoding: [gzip, deflate, br] Forwarded: [host=localhost:8090] X-WP-Diagnostic-CallerId: [WPG_SYSTEM] X-WP-Timestamp: [1519653386] X-WP-Jwt: [eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imp3dCJ9.eyJzdWIiOiJXUEdfU1lTVEVNIiwidmVyIjoiMi4wIiwibGx0IjoxNTU2MDA1ODUwLCJpc3MiOiJXUEciLCJhc2wiOjEsInNpcCI6IjEyNy4wLjAuMSIsImlhdCI6MTU1NjAwNTg1MCwic3R5cCI6NSwicmVxIjoiZTQ2OWJlODQtOTFlOC00Mjc0LTk3ZDYtYjVkYTNhYTQ3OWMwIn0.LSUhT5baZnL8RGasm5NepTTB0LBvLFlGTPhapg4QXwCE0kWjvZWH_wYWPDJoxLo2XIRaRBBzp-lmQ2B5RzecySfGXK1LUYd5udZzkhmgI6IoJpD2JoZa-iE0Bv6C4ICaAxmouHFNhhc7E13aR6DhSq2iZr247dHsOwyDhZwd2Fh_JuwCRE8EwP5uUPEkZOQUiSiXcfKgUCSluvxcNbBIw8j8eAVleAMI_rMECVLH5kOWNubitSawpfjmoBNY5zsmrIrcYuLJPFpQDvEbxHp1j7m26Ffqz4MBAeEaLDi1YH7n48TCWb250uv_AwHMBeRtO8e2cu1XFthON1qTRQ5t4g] Postman-Token: [86a72979-f19e-403c-bb72-454e289b5a47] Content-Length: [22] Content-Type: [application/v1+json] 2024-04-15 190620.234 Warning: JSON path expression '$[?(@.name == 'test')]' failed to match document '["{\r\n \"name\": \"t' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 21: null' 2024-04-15 190620.234 Warning: JSON path expression '$[?(@.name == 'test')]' failed to match document '["{\r\n \"name\": \"t' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 21: null' 2024-04-15 190620.235 Warning: JSON path expression '$[?(@.name == 'test')]' failed to match document '["{\r\n \"name\": \"t' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 21: null' 2024-04-15T190620.236+05:30 DEBUG 77392 --- [ctor-http-nio-4] r.n.http.client.HttpClientOperations : [82aa07ac-1, L/127.0.0.158735 - Rlocalhost/127.0.0.18091] Received response (auto-read:false) : RESPONSE(decodeResult: success, version: HTTP/1.1) HTTP/1.1 404 Not Found Content-Type: <filtered> Transfer-Encoding: <filtered> 2024-04-15T190620.238+05:30 DEBUG 77392 --- [ctor-http-nio-4] r.n.http.client.HttpClientOperations : [82aa07ac-1, L/127.0.0.158735 - Rlocalhost/127.0.0.18091] Received last HTTP packet 2024-04-15 190620.235 Request was not matched ======================= ----------------------------------------------------------------------------------------------------------------------- | Closest stub | Request | ----------------------------------------------------------------------------------------------------------------------- | POST | POST [regex] | /boarding/paymentmethod/PAYPAL/merchantBoarding /boarding/paymentmethod/([A-Z]{3,50})/merchantBoarding | | $[?(@.name == 'test')] | ["{\r\n \"name\": \"t <<<<< Body does not match | -----------------------------------------------------------------------------------------------------------------------
t
Seems like you’re still hitting your app under test there rather than WireMock directly
m
How to hit wiremock directly
t
You can create a URL in your postman request that uses WireMock’s host and port. It looks like the base URL should be
<http://localhost:8091>
in your case.
i got the response as 200
2024-04-15 191038.221 Request received: [0000000:1] - POST /boarding/paymentmethod/PAYPAL/merchantBoarding X-WP-Diagnostic-CorrelationId: [e469be84-91e8-4274-97d6-b5da3aa479c0] X-WP-Jwt: [eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imp3dCJ9.eyJzdWIiOiJXUEdfU1lTVEVNIiwidmVyIjoiMi4wIiwibGx0IjoxNTU2MDA1ODUwLCJpc3MiOiJXUEciLCJhc2wiOjEsInNpcCI6IjEyNy4wLjAuMSIsImlhdCI6MTU1NjAwNTg1MCwic3R5cCI6NSwicmVxIjoiZTQ2OWJlODQtOTFlOC00Mjc0LTk3ZDYtYjVkYTNhYTQ3OWMwIn0.LSUhT5baZnL8RGasm5NepTTB0LBvLFlGTPhapg4QXwCE0kWjvZWH_wYWPDJoxLo2XIRaRBBzp-lmQ2B5RzecySfGXK1LUYd5udZzkhmgI6IoJpD2JoZa-iE0Bv6C4ICaAxmouHFNhhc7E13aR6DhSq2iZr247dHsOwyDhZwd2Fh_JuwCRE8EwP5uUPEkZOQUiSiXcfKgUCSluvxcNbBIw8j8eAVleAMI_rMECVLH5kOWNubitSawpfjmoBNY5zsmrIrcYuLJPFpQDvEbxHp1j7m26Ffqz4MBAeEaLDi1YH7n48TCWb250uv_AwHMBeRtO8e2cu1XFthON1qTRQ5t4g] X-WP-Diagnostic-CallerId: [WPG_SYSTEM] X-WP-Timestamp: [1519653386] Content-Type: [application/v1+json] Accept: [application/v4+json] User-Agent: [PostmanRuntime/7.37.3] Postman-Token: [f78cfa41-41c5-4263-a133-189ddda335f2] Host: [localhost:8091] Accept-Encoding: [gzip, deflate, br] Connection: [keep-alive] Content-Length: [22] { "name": "test" } Matched response definition: { "status" : 200 } Response: HTTP/1.1 200 Matched-Stub-Id: [10fed0eb-95af-4fb1-ba1d-31c8ece93b85]
t
So it seems the WireMock server is still working OK, but for some reason your app’s client is truncating the JSON in the request body, or else some strange interaction is occurring between specific versions of client and server.
m
but i am not understanding what is the issue with my application . its working for wirework
t
Which HTTP client library does your app use?
m
i think its using jetty server
t
What about the client?
I’m guessing Netty from the log names
m
2024-04-15T191641.938+05:30 INFO 42244 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8090 2024-04-15T191643.254+05:30 INFO 42244 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
t
If so, it’s worth checking you’re on an up to date version of Netty. There was a issue (quite a while ago) where certain versions of Netty client played badly with certain versions of Jetty server.
m
ok . let me try with different version
we are using Spring reactive context and sending the Json body as Mono<String> . but request are failing with mismatch of body as showed the below .
Copy code
private Flux<String> getBodyFromReq(Flux<DataBuffer> flux) {
    return flux.flatMap(dataBuffer -> {
        byte[] bytes = new byte[dataBuffer.readableByteCount()];
        dataBuffer.read(bytes);
        DataBufferUtils.release(dataBuffer);
       var body = new String(bytes, StandardCharsets.UTF_8);
        return Mono.just(body);
    });
}
2024-04-16 112223.450 Warning: JSON path expression '$[?(@.name == 'test')]' failed to match document '["{\r\n \"name\": \"t' because of error 'wiremock.net.minidev.json.parser.ParseException: Unexpected End Of File position 21: null' 2024-04-16 112223.450 Request was not matched ======================= ----------------------------------------------------------------------------------------------------------------------- | Closest stub | Request | ----------------------------------------------------------------------------------------------------------------------- | POST | POST [regex] | /boarding/paymentmethod/XXXX/merchantBoarding /boarding/paymentmethod/([A-Z]{3,50})/merchantBoarding | | $[?(@.name == 'test')] | ["{\r\n \"name\": \"t <<<<< Body does not match | ----------------------------------------------------------------------------------------------------------------------- what wire mock is expecting what type of object ? will that accept flux<String> . do you see this as a problem ?
t
I can still see the truncated JSON and looking at the code you’ve shared, I’d guess that
dataBuffer.readableByteCount()
isn’t returning the entire length of the JSON payload. I’m not all that familiar with the Spring reactive APIs but I’d guess there’s a way to read a
DataBuffer
until it signals that everything has been read?