Michael
Michael

Reputation: 2128

Spring request mapping with Paypal

For the return URL, it seem you have to define the whole URL like so:

String returnURL = "http://localhost:8080/appName/shopping/confirmorder";

Now, I have a problem with the request mapping:

    @RequestMapping(value = "/shopping/confirmorder?token={token}&PayerID={payerID}", method = RequestMethod.GET)
public String doGet(@PathVariable("token") String token, @PathVariable("payerID") String payerID,
        HttpServletRequest request) {

    // do stuff
}

The controller is never called for some reason?

The final returnURL returned from Paypal is like this:

http://localhost:8080/appName/shopping/confirmorder?token=EC-4...G&PayerID=A...W

Note the Ids have been edited.

Upvotes: 1

Views: 622

Answers (1)

JB Nizet
JB Nizet

Reputation: 692013

If you have two path variables named token and payerID, then the method signature should be

public void doGet(@PathVariable("token") String token, 
                  @PathVariable("payerID") String token, 
                  HttpServletRequest request, 
                  HttpServletResponse response)

How did you expect Spring to put those two strings inside a single option parameter of type int?

See http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates

Moreover, PathVariable is used to bind portions of the request path to method arguments. In your case, you have request parameters. You should thus use @RequestParam:

@RequestMapping(value = "/shopping/confirmorder", method = RequestMethod.GET)
public void doGet(@RequestParam("token") String token, 
                  @RequestParam("PayerID") String token, 
                  HttpServletRequest request, 
                  HttpServletResponse response)

See http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestparam

Upvotes: 1

Related Questions