0

I am trying to send a JSON string as a request to my application. This is my code:

@RequestMapping(
        value = "/mylink/upload",
        method = RequestMethod.POST,
        consumes ="application/json",
        produces = "application/json")
public
@ResponseBody
List<Upload> upload(
        @RequestParam(value = "hdfsLocation") String hdfsLocation

) throws Exception {
    return S3HdfsTransfer.uploadFromHDFS(hdfsLocation);
}

I am trying to send a request with Postman. The method I use is POST, the header contains: Accept "application/json",Content-Type "application/json", the request body is the following:

{
    "hdfsLocation" : "hdfs://145.160.10.10:8020"
}

This is the response I get. If I put the parameter in the URL, it works.

{
  "httpStatus": 500,
  "appErrorId": 0,
  "message": "Required String parameter 'hdfsLocation' is not present",
  "trackingId": "8c6d45fd-2da5-47ea-a213-3d4ea5764681"
}

Any idea what I am doing wrong?

Thanks, Serban

2
  • try to change your return type Commented Aug 24, 2015 at 8:19
  • can you remove the content-type and try Commented Aug 24, 2015 at 8:28

2 Answers 2

1

Looks like you have confused @RequestBody with @RequestParam. Do either of following :

I guess you over looked :)

Sign up to request clarification or add additional context in comments.

Comments

1

Shouldn't it be @RequestBody instead of @RequestParam? Also, even after using @RequestBody, the whole of the JSON string: { "hdfsLocation" : "hdfs://145.160.10.10:8020" } will be the value of String hdfsLocation and not just the hdfs url. Hence, you'll have to JSON parse that JSON by yourself to get just the hdfs url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.