question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash with POST requests and WebTestClient: Request body incomplete.

See original GitHub issue

Hi.

I’m getting the following crash

java.lang.IllegalArgumentException: Request body incomplete.

	at org.springframework.util.Assert.isTrue(Assert.java:116)
	at org.springframework.test.web.reactive.server.ExchangeResult.getRequestBodyContent(ExchangeResult.java:149)
	at org.springframework.restdocs.webtestclient.WebTestClientRequestConverter.convert(WebTestClientRequestConverter.java:73)
	at org.springframework.restdocs.webtestclient.WebTestClientRequestConverter.convert(WebTestClientRequestConverter.java:60)
	at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:199)
	at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:81)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$2(DefaultWebTestClient.java:496)
	at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:194)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:496)
	at MyTest.testMain(MyTest.java:72)

The issue is related with the use of a request body with a post request. This happens due to an assert Assert.isTrue(MonoProcessor.isTerminated(). Inspecting that method isTerminated returns subscribers == TERMINATED, but in the case of the request body, debugging shows that subscribers == EMPTY.

Testcase follows.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joaoecommented, Nov 22, 2018

I finally pinpointed the problem: the class WiretapConnector.WiretapClientHttpRequest caches the request body, which is then relayed to the rest docs code. If the request body is not injected into the @RequestMapping, then the original publisher is never written and the MonoProcessor never reaches the terminated state.

This fixes the test case

@PostMapping(path=END_POINT, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handlePutPoll(@RequestBody String stuff) {
  // ...
}
0reactions
joaoecommented, Nov 22, 2018

Ok. Thanks for the input. Cheers.

PS: One of the very last classes in the stack is org.springframework.restdocs.webtestclient.WebTestClientRequestConverter so I asked about the error message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring WebClient Post method Body - Stack Overflow
Here's what i've tried to do but it gives me HTTP code 500. Most likely because you're sending the wrong data in a...
Read more >
Spring 5 WebClient and WebTestClient Tutorial with Examples
WebClient is a non-blocking, reactive HTTP client with a fluent functional style API. ... Passing Request Body in WebClient requests.
Read more >
WebTestClient gets 404 on Spring Boot 2.4.0-M3 while works ...
Coding example for the question WebTestClient gets 404 on Spring Boot 2.4.0-M3 ... If you want to be able to make POST requests...
Read more >
spring-projects/spring-boot - Gitter
Hey I have a spring boot webflux (2.2.7) app running on k8s. It will from time to time receive 10-100 rest call at...
Read more >
Changelog | Pact Docs
4.3.0-beta.2 - Support plugin data in pact files + fixes from master​ ... a84d47a09 - feat: Ignore missing part content type headers with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found