@Override public PduResponse firePduRequestReceived(PduRequest request) { PduResponse response; try { if (request instanceof DeliverSm) { String sourceAddress = ((DeliverSm) request).getSourceAddress().getAddress(); String message = CharsetUtil.decode(((DeliverSm) request).getShortMessage(), smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding())); LOGGER.info("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress); boolean isDeliveryReceipt; if (smppClient.getDetectDlrByOpts()) { isDeliveryReceipt = request.getOptionalParameters() != null; } else { isDeliveryReceipt = SmppUtil.isMessageTypeAnyDeliveryReceipt(((DeliverSm) request).getEsmClass()); } if (!isDeliveryReceipt) { TextMessageEventHandler.handleTextMessage(sourceAddress, message); } } response = request.createResponse(); } catch (Exception error) { LOGGER.warn("SMS receiving error", error); response = request.createResponse(); response.setResultMessage(error.getMessage()); response.setCommandStatus(SmppConstants.STATUS_UNKNOWNERR); } return response; }
public static DeliverSm createDeliveryReceipt(DeliveryReceiptRecord deliveryReceiptRecord, int sequenceNumber) throws Exception { DeliverSm pdu0 = new DeliverSm(); pdu0.setSequenceNumber(sequenceNumber); pdu0.setSourceAddress(deliveryReceiptRecord.getSourceAddress()); pdu0.setDestAddress(deliveryReceiptRecord.getDestinationAddress()); pdu0.setEsmClass((byte) 0x04); pdu0.setProtocolId((byte) 0x00); pdu0.setPriority((byte) 0x00); pdu0.setScheduleDeliveryTime(null); pdu0.setValidityPeriod(null); pdu0.setRegisteredDelivery((byte) 0x00); pdu0.setReplaceIfPresent((byte) 0x00); pdu0.setDataCoding((byte) 0x00); pdu0.setDefaultMsgId((byte) 0x00); pdu0.setShortMessage(CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM)); pdu0.addOptionalParameter(new Tlv(SmppConstants.TAG_RECEIPTED_MSG_ID, convertOptionalStringToCOctet(FormatUtils.formatAsHex(deliveryReceiptRecord .getMessageId())))); pdu0.addOptionalParameter(new Tlv(SmppConstants.TAG_MSG_STATE, new byte[] { SmppConstants.STATE_DELIVERED })); pdu0.calculateAndSetCommandLength();
public static DeliverSm createDeliverSm(Address sourceAddress, Address destinationAddress, int sequenceNumber) throws SmppInvalidArgumentException { DeliverSm pdu0 = new DeliverSm(); pdu0.setSequenceNumber(sequenceNumber); pdu0.setSourceAddress(sourceAddress); pdu0.setDestAddress(destinationAddress); pdu0.setProtocolId((byte) 0x00); pdu0.setPriority((byte) 0x00); pdu0.setScheduleDeliveryTime(null); pdu0.setValidityPeriod(null); pdu0.setRegisteredDelivery((byte) 0x00); pdu0.setReplaceIfPresent((byte) 0x00); pdu0.setDataCoding((byte) 0x00); pdu0.setDefaultMsgId((byte) 0x00); return pdu0; }
DeliverSm deliverPdu = new DeliverSm(); pdu = deliverPdu;
void sendMessage( SmppSession session, String message) { try { byte[] textBytes = CharsetUtil.encode(message, CharsetUtil.CHARSET_UCS_2); DeliverSm deliver = new DeliverSm(); deliver.setSourceAddress(new Address((byte)0x03, (byte)0x00, "40404")); deliver.setDestAddress(new Address((byte)0x01, (byte)0x01, "44555519205")); deliver.setShortMessage(textBytes); WindowFuture<Integer,PduRequest,PduResponse> future = session.sendRequestPdu(deliver, 10000, false); if (!future.await()) { logger.error("Failed to receive deliver_sm_resp within specified time"); } else if (future.isSuccess()) { DeliverSmResp deliverSmResp = (DeliverSmResp)future0.getResponse(); logger.info("deliver_sm_resp: commandStatus [" + deliverSmResp.getCommandStatus() + "=" + deliverSmResp.getResultMessage() + "]"); } else { logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause()); } } catch (Exception e) {} }
@Override public DeliverSmResp createResponse() { DeliverSmResp resp = new DeliverSmResp(); resp.setSequenceNumber(this.getSequenceNumber()); return resp; }
case SmppConstants.CMD_ID_DELIVER_SM: DeliverSm deliverSm = (DeliverSm) pduRequest; sourceAddress = deliverSm.getSourceAddress(); if (!this.esme.isSourceAddressMatching(sourceAddress)) { tracer.warning(String .format("Incoming DELIVER_SM's sequence_number=%d source_addr_ton=%d source_addr_npi=%d source_addr=%s doesn't match with configured ESME name=%s source_addr_ton=%d source_addr_npi=%d source_addr=%s", deliverSm.getSequenceNumber(), sourceAddress.getTon(), sourceAddress.getNpi(), sourceAddress.getAddress(), this.esme.getName(), this.esme.getSourceTon(), this.esme.getSourceNpi(), this.esme.getSourceAddressRange()));
@ManagedOperation public void sendSegmentedDeliverLongMsg(int numberOfSegments, int minMsgSize) throws Exception { Address sourceAddress = new Address((byte) 0, (byte) 0, "123456789"); Address destinationAddress = new Address((byte) 0, (byte) 0, "987654321"); int msgRefNum = nextMsgRefNum.incrementAndGet(); for (int i = 1; i <= numberOfSegments; i++) { StringBuilder sb = new StringBuilder(255); sb.append("Segment content "); sb.append(i); sb.append(". "); while (sb.length() < minMsgSize) { sb.append("."); } String shortMessage = sb.toString(); DeliverSm pdu = SmppPduUtils.createDeliverSm(sourceAddress, destinationAddress, getSessionManager().getNextSequenceNumber()); SmppPduUtils.setSegmentOptionalParams(pdu, msgRefNum, i, numberOfSegments); byte[] body = CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM); if (body.length < 256) { pdu.setShortMessage(body); } else { SmppPduUtils.setMessagePayloadOptionalParams(pdu, body); } pdu.setDataCoding(SmppConstants.DATA_CODING_8BITA); send(pdu); } }
/** * Taken from * * @see http://memoirniche.wordpress.com/2010/04/10/smpp-submit-pdu/ **/ public static void setSegmentUdh00AndMessage(DeliverSm pdu, int msgRefNum, int segmentNum, int totalSegmentCount, String shortMessage) throws SmppInvalidArgumentException { // add UDHI bit to ESM class byte esmClass = 0; esmClass |= SmppConstants.ESM_CLASS_UDHI_MASK; pdu.setEsmClass(esmClass); byte[] udhHeader = new byte[6]; udhHeader[0] = 0x05; // the total length of data in UDH, not including // the first byte of header (i.e. the byte // containing the total length). udhHeader[1] = 0x00; // IE identifier for concatenated messages udhHeader[2] = 0x03; // length of data in IE udhHeader[3] = (byte) msgRefNum; udhHeader[4] = (byte) totalSegmentCount; udhHeader[5] = (byte) segmentNum; byte[] message = CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM); ByteBuffer bb = ByteBuffer.allocate(udhHeader.length + message.length); bb.put(udhHeader); bb.put(message); pdu.setShortMessage(bb.array()); }
@Override public DeliverSm createMessage() throws Exception { if (nextSegmentId > numberOfSegments) { // we are starting a new segmented message currentMsgRefNum = ++nextMsgRefNum; nextSegmentId = 1; } DeliverSm pdu = super.createMessage(); String shortMessage = "Segment content " + nextSegmentId + ". "; SmppPduUtils.setSegmentOptionalParams(pdu, currentMsgRefNum, nextSegmentId, numberOfSegments); pdu.setShortMessage(CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM)); nextSegmentId += 1; return pdu; }
break; case DeliverSm: DeliverSm deliverPdu = new DeliverSm(); pdu = deliverPdu; break;
@Override public DeliverSmResp createResponse() { DeliverSmResp resp = new DeliverSmResp(); resp.setSequenceNumber(this.getSequenceNumber()); return resp; }
@ManagedOperation public void sendSegmentedBinaryDeliverMsg(int numberOfSegments) throws Exception { Address sourceAddress = new Address((byte) 0, (byte) 0, "123456789"); Address destinationAddress = new Address((byte) 0, (byte) 0, "987654321"); int msgRefNum = nextMsgRefNum.incrementAndGet(); for (int i = 1; i <= numberOfSegments; i++) { String shortMessage = "Segment content " + i + ". "; DeliverSm pdu = SmppPduUtils.createDeliverSm(sourceAddress, destinationAddress, getSessionManager().getNextSequenceNumber()); SmppPduUtils.setSegmentOptionalParams(pdu, msgRefNum, i, numberOfSegments); pdu.setShortMessage(CharsetUtil.encode(shortMessage, CharsetUtil.NAME_GSM)); pdu.setDataCoding((byte) 0x02); // 8 bit binary encoding send(pdu); } }
public static void setSegmentUdh08AndMessage(DeliverSm pdu, int msgRefNum, int segmentNum, int totalSegmentCount, String shortMessage) throws SmppInvalidArgumentException { // add UDHI bit to ESM class byte esmClass = 0; esmClass |= SmppConstants.ESM_CLASS_UDHI_MASK; pdu.setEsmClass(esmClass); byte[] udhHeader = new byte[7]; udhHeader[0] = 0x06; // the total length of data in UDH, not including // the first byte of header (i.e. the byte // containing the total length). udhHeader[1] = 0x08; // IE identifier for concatenated messages udhHeader[2] = 0x05; // length of data in IE byte[] unsignedShortMsgRefNum = intToUnsignedShort(msgRefNum); udhHeader[3] = unsignedShortMsgRefNum[0]; udhHeader[4] = unsignedShortMsgRefNum[1]; udhHeader[5] = (byte) totalSegmentCount; udhHeader[6] = (byte) segmentNum; byte[] message = CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM); ByteBuffer bb = ByteBuffer.allocate(udhHeader.length + message.length); bb.put(udhHeader); bb.put(message); pdu.setShortMessage(bb.array()); }
@ManagedOperation public void sendSegmentedDeliverMsg(int numberOfSegments) throws Exception { Address sourceAddress = new Address((byte) 0, (byte) 0, "123456789"); Address destinationAddress = new Address((byte) 0, (byte) 0, "987654321"); int msgRefNum = nextMsgRefNum.incrementAndGet(); for (int i = 1; i <= numberOfSegments; i++) { String shortMessage = "Segment content " + i + ". "; DeliverSm pdu = SmppPduUtils.createDeliverSm(sourceAddress, destinationAddress, getSessionManager().getNextSequenceNumber()); SmppPduUtils.setSegmentOptionalParams(pdu, msgRefNum, i, numberOfSegments); pdu.setShortMessage(CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM)); send(pdu); } }
pdu = new EnquireLink(); } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM) { pdu = new DeliverSm(); } else if (commandId == SmppConstants.CMD_ID_SUBMIT_SM) { pdu = new SubmitSm();
@Override public DeliverSmResp createResponse() { DeliverSmResp resp = new DeliverSmResp(); resp.setSequenceNumber(this.getSequenceNumber()); return resp; }
@ManagedOperation public void sendSegmentedDeliverMsgRandomized(int numberOfMessages, int numberOfSegments) throws Exception { for (int msgNum = 0; msgNum < numberOfMessages; msgNum++) { Address sourceAddress = new Address((byte) 0, (byte) 0, "123456789"); Address destinationAddress = new Address((byte) 0, (byte) 0, "987654321"); int msgRefNum = nextMsgRefNum.incrementAndGet(); for (int i = 1; i <= numberOfSegments; i++) { String shortMessage = "Msg " + msgNum + ". Segment content " + i + ". "; DeliverSm pdu = SmppPduUtils.createDeliverSm(sourceAddress, destinationAddress, getSessionManager().getNextSequenceNumber()); SmppPduUtils.setSegmentOptionalParams(pdu, msgRefNum, i, numberOfSegments); pdu.setShortMessage(CharsetUtil.encode(shortMessage, CharsetUtil.CHARSET_GSM)); getDeliverSender().scheduleDelivery(new PduRequestRecord(pdu, 1000, 5000)); } } }
pdu = new EnquireLink(); } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM) { pdu = new DeliverSm(); } else if (commandId == SmppConstants.CMD_ID_SUBMIT_SM) { pdu = new SubmitSm();
@Override public DeliverSmResp createResponse() { DeliverSmResp resp = new DeliverSmResp(); resp.setSequenceNumber(this.getSequenceNumber()); return resp; }