From 1a832d8c4cdd59e3fced3f1200e97de2315c0291 Mon Sep 17 00:00:00 2001 From: Aravindhan Alagesan Date: Thu, 11 Jan 2024 10:50:38 +0530 Subject: [PATCH] Added the url decoder to avoid double encoding for SMS Signed-off-by: Aravindhan Alagesan --- .../msg91/impl/SMSServiceProviderImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/kernel-smsserviceprovider-msg91/src/main/java/io/mosip/kernel/smsserviceprovider/msg91/impl/SMSServiceProviderImpl.java b/kernel/kernel-smsserviceprovider-msg91/src/main/java/io/mosip/kernel/smsserviceprovider/msg91/impl/SMSServiceProviderImpl.java index e0315a1eb02..3e46490a2aa 100644 --- a/kernel/kernel-smsserviceprovider-msg91/src/main/java/io/mosip/kernel/smsserviceprovider/msg91/impl/SMSServiceProviderImpl.java +++ b/kernel/kernel-smsserviceprovider-msg91/src/main/java/io/mosip/kernel/smsserviceprovider/msg91/impl/SMSServiceProviderImpl.java @@ -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 @@ -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()); }