Http 204 error in REST web service (Jersey) -
i using jersey/java develop rest services. need return xml representation carstore :
@xmlrootelement public class carstore { private list<car> cars; public list<car> getcars() { return cars; } public void setcars(list<car> cars) { this.cars = cars; }
here car object :
@xmlrootelement > public class car { private string carname; private specs carspecs; private category carcategory; public string getcarname() { return carname; } public void setcarname(string carname) { this.carname = carname; } public specs getcarspecs() { return carspecs; } public void setcarspecs(specs carspecs) { this.carspecs = carspecs; } public category getcarcategory() { return carcategory; } public void setcarcategory(category carcategory) { this.carcategory = carcategory; } }
specs , category enums :
@xmlrootelement > public enum category { sedans, compacts, wagons, hatch_hybrids, suvs, convertibles, comparable; }
my resource class :
@get @produces({mediatype.application_xml}) public carstore getcars() { return carstoremodel.instance.getallcars(); }
my jersey client :
webresource service = client.resource(getbaseuri()); system.out.println(service.path("rest").path("cars").accept( mediatype.application_xml).get(string.class));
i getting http 204 error on access alongwith client exception :
com.sun.jersey.api.client.uniforminterfaceexception
any ideas ? !
edit : have yet not developed model class...i initialized car objects dummy data , put them in carstore. showing classes here clumsy. btw, sorry writing 204 error..it getting exception led me think so.
i believe getting uniforminterfaceexception
because getcars()
function not returning http response body. root problem car list isn't being converted xml jaxb because missing @xmlelement
annotation.
your getcars() function should be:
@get @produces(mediatype.application_xml) public carstore getcars() { // mycarstore instance of carstore return mycarstore.getcars(); }
and car list in carstore should defined:
@xmlelement(name="car") private list<car> cars;
Comments
Post a Comment