I have come across similar questions but they don't seem to offer a direct example of doing it. I am trying to use RestTemplate to GET with an encoded url. I have an amazon class helper to generate a signed url but returns the url encoded so when I use it in RestTemplate it is encoded again. The url I am supposed to feed into RestTemplate should look like this;
http://webservices.amazon.com/onca/xml?AWSAccessKeyId=REMOVED&AssociateTag=REMOVED&Keywords=php&Operation=ItemSearch&ResponseGroup=Images,ItemAttributes,Offers&SearchIndex=All&Service=AWSECommerceService&Timestamp=2017-09-05T06:47:25.703Z&Signature=dthAE5BwmK2aZmSoIPRBwsPgCNwIv6JnXoqjC0QyRCQ=
But my amazon helper gives me this;
http://webservices.amazon.com/onca/xml?AWSAccessKeyId=REMOVED&AssociateTag=REMOVED&Keywords=php&Operation=ItemSearch&ResponseGroup=Images%2CItemAttributes%2COffers&SearchIndex=All&Service=AWSECommerceService&Timestamp=2017-09-05T06%3A47%3A25.703Z&Signature=dthAE5BwmK2aZmSoIPRBwsPgCNwIv6JnXoqjC0QyRCQ%3D
Which is again encoded breaking my timestamp. I see I could very easily use string replace but I looking for a better way of doing it.
My code looks like this;
SignedRequestsHelper helper;
try {
helper = SignedRequestsHelper.getInstance(this.ENDPOINT, this.ACCESS_KEY_ID, this.SECRET_KEY);
} catch (Exception e) {
return "ERROR";
//e.printStackTrace();
}
String requestUrl = null;
Map<String, String> params = new HashMap<String, String>();
...
requestUrl = helper.sign(params);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new ResponseErrorHandler());
...
try {
String response = restTemplate.getForObject(requestUrl, String.class);
} catch (HttpStatusCodeException exception) {
return exception.getStatusCode().toString();
}