I have a RESTful Web Service that acts as a repository of ToDo tasks.
On the other hand I have a Web Application that uses that REST Server for managing the Todo repository.
I've tried my first call from the client to the server in order to retrieve some data, but it fails.
The code in the REST Server is as follows:
/**
* A service that manipulates ToDo's in an repository.
*
*/
@Path("/todolist")
public class ToDoWebService {
/**
* The (shared) repository object.
*/
@Inject
ToDoList toDoList;
/**
* A GET /todos request should return the ToDo's repository in JSON.
* @return a JSON representation of the ToDo's repository.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public ToDoList getToDoList() {
return toDoList;
}
....
And the client call (in AngularJS):
(function() {
var app = angular.module('toDoApp', []);
var API_URI = "http://localhost:8080/todolist";
....
....
app.controller('addToDoCtrl', ['$scope', '$http', function($scope, $http){
$scope.getToDoList = function() {
$http.get(API_URI).
success(function(data) {
console.log(data);
}).
error(function(data, status, headers, config) {
console.log(status);
console.log(data);
console.log(headers);
console.log(config);
});
};
}]);
....
....
})();
But the server always return a 500 (Internal Server Error)
This call it's made when you click on the "AddToDo" tab of the web application, and you can see the result of the call in the console, the error in this case.
But the most remarkable thing is that when I change the REST Server code:
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getToDoList() {
return "It's me, example text";
}
Then, it returns correctly the string "It's me, example text".
I've checked the libaries included in the I've checked the libaries included in the build.gradle file and all the server classes over and over again, finding no solution at all.
This are the headers of the HTTP request-response, all seems in order, except for the error of course:
Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/todolist
Request Method:GET
Status Code:500 Internal Server Error
**Request Headers**
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:es-ES,es;q=0.8,en;q=0.6
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost
Referer:http://localhost/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Response Headersview source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin, content-type, accept, authorization
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1209600
Connection:close
Content-Length:0
Date:Fri, 31 Oct 2014 23:45:08 GMT
¿Anybody who maybe know where this error could come from?
ToDoListtype defined?@Injectis not supported by the server. Maybe look into that?