Skip to content

Commit

Permalink
Added the url decoder to avoid double encoding for SMS
Browse files Browse the repository at this point in the history
Signed-off-by: Aravindhan Alagesan <[email protected]>
  • Loading branch information
aranaravi committed Jan 11, 2024
1 parent 0f164c6 commit 1a832d8
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.mosip.kernel.core.util.StringUtils;
import io.mosip.kernel.smsserviceprovider.msg91.constant.SmsExceptionConstant;
import io.mosip.kernel.smsserviceprovider.msg91.constant.SmsPropertyConstant;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
* @author Ritesh Sinha
Expand Down Expand Up @@ -61,14 +63,16 @@ public SMSResponseDto sendSms(String contactNumber, String message) {
validateInput(contactNumber);
UriComponentsBuilder sms = UriComponentsBuilder.fromHttpUrl(api)
.queryParam(SmsPropertyConstant.AUTH_KEY.getProperty(), authkey)
.queryParam(SmsPropertyConstant.SMS_MESSAGE.getProperty(), message)
.queryParam(SmsPropertyConstant.SMS_MESSAGE.getProperty(), message.replaceAll("\\#", "%23"))
.queryParam(SmsPropertyConstant.ROUTE.getProperty(), route)
.queryParam(SmsPropertyConstant.SENDER_ID.getProperty(), sender)
.queryParam(SmsPropertyConstant.RECIPIENT_NUMBER.getProperty(), contactNumber)
.queryParam(SmsPropertyConstant.UNICODE.getProperty(), unicode)
.queryParam(SmsPropertyConstant.COUNTRY_CODE.getProperty(), countryCode);
try {
restTemplate.getForEntity(sms.toUriString(), String.class);
//restTemplate.getForEntity(sms.toUriString(), String.class);
/*Added the url decoder to avoid double encoding*/
restTemplate.getForEntity(URLDecoder.decode(sms.toUriString(), StandardCharsets.UTF_8), String.class);
} catch (HttpClientErrorException | HttpServerErrorException e) {
throw new RuntimeException(e.getResponseBodyAsString());
}
Expand Down

0 comments on commit 1a832d8

Please sign in to comment.