34
34
public class Msg91SmsProvider implements ISmsProvider {
35
35
36
36
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" ;
37
40
38
41
private Map <String , String > configurations ;
39
42
@@ -51,18 +54,15 @@ private boolean sendSms(String mobileNumber, String smsText) {
51
54
// Send an SMS
52
55
logger .debug ("Msg91SmsProvider@Sending " + smsText + " to mobileNumber " + mobileNumber );
53
56
54
- String gateWayUrl = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_SMS_BASE_URL );
55
57
String authKey = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_AUTH_KEY );
56
58
String sender = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_SMS_SENDER );
57
59
String country = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_SMS_COUNTRY );
58
60
String smsMethodType = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_SMS_METHOD_TYPE );
59
61
String smsRoute = SMSConfigurationUtil .getConfigString (configurations , SmsConfigurationConstants .CONF_SMS_ROUTE );
60
62
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 );
63
63
64
64
logger .debug ("Msg91SmsProvider@SMS Provider parameters \n " +
65
- "Gateway - " + gateWayUrl + "\n " +
65
+ "Gateway - " + BASE_URL + "\n " +
66
66
"authKey - " + authKey + "\n " +
67
67
"sender - " + sender + "\n " +
68
68
"country - " + country + "\n " +
@@ -73,24 +73,18 @@ private boolean sendSms(String mobileNumber, String smsText) {
73
73
74
74
CloseableHttpClient httpClient = null ;
75
75
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
- }
82
76
83
77
httpClient = HttpClients .createDefault ();
84
78
85
79
String path = null ;
86
80
87
- if (!StringUtils .isNullOrEmpty (gateWayUrl ) && ! StringUtils . isNullOrEmpty ( sender ) && !StringUtils .isNullOrEmpty (smsRoute )
81
+ if (!StringUtils .isNullOrEmpty (sender ) && !StringUtils .isNullOrEmpty (smsRoute )
88
82
&& !StringUtils .isNullOrEmpty (mobileNumber ) && !StringUtils .isNullOrEmpty (authKey ) && !StringUtils .isNullOrEmpty (country )
89
83
&& !StringUtils .isNullOrEmpty (smsText )) {
90
84
91
85
if (httpMethod .equals (HttpMethod .GET )) {
92
86
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" ));
94
88
95
89
logger .debug ("Msg91SmsProvider -Executing request - " + path );
96
90
@@ -106,7 +100,7 @@ private boolean sendSms(String mobileNumber, String smsText) {
106
100
} else if (httpMethod .equals (HttpMethod .POST )) {
107
101
logger .debug ("Inside POST" );
108
102
109
- path = gateWayUrl + getPostPoint ;
103
+ path = BASE_URL + POST_URL ;
110
104
logger .debug ("Msg91SmsProvider -Executing request - " + path );
111
105
112
106
HttpPost httpPost = new HttpPost (path );
0 commit comments