Search in sources :

Example 1 with SubmitSM

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

the class DeliveryInfoSender method deliver.

private void deliver(DeliveryInfoEntry entry) {
    debug.enter(this, "deliver");
    SubmitSM submit = entry.submit;
    DeliverSM deliver = new DeliverSM();
    deliver.setEsmClass((byte) Data.SM_SMSC_DLV_RCPT_TYPE);
    deliver.setSourceAddr(submit.getDestAddr());
    deliver.setDestAddr(submit.getDestAddr());
    // ISO-Latin-1
    deliver.setDataCoding((byte) 0x03);
    String msg = "";
    msg += "id:" + entry.messageId + " ";
    msg += "sub:" + entry.sub + " ";
    msg += "dlvrd:" + entry.dlvrd + " ";
    msg += "submit date:" + formatDate(entry.submitted) + " ";
    msg += "done date:" + formatDate(System.currentTimeMillis()) + " ";
    msg += "stat:" + states[entry.stat] + " ";
    msg += "err:" + entry.err + " ";
    String shortMessage = submit.getShortMessage();
    int msgLen = shortMessage.length();
    msg += "text:" + shortMessage.substring(0, (msgLen > 20 ? 20 : msgLen));
    try {
        deliver.setShortMessage(msg);
        deliver.setServiceType(submit.getServiceType());
    } catch (WrongLengthOfStringException e) {
    }
    try {
        entry.processor.serverRequest(deliver);
    } catch (Exception e) {
    }
    debug.exit(this);
}
Also used : WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) SubmitSM(org.smpp.pdu.SubmitSM) WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) DeliverSM(org.smpp.pdu.DeliverSM)

Example 2 with SubmitSM

use of org.smpp.pdu.SubmitSM 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

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