I have written a number of REST web services using Spring 3.1 and the REST support introduced int 3.x. I have no issue accessing these services with something like JQuery when originating from the same domain in which these services are deployed.
However, I have been running into issues trying to access these from different domains via a JSONP request. I have been looking through the forums to see what others have done in this scenario, but I don't seem to be finding anyone doing this.
Does anyone have any insight on what I need to do differently to my REST Services to allow them to be accessible via a JSONP request?
Here are a few of my endpoints in my controller.
When I try to call these via a JSONP request with jquery, in firebug or chrome inspector, I never seem to be able to set the content type to 'application/json' or 'application/xml' so these are never getting executed. So the end up erroring out because these same endpoints also return an html view, and that is what gets returned on a JSONP request.Code:@RequestMapping( method = RequestMethod.GET, consumes = { "application/json" }, produces = { "application/json" } ) public @ResponseBody List<Restaurant> restaurantsJson() { return service.list(); } @RequestMapping( method = RequestMethod.GET, consumes = { "application/xml", "text/xml" }, produces = { "application/xml", "text/xml" } ) public @ResponseBody List<Restaurant> restaurantsXml() { return service.list(); } @RequestMapping( value = "{restaurantId}", method = RequestMethod.GET, consumes = { "application/json" }, produces = { "application/json" } ) public @ResponseBody Restaurant restaurantJson( @PathVariable Long restaurantId ) { return service.findById( restaurantId ); } @RequestMapping( value = "{restaurantId}", method = RequestMethod.GET, consumes = { "application/xml", "text/xml" }, produces = { "application/xml", "text/xml" } ) public @ResponseBody Restaurant restaurantXml( @PathVariable Long restaurantId ) { return service.findById( restaurantId ); }
Thanks for any assistance.


Reply With Quote