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

Validation beforeSave* is not working (but beforeCreate* is working) #4

Open
guptasujeet opened this issue Mar 21, 2013 · 3 comments
Open

Comments

@guptasujeet
Copy link

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

@guptasujeet
Copy link
Author

Forgot to commit changes in github , will commit tomorrow

@zachariahyoung
Copy link

@olivergierke @guptasujeet Can we get this working in the main project?

@gedankennebel
Copy link

Any updates??

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

3 participants