Search in sources :

Example 1 with Address

use of org.smpp.pdu.Address in project opensmpp by OpenSmpp.

the class SMPPSender method submit.

/**
 * Creates a new instance of <code>SubmitSM</code> class, lets you set
 * subset of fields of it. This PDU is used to send SMS message
 * to a device.
 *
 * See "SMPP Protocol Specification 3.4, 4.4 SUBMIT_SM Operation."
 * @see Session#submit(SubmitSM)
 * @see SubmitSM
 * @see SubmitSMResp
 */
private void submit(String destAddress, String shortMessage, String sender, byte senderTon, byte senderNpi) {
    try {
        SubmitSM request = new SubmitSM();
        SubmitSMResp response;
        // set values
        request.setServiceType(serviceType);
        if (sender != null) {
            if (sender.startsWith("+")) {
                sender = sender.substring(1);
                senderTon = 1;
                senderNpi = 1;
            }
            if (!sender.matches("\\d+")) {
                senderTon = 5;
                senderNpi = 0;
            }
            if (senderTon == 5) {
                request.setSourceAddr(new Address(senderTon, senderNpi, sender, 11));
            } else {
                request.setSourceAddr(new Address(senderTon, senderNpi, sender));
            }
        } else {
            request.setSourceAddr(sourceAddress);
        }
        if (destAddress.startsWith("+")) {
            destAddress = destAddress.substring(1);
        }
        request.setDestAddr(new Address((byte) 1, (byte) 1, destAddress));
        request.setReplaceIfPresentFlag(replaceIfPresentFlag);
        request.setShortMessage(shortMessage, Data.ENC_GSM7BIT);
        request.setScheduleDeliveryTime(scheduleDeliveryTime);
        request.setValidityPeriod(validityPeriod);
        request.setEsmClass(esmClass);
        request.setProtocolId(protocolId);
        request.setPriorityFlag(priorityFlag);
        request.setRegisteredDelivery(registeredDelivery);
        request.setDataCoding(dataCoding);
        request.setSmDefaultMsgId(smDefaultMsgId);
        // send the request
        request.assignSequenceNumber(true);
        System.out.println("Submit request " + request.debugString());
        response = session.submit(request);
        System.out.println("Submit response " + response.debugString());
        messageId = response.getMessageId();
        enquireLink();
    } catch (Exception e) {
        System.out.println("Submit operation failed. " + e);
    }
}
Also used : SubmitSMResp(org.smpp.pdu.SubmitSMResp) Address(org.smpp.pdu.Address) SubmitSM(org.smpp.pdu.SubmitSM) IOException(java.io.IOException) WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException)

Aggregations

IOException (java.io.IOException)1 Address (org.smpp.pdu.Address)1 SubmitSM (org.smpp.pdu.SubmitSM)1 SubmitSMResp (org.smpp.pdu.SubmitSMResp)1 WrongLengthOfStringException (org.smpp.pdu.WrongLengthOfStringException)1