• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help needed with HttpMessageNotReadabableException

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have been struggling with this for a long time now. I have a simple app where I am posting data through AngularJS/Json. I have a Spring controller which works okay when I send the request through postmaster but when I use my angular form to post request, it is giving me a 400 Bad request. I get the following HttpMessageNotReadable Exception on the server. Please help.




My AngularJS controller:




Spring controller:







 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anywhere where fields is defined on the scope. (And what's up with the extra semicolon?)

Irrespective of your data problem, line 7 and 8 are wrong. The post method returns a promise, not the response.

 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I don't see anywhere where fields is defined on the scope. (And what's up with the extra semicolon?)

Irrespective of your data problem, line 7 and 8 are wrong. The post method returns a promise, not the response.



Fields are defined on the form:



Semicolon was by mistake. I initially had promise only, changed this due to few things I was trying..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still see nowhere where the property fields is defined.

Set a break point at line 7. What does variable data contain?
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Data is actually coming out to be undefined...I have not defined fields but I thought that was an angular specific function which changed all the form fields to json data
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed my controller to this now, data now contains Object



Form is like this:



Error as also changes at server:




Update:

I created a default constructor in my User class and now the initial error is back
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you've solved the Angular problem. Congrats!

Now you have a Spring problem. I'll add this post to the Spring forum for you. I don't use Spring so I can't help you with that part.
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:OK, so you've solved the Angular problem. Congrats!

Now you have a Spring problem. I'll add this post to the Spring forum for you. I don't use Spring so I can't help you with that part.



Actually I solved half the problem. I don't think its a Spring problem because Spring works fine when I send data through browser tools. So, after your valuable suggestions, I changed the controller. I edited the post as well but it pending with the mods. The data request goes through but the response is coming out to be bad.







I am even able to see the String response in browser tools.
 
kuhu vora
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to resolve the latest error. I added produces="text/plain" in my Spring controller. Thanks @Bear Bibeault for all the valuable help!
 
permaculture is largely about replacing oil with people. And one tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic