0

Setting an invalid value in the edit form (bigger value than the Long limit) causes a 405 on submit (POST) on tomcat 8.

Same submit on tomcat 7 works as expected and shows a field binding error:

Failed to convert property value of type java.lang.String to required type java.lang.Long for property userId; nested exception is java.lang.NumberFormatException: For input string: "56345345345345345345345345"

Any idea?

Chris
  • 549
  • 1
  • 5
  • 18

2 Answers2

1

The max value for Long is 9223372036854775807. Your number is bigger than it. Try BigDecimal as parameter or get it as string and then parse it to BigDecimal.

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
  • Hi Evgeni, I know that it's bigger. This is why I was expecting a validation error message in my update form (as shown in tomcat 7) instead of a 405 page shown in tomcat 8. The question is how can I have that validation message on tomcat 8 and why I get a 405 (the request is POST) instead of a validation message. – Chris Mar 21 '15 at 16:13
  • @Chris How is your validation organized? Hibernate validator, spring validator, client side? Can you add it to the question. – Evgeni Dimitrov Mar 21 '15 at 17:42
  • there's not any validation constraint on that field. Spring binding mechanism fails to translate the input string to Long and shows the thrown exception message below the fields in a validation error format – Chris Mar 22 '15 at 17:32
0

Finally I found out that the reason has to do with the fact that Spring changes the request from POST to PUT based on the hidden field _method (on HiddenHttpMethodFilter, see [1]) but never changes it back to the previous method. As a result, when there is requested the update form to be shown with the validation or binding error messages, the forward Spring does (InternalResourceView), contains the wrapped request which has the method overwritten to PUT and for this reason is rejected by Tomcat >= 8.

A good approach seems to be the use of a manual filter which changes the method to GET on FORWARD [2], [3]

[1] HTTP Status 405 - JSPs only permit GET POST or HEAD

[2] 405 JSP error with Put Method

[3] https://jira.spring.io/browse/SPR-12848

Community
  • 1
  • 1
Chris
  • 549
  • 1
  • 5
  • 18