Tuesday 6 May 2014

SMS Notification/Sending Integration...Part 1

Recently i was faced with client request to integrate sms sending to an existing application.
i had not done it before but i knew it is possible.

The application is a web based application hosted by a third party hosting company.

The sms notification to registering clients must
1. send sms notification to clients on successful registration informing them of date of start of service
2. auto send sms reminders to clients some days before start of service
3. auto send sms  reminders to clients some days before end/expiry of service
4. send custom sms notification to selected clients

Presentation/Logic:
JSF 2.1
Primefaces 4.0
DAO, Javabeans

Container:
Apache Tomcat 7.0 (production).
Weblogic (development).

Database:
MySQL (production)
Oracle (development)

SMS Gateway:
Clickatell SMS gateway transport

Third party:
Quartz job scheduler (attached to the web servlet listener and register reminder)
Quartz 2.2.1

IDE
Jdeveloper
Netbeans
















Code snippets
/*****
*Manage bean exposes the sendsms to client
****/
    private final void SendSMS() {
        try {
            Date d = new Date();
            d.setTime(pet.getCurrent_date_of_enrolment().getTime() + globalsettings().getIncubation_period() * 60 * 60 * 24 * 1000);

            AlertInfoDetailEntity alertinfo = new AlertInfoDetailEntity();
            alertinfo = aldsr.AlertInfoDetail("Registration");

            SMSGatewayEntity smsgateway = new SMSGatewayEntity();
            smsgateway = smdsr.SMSGateway();
            SMSender SendSMS =  new SMSender(smsgateway.getSms_gateway_username(), smsgateway.getSms_gateway_password(),
                                                smsgateway.getSms_gateway_apiid(), smsgateway.getSms_gateway_name());

            SendSMS.SendSMSText_NoSSL(alertinfo.getAlert_message().replaceAll("<client_name>",
                                                                              pee.getFirstname() + " " +
                                                                              pee.getSurname()).replaceAll("<enrolment_uid>",
                                                                                                           pee.getEnrolment_uid()).replaceAll("<start_date>",
               new SimpleDateFormat("dd/MMM/yyyy").format(d)), "234" + pee.getPhone_number().replaceAll("-", "").trim(), "CHIEASY");
              
              addMessageInfo("SMS Notification Sent Successfully.");


        } catch (SmsException cfe) {

            addMessageError("Error Sending SMS..." + cfe.getMessage().replaceAll("Clickatell", "SMS Gateway"));
            logger.log(logger.getLevel().SEVERE, cfe.getMessage());
            cfe.printStackTrace();
        } catch (IOException cfe) {
            addMessageError("Error Sending SMS..." + cfe.getMessage());
            logger.log(logger.getLevel().SEVERE, cfe.getMessage());

        } catch (ConfigurationException cfe) {
            addMessageError("Error Sending SMS..." + cfe.getMessage());
            logger.log(logger.getLevel().SEVERE, cfe.getMessage());

        }

    }





2 comments:

  1. Thanks for posting this.
    Can you share SendSMS.SendSMSText_NoSSL(...)?

    ReplyDelete
  2. Thanks for sharing
    Msgclub have two types of sms api Java; XML and JSON for sending SMS in bulk to your prospects from our gateway.
    bulk SMS API

    ReplyDelete

A hybrid Android and IOS Mobile Chat app

Project :   Development of a simple extensible chat  Technologies and Frameworks Oracle Mobile Application Framework (MAF) Oracle Java ...