1

My employer uses Playframework 2.4, which uses Netty as it's HTTP handler.

In the application I'm working on, the server rejects some client POSTs (no request body) with an HTTP 400 error.

If I POST the same URL from my REST client, it succeeds. It gets to application controller method mapped to that route.

Therefore, I think Netty is rejecting the client POST. I want to know why Netty doesn't like the request.

Having a Netty access.log would be very helpful for this situation (and future odd situations).

Is there an easy way to add a Java access logging class to the Netty pipeline included in Playframework 2.4?

If so, what would the Java class look like and where would I put it, so Netty would use it?

Joan
  • 4,079
  • 2
  • 28
  • 37
devdanke
  • 1,309
  • 15
  • 27
  • I was able to configure Playframework and Netty to output a basic accesslog. It takes a System property `http.netty.log.wire=true` and logback.xml config, as described here: https://www.playframework.com/documentation/2.3.x/SettingsLogger . However, that log still doesn't tell me exactly why Netty decided a POST request was a 400. – devdanke Mar 22 '16 at 22:54

1 Answers1

0

Netty is not rejecting the POST requests, Netty doesn't reject anything, it's a very low level framework, even if it has troubles parsing the request, it still passes it on to Play in a failed state. If anything is rejecting the POST requests, it's Play.

You can implement a simple filter in Play to log requests, as shown here:

https://www.playframework.com/documentation/2.4.x/ScalaHttpFilters

James Roper
  • 12,695
  • 46
  • 45
  • Sorry, Scala is not an option for this project. But for the heck of it, I tried to follow that example. Unfortunately, I found no documentation about how to mix Java and Scala code files together for this sort of thing. I've edited the question to make it clear, I'm looking for a Java solution. Also, despite enabling all the loggers I could, I never saw any indication that a Playframework class received the request. I suspect that something like Netty's HttpRequestDecoder is being used. And that it rejects the bad POST. – devdanke Mar 22 '16 at 22:44
  • 1
    You can replace the word 'Scala' in the url with the word 'Java': https://www.playframework.com/documentation/2.4.x/JavaHttpFilters – cagenut Mar 23 '16 at 14:40
  • @cagenut: A few things: 1) Your reference shows how to configure existing filters, not how to write a Java filter. 2) AFAIK, these filters are like Servlet Filters, i.e. they're invoked after and outside of the Netty HTTP server. In my case, the client request is rejected not by Play but by Netty, which is embedded within Play. AFAIK, the error happens in Netty and never makes it to Play code. 3) I already I tried to create a Java Filter based the on that. It didn't work. I posted my question to get concrete help to solve the problem. I already scanned the docs pretty thoroughly. – devdanke Mar 23 '16 at 18:10
  • @James Roper: You suggest that HTTP errors found by Netty are in some way passed to Play. If true, than there should be a way to see that in the logs. Can you please post a logback config that would cause Netty HTTP errors to be logged or that shows where/why Play sees it as an error? I've tried various logback configs but never saw these error/warn messages. – devdanke Mar 23 '16 at 18:17
  • Not all errors found by Netty are passed to Play, if you open a connection to Play and send complete junk, then those errors will just be logged to the error logger. But then - if it's junk, not an HTTP request, then there's no HTTP request to log. Whatever the case, Netty never sends 400 errors, only Play does that. – James Roper Mar 31 '16 at 05:09