Sunday 15 May 2011

Angularjs GET http request to REST server returns 500 (Internal Server Error) -



Angularjs GET http request to REST server returns 500 (Internal Server Error) -

i have restful web service acts repository of todo tasks.

on other hand have web application uses rest server managing todo repository.

i've tried first phone call client server in order retrieve data, fails.

the code in rest server follows:

/** * service manipulates todo's in repository. * */ @path("/todolist") public class todowebservice { /** * (shared) repository object. */ @inject todolist todolist; /** * /todos request should homecoming todo's repository in json. * @return json representation of todo's repository. */ @get @produces(mediatype.application_json) public todolist gettodolist() { homecoming todolist; } ....

and client phone 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 server homecoming 500 (internal server error)

this phone call it's made when click on "addtodo" tab of web application, , can see result of phone call in console, error in case.

but remarkable thing when alter rest server code:

@get @produces(mediatype.text_plain) public string gettodolist() { homecoming "it's me, illustration text"; }

then, returns correctly string "it's me, illustration text".

i've checked libaries included in i've checked libaries included in build.gradle file , server classes on , on again, finding no solution @ all.

this headers of http request-response, seems in order, except 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, 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 maybe know error come from?

the problem lies in pojo. must provide 0 argument constructor todo class. moxy marshaller pojo json requires 0 argument constructor.

public class todo { private string task; //task description private string context; //task context private string project; //task project private int priority; //task priority private uri href; private int id; // add together this!!!! public todo(){ } //constructor public todo(string task,string ctx,string proj,int pri){ this.task = task; this.context = ctx; this.project = proj; this.priority = pri; } {... code go on here ...} }

angularjs rest http jax-rs

No comments:

Post a Comment