1

Okay so I am using a payment service called Thrive cart, I am doing this for a membership website I'm creating. When the user has paid I want them to be redirected to a URL where I can use that data to update the current users information.

The data that get's sent in the params is insane:

http://localhost:5000/user/welcome?thrivecart%5Baccount_id%5D=3196&thrivecart%5Baccount_name%5D=testacount&thrivecart%5Bcustomer%5D%5Bemail%5D=testname8%40gmail.com&thrivecart%5Bcustomer%5D%5Baddress%5D%5Bcountry%5D=GB&thrivecart%5Bcustomer%5D%5Baddress%5D%5Bzip%5D=pe303wu&thrivecart%5Border%5D%5B0%5D%5Bt%5D=product&thrivecart%5Border%5D%5B0%5D%5Bid%5D=6&thrivecart%5Border%5D%5B0%5D%5Bn%5D=Monthly+membership&thrivecart%5Border%5D%5B0%5D%5Bp%5D=799&thrivecart%5Border%5D%5B0%5D%5Bq%5D=1&thrivecart%5Border%5D%5B0%5D%5Bpo%5D=60120&thrivecart%5Border%5D%5B1%5D%5Bt%5D=product&thrivecart%5Border%5D%5B1%5D%5Bid%5D=6&thrivecart%5Border%5D%5B1%5D%5Bn%5D=Monthly+membership&thrivecart%5Border%5D%5B1%5D%5Bp%5D=799&thrivecart%5Border%5D%5B1%5D%5Bq%5D=1&thrivecart%5Border%5D%5B1%5D%5Bpo%5D=60120&thrivecart%5Border_currency%5D=GBP&thrivecart%5Border_id%5D=1041278&thrivecart%5Border_tax%5D=0.2&thrivecart%5Border_tax_id%5D=gb&thrivecart%5Border_total%5D=799&thrivecart%5Bpayment_processor%5D=paypal&thrivecart%5Bproduct_id%5D=6&thrivecart%5Bpurchases%5D%5B0%5D=6&thrivecart%5Bpurchases%5D%5B1%5D=6&thrivecart_hash=a5b711d2288b4cb587511811bc0a3473

So far I've set up a simple controller which doesn't get hit:

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping(value = "/welcome", method = RequestMethod.POST)
    public void welcomeMember(@PathVariable String data) {

        System.out.println(data);
    }   
}

How do I deal with crazy data like this? Do I have to specific each path param?

user3667111
  • 611
  • 6
  • 21

3 Answers3

1

First of all, what you seem to get are not path elements but request parameters, so you will need @RequestParam annotations to get the values.

Since there are so many request parameters, I would also recommend to take just one parameter, a Map<String, String>. That Map will contain all the parameters as key/value pairs, for example:

  • key: "thrivecart[account_id]"
  • value: "3196"

If you're not sure whether you receive a POST or a GET request, you can also add a second parameter to receive the HttpMethod.

Change your RestController to:

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping(value = "/welcome")
    public void welcomeMember(@RequestParam Map<String, String> data, HttpMethod method) {
        System.out.println(method);
        System.out.println(data);
    }   
}
Thomas Kläger
  • 17,754
  • 3
  • 23
  • 34
  • @user3667111 maybe your not receiving a POST request but a GET request. I've updated the sample code so that it works with both POST and GET – Thomas Kläger Oct 27 '18 at 14:13
0

That looks like a problem with how the rest api is called from the service consumer side.

try sending the data in a request body rather then as a param. This way you can use a POJO to handle the data.

btshepo
  • 16
  • 5
0

Question 1: So far I've set up a simple controller which doesn't get hit:

As per your URL http://localhost:5000/user/welcome "user" seems to be your projects context name. Try removing @RequestMapping("/user") from your class.

Also, instead of@PathVariable String data use @RequestParam Map<String,String> params. @PathVariable String data is used when data is part of url but in your case it's parameter. Final code should be like below.

    @RestController
    public class UserController {
        @RequestMapping(value = "/welcome", method = RequestMethod.POST)
        public void welcomeMember(@RequestParam Map<String,String> params ) {
            for(Map.Entry<String, String> entry : params.entrySet()){
             //This will print all paramters name and their value
             System.out.println(entry.getKey() + "-" + entry.getValue());
            }
        }   
    }

Question 2: How do I deal with crazy data like this? Do I have to specific each path param?

I will suggest to follow standard practice. Send data in json format. There are different ways for this depend upon front end technology you are using. One way is Link

Rupesh S.
  • 41
  • 7