Search in sources :

Example 1 with BaseSm

use of com.cloudhopper.smpp.pdu.BaseSm in project smscgateway by RestComm.

the class MessageDeliveryResultResponseSmpp method responseDeliverySuccess.

@Override
public void responseDeliverySuccess() {
    PduResponse response = null;
    BaseSm event = null;
    if (eventSubmit != null) {
        event = eventSubmit;
        SubmitSmResp responseSubmit = eventSubmit.createResponse();
        response = responseSubmit;
        responseSubmit.setMessageId(((Long) messageId).toString());
    }
    if (eventData != null) {
        event = eventData;
        DataSmResp responseData = eventData.createResponse();
        response = responseData;
        responseData.setMessageId(((Long) messageId).toString());
    }
    // Lets send the Response with success here
    try {
        if (response != null) {
            this.smppSessions.sendResponsePdu(esme, event, response);
        }
    } catch (Throwable e) {
        this.logger.severe("Error while trying to send SubmitSmResponse=" + response, e);
    }
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) SubmitSmResp(com.cloudhopper.smpp.pdu.SubmitSmResp) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) DataSmResp(com.cloudhopper.smpp.pdu.DataSmResp)

Example 2 with BaseSm

use of com.cloudhopper.smpp.pdu.BaseSm in project smscgateway by RestComm.

the class MessageDeliveryResultResponseSmpp method responseDeliveryFailure.

@Override
public void responseDeliveryFailure(DeliveryFailureReason reason, MAPErrorMessage errMessage) {
    PduResponse response = null;
    BaseSm event = null;
    if (eventSubmit != null) {
        event = eventSubmit;
        SubmitSmResp responseSubmit = eventSubmit.createResponse();
        response = responseSubmit;
        responseSubmit.setMessageId(((Long) messageId).toString());
    }
    if (eventData != null) {
        event = eventData;
        DataSmResp responseData = eventData.createResponse();
        response = responseData;
        responseData.setMessageId(((Long) messageId).toString());
    }
    response.setCommandStatus(SmppConstants.STATUS_DELIVERYFAILURE);
    if (reason != null) {
        byte[] value = new byte[1];
        value[0] = (byte) reason.getCode();
        Tlv tlv = new Tlv(SmppConstants.TAG_DELIVERY_FAILURE_REASON, value);
        response.addOptionalParameter(tlv);
    }
    // Lets send the Response with success here
    try {
        if (response != null) {
            this.smppSessions.sendResponsePdu(esme, event, response);
        }
    } catch (Throwable e) {
        this.logger.severe("Error while trying to send SubmitSmResponse=" + response, e);
    }
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) SubmitSmResp(com.cloudhopper.smpp.pdu.SubmitSmResp) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) DataSmResp(com.cloudhopper.smpp.pdu.DataSmResp) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 3 with BaseSm

use of com.cloudhopper.smpp.pdu.BaseSm in project smscgateway by RestComm.

the class ClientSmppSessionHandler method firePduRequestReceived.

// private int incMsgCnt = 0;
@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
    // incMsgCnt++;
    // if (incMsgCnt > 150) {
    // incMsgCnt = 0;
    // try {
    // Thread.sleep(60000);
    // } catch (InterruptedException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // }
    testingForm.addMessage("PduRequestReceived: " + pduRequest.getName(), pduRequest.toString());
    this.testingForm.messagesRcvd.incrementAndGet();
    PduResponse resp = pduRequest.createResponse();
    // here we can insert responses
    if (pduRequest.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM || pduRequest.getCommandId() == SmppConstants.CMD_ID_DATA_SM || pduRequest.getCommandId() == SmppConstants.CMD_ID_SUBMIT_SM) {
        if (pduRequest instanceof BaseSm) {
            BaseSm dev = (BaseSm) pduRequest;
            byte[] data = dev.getShortMessage();
            if (dev.getShortMessageLength() == 0) {
                // Probably the message_payload Optional Parameter is being used
                Tlv messagePaylod = dev.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
                if (messagePaylod != null) {
                    data = messagePaylod.getValue();
                }
            }
            DataCodingScheme dcs = new DataCodingSchemeImpl(dev.getDataCoding());
            boolean udhPresent = (dev.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
            byte[] textPart = data;
            byte[] udhData = null;
            if (udhPresent && data.length > 2) {
                // UDH exists
                int udhLen = (data[0] & 0xFF) + 1;
                if (udhLen <= data.length) {
                    textPart = new byte[textPart.length - udhLen];
                    udhData = new byte[udhLen];
                    System.arraycopy(data, udhLen, textPart, 0, textPart.length);
                    System.arraycopy(data, 0, udhData, 0, udhLen);
                }
            }
            String s = null;
            switch(dcs.getCharacterSet()) {
                case GSM7:
                case UCS2:
                    if (this.testingForm.getSmppSimulatorParameters().getSmppEncoding() == 0) {
                        s = new String(textPart, utf8Charset);
                    } else if (this.testingForm.getSmppSimulatorParameters().getSmppEncoding() == 1) {
                        s = new String(textPart, ucs2Charset);
                    } else {
                        GSMCharsetDecoder decoder = (GSMCharsetDecoder) gsm7Charset.newDecoder();
                        decoder.setGSMCharsetDecodingData(new GSMCharsetDecodingData(Gsm7EncodingStyle.bit8_smpp_style, Integer.MAX_VALUE, 0));
                        ByteBuffer bb = ByteBuffer.wrap(textPart);
                        CharBuffer bf = null;
                        try {
                            bf = decoder.decode(bb);
                        } catch (CharacterCodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        s = bf.toString();
                    }
                    break;
                case GSM8:
                    s = new String(textPart, isoCharset);
                    break;
            }
            String s2 = "";
            if (udhData != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("[");
                int i2 = 0;
                for (byte b : udhData) {
                    int i1 = (b & 0xFF);
                    if (i2 == 0)
                        i2 = 1;
                    else
                        sb.append(", ");
                    sb.append(i1);
                }
                sb.append("] ");
                s2 = sb.toString();
            }
            testingForm.addMessage("TextReceived: ", s2 + s);
        // try {
        // Thread.sleep(1000);
        // } catch (InterruptedException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
        }
        if (this.testingForm.getSmppSimulatorParameters().isRejectIncomingDeliveryMessage()) {
            resp.setCommandStatus(1);
        }
        long mId = this.testingForm.getMsgIdGenerator().incrementAndGet();
        String msgId;
        String msgId2;
        String msgId3;
        if (this.testingForm.getSmppSimulatorParameters().isIdResponseTlv()) {
            msgId = String.format("%08X", mId);
            msgId2 = MessageUtil.createMessageIdString(mId);
            msgId3 = msgId;
            if (this.testingForm.getSmppSimulatorParameters().isWrongMessageIdInDlr())
                msgId3 = msgId3 + "XYZ";
        } else {
            msgId = MessageUtil.createMessageIdString(mId);
            msgId2 = MessageUtil.createMessageIdString(mId);
            if (this.testingForm.getSmppSimulatorParameters().isWrongMessageIdInDlr())
                msgId2 = msgId2 + "XYZ";
            msgId3 = null;
        }
        MessageState msgState = null;
        if (this.testingForm.getSmppSimulatorParameters().isIdResponseTlvMessageState()) {
            if (this.testingForm.getSmppSimulatorParameters().isRejectIncomingDeliveryMessage())
                // message will have message_state set to REJECTED (value 8)
                msgState = MessageState.REJECTED;
            else if (this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating().equals(DeliveryResponseGenerating.Error8)) {
                // message will have message_state set to UNDELIVERABLE (value 5)
                msgState = MessageState.UNDELIVERABLE;
            } else {
                // message should have message_state set to DELIVERED (value 2)
                msgState = MessageState.DELIVERED;
            }
        }
        if (!(pduRequest instanceof DeliverSm) || this.testingForm.getSmppSimulatorParameters().isAddMessageIdIntoDeliverySmResp()) {
            ((BaseSmResp) resp).setMessageId(msgId);
        }
        // scheduling of delivery receipt if needed
        if (this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating() != DeliveryResponseGenerating.No) {
            int delay = 100;
            if (this.testingForm.getSmppSimulatorParameters().isDeliveryResponseAfter2Min())
                delay = 2 * 60 * 1000;
            this.testingForm.getExecutor().schedule(new DeliveryReceiptSender(this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating(), new Date(), msgId2, msgId3, msgState), delay, TimeUnit.MILLISECONDS);
        }
        testingForm.addMessage("PduResponseSent: " + resp.getName(), resp.toString());
    }
    boolean delayRequired = testingForm.getSmppSimulatorParameters().getResponseDelay() > 0;
    if (delayRequired)
        await(testingForm.getSmppSimulatorParameters().getResponseDelay(), TimeUnit.MILLISECONDS);
    return resp;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) CharBuffer(java.nio.CharBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) MessageState(org.mobicents.smsc.library.MessageState) BaseSmResp(com.cloudhopper.smpp.pdu.BaseSmResp) GSMCharsetDecoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecoder) GSMCharsetDecodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecodingData) Tlv(com.cloudhopper.smpp.tlv.Tlv) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm)

Example 4 with BaseSm

use of com.cloudhopper.smpp.pdu.BaseSm in project smscgateway by RestComm.

the class SmppTestingForm method doSubmitMessage.

