Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request body not being logged in Spring Boot #382

Closed
captainjackrana opened this issue Nov 6, 2018 · 8 comments
Closed

POST request body not being logged in Spring Boot #382

captainjackrana opened this issue Nov 6, 2018 · 8 comments

Comments

@captainjackrana
Copy link

captainjackrana commented Nov 6, 2018

Description

I'm using the logbook-spring-boot-starter package with Spring Boot 2.0.5.RELEASE.
As per the docs, I've set logging.level.org.zalando.logbook=TRACE property in application.properties
It logs all request/response as expected, however does not print the body of POST Requests with content type :application/x-www-form-urlencoded

The Readme says that since Logbook 1.5.0, we can set the strategy for logging the request body. I've even tried setting that, experimenting with all values for the property logbook.servlet.form-request, but it still doesn't work.

I did some debugging and looked up JsonHttpLogFormatter class. In the addBody method, the
message.getBodyAsString() for the HttpMessage is empty, due to which the key doesn't get printed in the output.

Also attaching a sample curl request -

  http://localhost:8080/ \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'postman-token: 249bbc87-51f7-f458-8f4a-1daaf2ea04e5' \
  -d query=test

And its corresponding generated log via Logbook

{"origin":"remote","type":"request","correlation":"fca9a0acdb70a26f","protocol":"HTTP/1.1","remote":"0:0:0:0:0:0:0:1","method":"POST","uri":"http://localhost:8080/","headers":{"accept":["*/*"],"accept-encoding":["gzip, deflate, br"],"accept-language":["en-US,en;q=0.9"],"cache-control":["no-cache"],"connection":["keep-alive"],"content-length":["10"],"content-type":["application/x-www-form-urlencoded"],"host":["localhost:8080"],"origin":["chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop"],"postman-token":["298fd08f-5ab0-8f44-b06d-f279e4d1e5bc"],"user-agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"]}}
2018-11-06

Your Environment

  • Version used: Spring Boot 2.0.5.RELEASE, logbook-spring-boot-starter v1.11.1
@captainjackrana
Copy link
Author

Seems like the problem only exists for application/x-www-form-urlencoded content-type.
Using content-type as application/json results in body being printed properly.

@whiskeysierra
Copy link
Collaborator

Yes, due to the way the Servlet API spec treats application/x-www-form-urlencoded it's a special content type. https://github.com/zalando/logbook#servlet mentions this with a reference to #94. If you set the system property logbook.servlet.form-request to either body or parameter, then you should see a difference.

@captainjackrana
Copy link
Author

Thanks for replying @whiskeysierra. As mentioned above in the description, I've tried setting the logbook.servlet.form-request property to both body as well as parameter, but it still does not print it.

@whiskeysierra
Copy link
Collaborator

Can you create a minimal project to reproduce the issue?

@captainjackrana
Copy link
Author

captainjackrana commented Nov 6, 2018

Created a spring boot project here @whiskeysierra :
https://github.com/captainjackrana/logbook-post-bug

@whiskeysierra
Copy link
Collaborator

logbook.servlet.form-request is a system property, not a Spring application property. You'd need to set that when you start you JVM: -Dlogbook.servlet.form-request=parameter

@captainjackrana
Copy link
Author

Thank you. Didn't pay attention to the system property line when I used it from the Logbook Readme. Perhaps you can explicitly mention -Dlogbook.servlet.form-request=parameter to avoid such things in future.
Closing the issue

@whiskeysierra
Copy link
Collaborator

whiskeysierra commented Nov 9, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants