Send Ringtone Using JSMPP

In this article let's discuss about how to send ring tone sms using jsmpp.
It is very similar to the one we used in the article Send SMS Using JSMPP, except for UDH.

What is UDH?
User Data Header is a header message to be appended before the actual message.
UDH is not required for sending text sms. It is only required for sending binary message.

UDH description is as follows
1. 06 - length of whole UDH i.e. 6 octet, now each octet has two char so 050415811581 count to 6.
2. 05 - it represents a keyword for 16-bit nokia port addressing (according to smart messaging specification)
3. 04 - it tells the UDH that each port is represented using 4 characters
4. 1581 - This is the destination port number for Ring tone Message.
5. 1581 - It is the source port for Ring tone Message. Source port can also be 0000.

UDH port differs for other binary messages like image, business card and calendar messages. Here we have to convert the ring tone in to 2-bit hexa decimal format before sending it.

The following class is used to send ring tone sms using JSMPP.

SendRingTone.java

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSES ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;

import org.jsmpp.InvalidResponseException;
import org.jsmpp.PDUException;
import org.jsmpp.bean.Alphabet;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.ESMClass;
import org.jsmpp.bean.GeneralDataCoding;
import org.jsmpp.bean.MessageClass;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.RegisteredDelivery;
import org.jsmpp.bean.SMSCDeliveryReceipt;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.NegativeResponseException;
import org.jsmpp.extra.ResponseTimeoutException;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.SMPPSession;
import org.jsmpp.util.AbsoluteTimeFormatter;
import org.jsmpp.util.TimeFormatter;

public class SendRingTone
{
        private static TimeFormatter    timeFormatter   = new AbsoluteTimeFormatter();

        public void sendRingTone(String MSISDN, String message) throws Exception
        {
                String ringTone = message;

                RegisteredDelivery registeredDelivery = new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT);
                String refId = new String();

                ByteBuffer buf = null;
                buf = ByteBuffer.allocate(ringTone.getBytes().length + 7);
                buf.put((byte) 0x06);
                buf.put((byte) 0x05);
                buf.put((byte) 0x04);
                buf.putShort((short) 0x1581);
                buf.putShort((short) 0x0000);

                buf.put(ringTone.getBytes());

                ESMClass esmClass = new ESMClass((byte) 0x40);
                GeneralDataCoding generalDataCoding = new GeneralDataCoding(false, false, MessageClass.CLASS1,
                Alphabet.ALPHA_8_BIT);

                System.out.println("full ring tone message = " + new String(buf.array()));

                try
                {
                        refId = getSession().submitShortMessage(
                                "CMT",
                                TypeOfNumber.NATIONAL,
                                NumberingPlanIndicator.ISDN,
                                "9999999999",
                                TypeOfNumber.NATIONAL,
                                NumberingPlanIndicator.ISDN,
                                MSISDN,
                                esmClass,
                                (byte) 0,
                                (byte) 0,
                                timeFormatter.format(new Date()),
                                null,
                                registeredDelivery,
                                (byte) 0,
                                generalDataCoding,
                                (byte) 0,
                                buf.array());
                }
                catch (PDUException e)
                {

                }
                catch (ResponseTimeoutException e)
                {

                }
                catch (InvalidResponseException e)
                {

                }
                catch (NegativeResponseException e)
                {

                }
                catch (IOException e)
                {

                }
        }

        private SMPPSession getSession() throws Exception
        {
                BindParameter bindParam = new BindParameter(
                        BindType.BIND_TX,
                        "<userName>",
                        "<passWord>",
                        "tdd",
                        TypeOfNumber.UNKNOWN,
                        NumberingPlanIndicator.UNKNOWN,
                        null);
                return new SMPPSession("12.1.1.1", 80, bindParam);
        }

        public static void main(String[] args) throws Exception
        {
                SendRingTone sR = new SendRingTone();
                // sample ring tone message in hexadecimal format
                String message = "034AA3A5121D195CDD004001B201D550590610560558550548540820849900000";
                sR.sendRingTone("9500000000", message);
        }
}

Technology: 

Search