private void doSubmitMessage(int dcs, ArrayList<byte[]> msgLst, int msgRef, boolean addSegmTlv, int esmClass, SmppSimulatorParameters.ValidityType validityType, int segmentCnt, String destAddr, int messageClassVal) throws Exception {
    int i1 = 0;
    for (byte[] buf : msgLst) {
        i1++;
        BaseSm pdu;
        switch(this.param.getSendingMessageType()) {
            case SubmitSm:
                SubmitSm submitPdu = new SubmitSm();
                pdu = submitPdu;
                break;
            case DataSm:
                DataSm dataPdu = new DataSm();
                pdu = dataPdu;
                break;
            case DeliverSm:
                DeliverSm deliverPdu = new DeliverSm();
                pdu = deliverPdu;
                break;
            case SubmitMulti:
                SubmitMulti submitMulti = new SubmitMulti();
                pdu = submitMulti;
                break;
            default:
                return;
        }
        pdu.setSourceAddress(new Address((byte) this.param.getSourceTON().getCode(), (byte) this.param.getSourceNPI().getCode(), this.param.getSourceAddress()));
        if (this.param.getSendingMessageType() == SendingMessageType.SubmitMulti) {
            long daOrig = 1;
            try {
                daOrig = Long.parseLong(destAddr);
            } catch (Exception e) {
            }
            for (int i2 = 0; i2 < this.param.getSubmitMultiMessageCnt(); i2++) {
                // this code can be used for testing of address rejections
                // if(i2 == 0){
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // 8, (byte) this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }else {
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // this.param.getDestTON().getCode(), (byte)
                // this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }
                ((SubmitMulti) pdu).addDestAddresses(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), String.valueOf(daOrig + i2)));
            }
        } else {
            pdu.setDestAddress(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), destAddr));
        }
        pdu.setEsmClass((byte) esmClass);
        switch(validityType) {
            case ValidityPeriod_5min:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
            case ValidityPeriod_2hours:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 2, 0, 0));
                break;
            case ScheduleDeliveryTime_5min:
                pdu.setScheduleDeliveryTime(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
        }
        pdu.setDataCoding((byte) dcs);
        pdu.setRegisteredDelivery((byte) this.param.getMcDeliveryReceipt().getCode());
        if (buf.length < 250 && this.param.getSendingMessageType() != SmppSimulatorParameters.SendingMessageType.DataSm)
            pdu.setShortMessage(buf);
        else {
            Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, buf);
            pdu.addOptionalParameter(tlv);
        }
        if (addSegmTlv) {
            byte[] buf1 = new byte[2];
            buf1[0] = 0;
            buf1[1] = (byte) msgRef;
            Tlv tlv = new Tlv(SmppConstants.TAG_SAR_MSG_REF_NUM, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) msgLst.size();
            tlv = new Tlv(SmppConstants.TAG_SAR_TOTAL_SEGMENTS, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) i1;
            tlv = new Tlv(SmppConstants.TAG_SAR_SEGMENT_SEQNUM, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (messageClassVal > 0) {
            byte[] buf1 = new byte[1];
            buf1[0] = (byte) messageClassVal;
            Tlv tlv = new Tlv(SmppConstants.TAG_DEST_ADDR_SUBUNIT, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (this.param.isSendOptionalParameter()) {
            for (Tlv tlv : this.param.getTlvSet().getOptionalParameters()) {
                pdu.addOptionalParameter(tlv);
            }
        }
        WindowFuture<Integer, PduRequest, PduResponse> future0 = session0.sendRequestPdu(pdu, 10000, false);
        this.messagesSent.incrementAndGet();
        if (this.timer == null) {
            this.addMessage("Request=" + pdu.getName(), pdu.toString());
        }
    }
    this.segmentsSent.addAndGet(segmentCnt);
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) Address(com.cloudhopper.smpp.type.Address) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) CharacterCodingException(java.nio.charset.CharacterCodingException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PduRequest(com.cloudhopper.smpp.pdu.PduRequest) DataSm(com.cloudhopper.smpp.pdu.DataSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SubmitMulti(com.cloudhopper.smpp.pdu.SubmitMulti) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

BaseSm (com.cloudhopper.smpp.pdu.BaseSm)4 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)4 Tlv (com.cloudhopper.smpp.tlv.Tlv)3 DataSmResp (com.cloudhopper.smpp.pdu.DataSmResp)2 DeliverSm (com.cloudhopper.smpp.pdu.DeliverSm)2 SubmitSmResp (com.cloudhopper.smpp.pdu.SubmitSmResp)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 BaseSmResp (com.cloudhopper.smpp.pdu.BaseSmResp)1 DataSm (com.cloudhopper.smpp.pdu.DataSm)1 PduRequest (com.cloudhopper.smpp.pdu.PduRequest)1 SubmitMulti (com.cloudhopper.smpp.pdu.SubmitMulti)1 SubmitSm (com.cloudhopper.smpp.pdu.SubmitSm)1 Address (com.cloudhopper.smpp.type.Address)1 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)1 ByteBuffer (java.nio.ByteBuffer)1 CharBuffer (java.nio.CharBuffer)1 Date (java.util.Date)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)1 GSMCharsetDecoder (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecoder)1