Encountering an error 404 in Firebug when attempting to send an object from Angular to a Java controller using JSON. While the backend in Java is able to receive the message, Angular is unable to find the specified path. Consequently, there is an issue with responding back to Angular.
This is the JSON data being sent:
{"title":"sdtgb","authors":[{"author_id":60,"author":"Brandon Sanderson"}],"genres":[{"genre_id":14,"genre":"Satyra"}],"description":"sdtb","path_image":"19674.png"}
Here is the Java controller code snippet that processes the incoming messages:
@SuppressWarnings("finally")
@RequestMapping(value = "/rest/book", method = RequestMethod.POST)
public MessageDTO addNewBook(@RequestBody BookDTO newBook) {
// Code logic here
}
The path where Angular sends the message and the associated error from Firebug are as follows:
"NetworkError: 404 Not Found - http://localhost:8080/engineering-project-web/rest/book"
Definition of BookDTO class:
public class BookDTO implements Serializable{
// Class variables and methods defined here
}
JavaScript snippet:
Controller section:
// JavaScript code for handling book addition
var book = {
// Content definition here
}
// Calls a function to add a new book
NewBookFct.addNewBook(book)
.then( function(resolve){
if(resolve.check){
alert("Book has been added.");
}else{
alert(resolve.description);
}
}, function(reason){
console.log(reason);
});
Service segment:
// JavaScript service function to incorporate adding a new book
service.addNewBook = function(book){
// Logic implementation here
}