This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Help needed with HttpMessageNotReadabableException

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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:







 
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!