spring-restbucks
spring-restbucks copied to clipboard
Validation beforeSave* is not working (but beforeCreate* is working)
Hi Oliver I was trying to add validation in the same project, but it didn't worked properly. When I give bean name as beforeSaveItemValidator its not working, eventhough beforeCreateItemValidator is working as expected. Can you please help me, or can you add validation in this restbucks project.
Here is the output
When bean is beforeCreateItemValidator()
Validation is working ---> 400 Bad Request
curl -v -X POST -H "Content-Type: application/json" -d '{ "id" :4, "quantity" : 44 }' http://localhost:8080/item/
- About to connect() to localhost port 8080
- Trying 127.0.0.1... connected
- Connected to localhost (127.0.0.1) port 8080
POST /item/ HTTP/1.1 User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: localhost:8080 Accept: / Content-Type: application/json Content-Length: 28
{ "id" :4, "quantity" : 44 }HTTP/1.1 400 Bad Request < Content-Type: application/json < Transfer-Encoding: chunked < Server: Jetty(8.1.9.v20130131)
- Connection #0 to host localhost left intact
- Closing connection #0 {"errors":[{"entity":"Item","message":"Item name required","invalidValue":"null","property":"name"}]}
but When bean is beforeSaveItemValidator()
Validation is not working ---> 201 Created
curl -v -X POST -H "Content-Type: application/json" -d '{ "id" :4, "quantity" : 44 }' http://localhost:8080/item/
- About to connect() to localhost port 8080
- Trying 127.0.0.1... connected
- Connected to localhost (127.0.0.1) port 8080
POST /item/ HTTP/1.1 User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: localhost:8080 Accept: / Content-Type: application/json Content-Length: 28
{ "id" :4, "quantity" : 44 }HTTP/1.1 201 Created < Location: http://localhost:8080/item/3 < Content-Length: 0 < Server: Jetty(8.1.9.v20130131)
- Connection #0 to host localhost left intact
- Closing connection #0
You can get the changes here
https://github.com/guptasujeet/spring-restbucks.git
Forgot to commit changes in github , will commit tomorrow
@olivergierke @guptasujeet Can we get this working in the main project?
Any updates??