2

In my application I have to compare 3 products for that in my controller I mapped request as

@RequestMapping(value = "/products/{proId1}Vs{proId2}Vs{proId3}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2, @PathVariable("proId3") int id3)
{
   //someLogic

when hit my url(http://something/products/12Vs13Vs14)

I'm getting http 400 error

I also tried for 2 @pathVariable like

@RequestMapping(value = "/products/{proId1}Vs{proId2}", method = RequestMethod.GET)
public ModelAndView compareTwoProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2) 

this is working fine but why i'm facing problem with 3 variables and also there are no errors in server log then how to find what's the bug.

any solution??

3
  • Please show us header of methods. Also are you sure that one of your products doesn't have Vs string in it's name? Commented Aug 11, 2011 at 15:27
  • I changed my post as u asked. I'm using Integers not strings Commented Aug 11, 2011 at 16:21
  • I can confirm the problem for Spring 4, only using slashes as separators. Commented Jan 9, 2014 at 9:25

3 Answers 3

3

How about explicitly specifying the regex you want each path variable to match, as described here?

@RequestMapping(value = "/products/{proId1:\d+}Vs{proId2:\d+}Vs{proId3:\d+}", method = RequestMethod.GET)

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

Comments

1

You could try lumping everything into one path variable then parsing it manually:

@RequestMapping(value = "/products/{compareIdString}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("compareIdString") String compareIdString)
{
    // split compareIdString on "Vs"
    // parse each resulting value to an int

This is more of a workaround than a solution, though. You might want to debug in the Spring code as Bozho suggested if you want to try to figure out exactly what's going wrong.

Comments

0
  • make sure the problem is not in the response - put a breakpoint in the method and see if it is invoked
  • check log files for any indications
  • try using slashes as separator /products/{p1}/{p2}/{p3} or /products/{p1}/vs/{p2}/vs/{p3}

8 Comments

I searched all my log files I didn't find any errors.. The only error i'm getting is http status 400(The request sent by the client was syntactically incorrect ().)
then try the other two points. And also - could you check with firebug what does the request look like?
Sorry to say that as our project requirement I have to use 'Vs' must.. any other solution..
But try it without Vs, only for the sake of experiment and identifying the issue.
then fire a bug in the spring issue tracker, and use slashes (you can have 12/vs/23/vs/34 for example.
|

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.