Feb 7th, 2011, 08:15 PM
Roo 1.1.1 JSON
I am using ROO 1.1.1 and I am trying to add JSON support using the JSON all command. This worked for the most part and with a get call using Accept=application/json I am able to get to the method in the controller successfully. I get an error though on the response saying it can't resolve the view. Do the need to content based view resolver? I did not think that was the case with Roo 1.1.1. I am not sure what I am missing. Any help would be appreciated.
This is the error I see
Could not resolve view with name '' in servlet.
Feb 8th, 2011, 03:29 PM
I believe this is related to how you send JSON document to the controller. The Roo documentation contains a section about the JSON integration which also shows the relevant CURL commands. Please use a traffic monitoring tool such as firebug to review if your JSON documents are correct.
Feb 8th, 2011, 03:39 PM
I am using what Roo generated without making any changes after running the json all command. So the JSON is just being sent from the generated JSON method in the controller which is in turn using the JSON serialization method generated on the underlying entity. It looks like the generated method on the controller is firing ok, but then an error occurs because a view cannot be found to handle the response. Since this was all generated by roo 1.1.1 I am not sure what I am missing or need to add manually to get it to work. I am using Firebug and running the app in debug mode so I can see the controller method being invoked properly. Thanks.
Feb 8th, 2011, 04:11 PM
I am not exactly sure what you expect here. If you do a curl request, do you receive a JSON document? If so, you need to send the same request from your view artifact and process the result accordingly.
It is up to you to write the processing code for JSON response in the view. Roo generates the controllers which accept and deliver JSON, it is up to you to integrate with that.
Feb 8th, 2011, 04:42 PM
Sorry for the confusion. I do not receive a JSON document back. I get a server error. I have written the client side code to invoke the view (which is working fine) and process the response (which is not because the response is not getting back). The controller method is being invoked successfully from my client page (I can see it on the server), but the response is never coming back to the client (CURL or otherwise) because following the controller method invocation on the server it is failing when going through the Spring view resolver because it cannot find a view to resolve to so it can send back the response. My question is do I need to manually add a view resolver in Spring config to handle this so the response is sent back correctly to my client? I thought roo handled this automatically, but I was unsure. Thanks for your help.
Feb 8th, 2011, 04:48 PM
Ok, we are getting a bit closer now .
If the controller does not return a JSON document then the request is not correct. most likely your request does not send the appropriate accept headers (the GET request needs to have the "Accept: application/json") header (please review this with firebug). The correctness of the URL might be another problem.
There is no need to register a special view resolver. The returned document is expected because all exceptions are rendered as html (as defined in webmvc-config.xml).
Feb 8th, 2011, 05:02 PM
Header is set to Accept: application/json (looks good in FireBug), when it was not set to that the JSON method on the controller was not getting invoked so I think we are good there. For some reason it is failing on the trip back on the server side.
Feb 8th, 2011, 05:11 PM
I don't see the @ResponseBody annotation on the JSON method, could that be part of the problem. The reference documentation shows it there in the example for a JSON controller method.
Feb 9th, 2011, 02:38 PM
That did it. Looks like the "json all" command did not add that annotation to the controller method for some reason.
Feb 9th, 2011, 03:07 PM
I have just tried the examples from our documentation again with Roo 1.1.1 and it all worked as advertised (the @ResponseBody annotations are also present on the HTTP GET methods).
Can you please open a bug ticket with your specific use case which causes the trouble you have seen?
Tags for this Thread