Announcement Announcement Module
Collapse
No announcement yet.
Roo 1.1.1 JSON Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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.

    http://static.springsource.org/sprin...html#base-json

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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).

            Comment


            • #7
              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.

              Comment


              • #8
                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.

                Comment


                • #9
                  That did it. Looks like the "json all" command did not add that annotation to the controller method for some reason.

                  Comment


                  • #10
                    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?

                    Comment


                    • #11
                      I will do that. Maybe it has something to do with the order the controller command and the JSON command are invoked. Thanks for your help.

                      Comment


                      • #12
                        Hi there,

                        I'm facing the same problem.
                        I did the following steps:
                        1. I created the entities and fields
                        Code:
                        entity --class ~.domain.Product --testAutomatically
                        field string --fieldName name --notNull --sizeMin 2
                        2. added mvc
                        Code:
                        controller all --package ~.web
                        3. updated my entitites (also added new ones)
                        4. added a finder
                        Code:
                        finder add --class ~.domain.Product --finderName findProductsByClient
                        5. added json support
                        Code:
                        json add --class ~.domain.Product
                        the generated method in the controller looks like this:
                        Code:
                            @RequestMapping(params = "find=ByClient", method = RequestMethod.GET, headers = "Accept=application/json")
                            public String ProductController.jsonFindProductsByClient(@RequestParam("client") Client client) {
                                return Product.toJsonArray(Product.findProductsByClient(client).getResultList());
                            }
                        For a workaround, I copied the method to my controller and added the @ResponseBody Annotation.

                        I'm using roo 1.2.2.
                        Is there already a issue for that (I did not find anything related) or should I start a new one?

                        Comment

                        Working...
                        X