0

I have a Spring Controller class set up with @RequestMapping("/vehicle") set at the class level. One method of this class is

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public Vehicle getVehicleByRegistration(
    @RequestParam(value="doAs", required = true) String doAsUser,
    @RequestParam(value="registration", required = true) String registration) throws IOException {

    return vehicleController.getByIndex(registration, doAsUser);
}

and I'm sending queries to it like:

curl -iv localhost:8096/vehicle/?doAs=user&registration=ABC1234

When executed, I get a response containing:

"exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'registration' is not present"

If I reverse the order of doAs and registration in the URL then the error says that 'doAs' is not present.

If I modify the method to only take one argument (either doAs or registration) then it works fine.

What's going wrong here? I've tried using param in the @RequestMapping but that doesn't work either.

1
  • Try removing the / after vehicle: curl -iv localhost:8096/vehicle?doAs=user&registration=ABC1234 Commented Jan 13, 2016 at 16:55

2 Answers 2

3

You're not protecting the ampersand from the shell, which is why you're also getting other weird shell output. Put the URL in quotes.

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

Comments

0

Try quoting the url you are passing to curl, in other post I saw that the ampersant was backgrounding the job. try:

curl -iv "localhost:8096/vehicle/?doAs=user&registration=ABC1234"

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.