Skip to content

Commit 9a5584e

Browse files
committed
Issue #12 chores: Provider configurations refactoring, removed gateWayUrl, getUrl, postUrl from config
1 parent cb4d646 commit 9a5584e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

keycloak/sms-provider/src/main/java/org/sunbird/sms/msg91/Msg91SmsProvider.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
public class Msg91SmsProvider implements ISmsProvider {
3535

3636
private static Logger logger = Logger.getLogger(Msg91SmsProvider.class);
37+
private static String BASE_URL = "http://api.msg91.com/";
38+
private static String GET_URL = "api/sendhttp.php?";
39+
private static String POST_URL = "api/v2/sendsms";
3740

3841
private Map<String, String> configurations;
3942

@@ -51,18 +54,15 @@ private boolean sendSms(String mobileNumber, String smsText) {
5154
// Send an SMS
5255
logger.debug("Msg91SmsProvider@Sending " + smsText + " to mobileNumber " + mobileNumber);
5356

54-
String gateWayUrl = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_BASE_URL);
5557
String authKey = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_AUTH_KEY);
5658
String sender = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_SENDER);
5759
String country = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_COUNTRY);
5860
String smsMethodType = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_METHOD_TYPE);
5961
String smsRoute = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_ROUTE);
6062
String httpMethod = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_METHOD_TYPE);
61-
String getUrlPoint = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_GET_URL);
62-
String getPostPoint = SMSConfigurationUtil.getConfigString(configurations, SmsConfigurationConstants.CONF_SMS_POST_URL);
6363

6464
logger.debug("Msg91SmsProvider@SMS Provider parameters \n" +
65-
"Gateway - " + gateWayUrl + "\n" +
65+
"Gateway - " + BASE_URL + "\n" +
6666
"authKey - " + authKey + "\n" +
6767
"sender - " + sender + "\n" +
6868
"country - " + country + "\n" +
@@ -73,24 +73,18 @@ private boolean sendSms(String mobileNumber, String smsText) {
7373

7474
CloseableHttpClient httpClient = null;
7575
try {
76-
URL smsURL = (gateWayUrl != null && gateWayUrl.length() > 0) ? new URL(gateWayUrl) : null;
77-
78-
if (smsURL == null) {
79-
logger.error("Msg91SmsProvider@ SMS gateway URL is not configured.");
80-
return false;
81-
}
8276

8377
httpClient = HttpClients.createDefault();
8478

8579
String path = null;
8680

87-
if (!StringUtils.isNullOrEmpty(gateWayUrl) && !StringUtils.isNullOrEmpty(sender) && !StringUtils.isNullOrEmpty(smsRoute)
81+
if (!StringUtils.isNullOrEmpty(sender) && !StringUtils.isNullOrEmpty(smsRoute)
8882
&& !StringUtils.isNullOrEmpty(mobileNumber) && !StringUtils.isNullOrEmpty(authKey) && !StringUtils.isNullOrEmpty(country)
8983
&& !StringUtils.isNullOrEmpty(smsText)) {
9084

9185
if (httpMethod.equals(HttpMethod.GET)) {
9286
logger.debug("Inside GET");
93-
path = getCompletePath(gateWayUrl + getUrlPoint, sender, smsRoute, KeycloakSmsAuthenticatorUtil.setDefaultCountryCodeIfZero(mobileNumber), authKey, country, URLEncoder.encode(smsText, "UTF-8"));
87+
path = getCompletePath(BASE_URL + GET_URL, sender, smsRoute, KeycloakSmsAuthenticatorUtil.setDefaultCountryCodeIfZero(mobileNumber), authKey, country, URLEncoder.encode(smsText, "UTF-8"));
9488

9589
logger.debug("Msg91SmsProvider -Executing request - " + path);
9690

@@ -106,7 +100,7 @@ private boolean sendSms(String mobileNumber, String smsText) {
106100
} else if (httpMethod.equals(HttpMethod.POST)) {
107101
logger.debug("Inside POST");
108102

109-
path = gateWayUrl + getPostPoint;
103+
path = BASE_URL + POST_URL;
110104
logger.debug("Msg91SmsProvider -Executing request - " + path);
111105

112106
HttpPost httpPost = new HttpPost(path);

0 commit comments

Comments
 (0)