I faced this for days, even the accepted answer did not work, because it is just copy paste from documentation.
My problem was with the URL. I was taking the URL as provided by Request object by Java, but it was slightly different (encoded) from the URL sent by HubSpot.
To figure out the URL sent by HubSpot, go to your App > Monitoring > CRM Extensions. This is where I found the correct URL and it solved the issue for me.