'String java heap size security protection

If I expose a POST api to registered customers which takes in input a parameter "data", how can I prevent a malicious user to send a huge "data" such that my server will have heap problems ? I think that truncating the parameter at application level would be too late.. should I use an intrusion prevention system in front of my application ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source