Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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:







 
Sheriff
Posts: 67399
173
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
Sheriff
Posts: 67399
173
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
Sheriff
Posts: 67399
173
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!
 
Not so fast naughty spawn! I want you to know about
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic