Results 1 to 2 of 2

Thread: controller with createFromJson accepts Content-Type: anything and fails

  1. #1

    Default controller with createFromJson accepts Content-Type: anything and fails

    Hi all,

    I am playing with "json add" to my entity managing controllers (roo 1.1.5, hibernate 3.6.4, spring 3.0.5, sts 2.8.1) . The *_ROO_Controller_Json ITD contains a method createFromJson:

    Code:
    @RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
        public ResponseEntity<String> DataController.createFromJson(@RequestBody String json) { ...
    when doing a
    Code:
     > curl -i -X POST -H 'Accept: application/json' -d @document.json http://localhost:8080/application/datas
    the json string will be empty because the Content-Type of the request is application/x-www-form-urlencoded. It is not picked up by the @RequestBody. You will see a FlexJson error: "Stepping back two steps is not supported" accompanied by a nice stack trace.

    The request with the Content-Type:
    Code:
     > curl -i -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d @document.json http://localhost:8080/application/datas
    works fine.

    Should the @RequestMapping of the Controller ITD refuse Content-Types which are not application/json with a nice 404 or similar?

    I have tried this
    Code:
        @RequestMapping(method = RequestMethod.POST, headers = {"accept=application/json","content-type=application/json"})
    but it did not work. Are multiple headers allowed?

    Or should the ITD template check if the json string is empty or null before calling the fromJsonToData method on the corresponding entity?

    Cheers
    Carsten
    Last edited by carsten.steckel; Feb 1st, 2012 at 03:05 PM. Reason: updated the used tools and versions

  2. #2

    Default

    I have successfully upgraded to roo 1.2. Now it works as expected.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •