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.

Post body empty when using Spring MVC @RequestParam to handle a application/x-www-form-urlencoded form POST

See original GitHub issue

When logbook-spring-boot-starter is enabled @RequestParam are null

Description

For a valid form POST the following code results in a 400 error. The Spring controller doesn’t see the POST body and the fields are null. Since the @RequestParam fields are required it returns a 400 error.

   @PostMapping("/form")
    public ModelAndView handlePost(@RequestParam String field1, @RequestParam String field2) {

Expected Behavior

The POST body should be processed by Spring MVC whether or not logbook is enabled.

Actual Behavior

Spring MVC can’t process the POST.

Possible Fix

Saw a similar bug about missing a flush call. We use logbook on another project that has a JSON POST body and it works fine. Seems to just be isolated to application/x-www-form-urlencoded

Steps to Reproduce

See https://github.com/dillon-sellars/logbook-bug

Context

Just wanted to add logging to app, broke form posts instead.

Your Environment

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dillon-sellarscommented, Oct 15, 2020

Ah I see, but your default configuration should not break the way servlets work. I would consider making the default parameter or off. I would go so far as to say the body options shouldn’t even exist - does an option where getParameter doesn’t work have a valid use?

0reactions
no-response[bot]commented, Nov 19, 2020

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don’t have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to properly receive urlencoded form body with Spring
It just gets set to null. I send it from Postman, as a post request, with the content type set, and my parameters...
Read more >
Springboot : @RequestParam in controller reads the request ...
Coding example for the question Springboot : @RequestParam in controller reads the request with '&' and '#' as empty-Spring MVC.
Read more >
Handling URL Encoded Form Data in Spring REST - Baeldung
Learn how to handle URL encoded form data in Spring REST. ... But, if we're using the POST method, then its data is...
Read more >
How to handle URL Encoded Form Data in Spring REST?
Sometimes, our REST endpoint needs to consume data in the form of application/x-www-form-urlencoded or using multipart/form-data. The source of ...
Read more >
Writing REST Services with RESTEasy Reactive - Quarkus
POST /cheeses;variant=goat/tomme?age=matured HTTP/1.1 Content-Type: application/x-www-form-urlencoded Cookie: level=hardcore ...
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