use of org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecodingData 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;
}
use of org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecodingData in project smscgateway by RestComm.
the class TxSmppServerSbb method parseShortMessageText.
private String parseShortMessageText(BaseSm event) {
byte[] data = event.getShortMessage();
if (event.getShortMessageLength() == 0) {
// Probably the message_payload Optional Parameter is being used
Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
if (messagePaylod != null) {
data = messagePaylod.getValue();
}
}
if (data == null) {
data = new byte[0];
}
boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
byte[] udhData;
byte[] textPart;
String msg;
udhData = null;
textPart = data;
if (udhPresent && data.length > 2) {
// UDH exists
int udhLen = (textPart[0] & 0xFF) + 1;
if (udhLen <= textPart.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);
}
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(event.getDataCoding());
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
msg = new String(textPart, isoCharset);
} else {
SmppEncoding enc;
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
enc = smscPropertiesManagement.getSmppEncodingForGsm7();
} else {
enc = smscPropertiesManagement.getSmppEncodingForUCS2();
}
switch(enc) {
case Utf8:
default:
msg = new String(textPart, utf8Charset);
break;
case Unicode:
msg = new String(textPart, ucs2Charset);
break;
case Gsm7:
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) {
// this can not be
}
msg = bf.toString();
break;
}
}
return msg;
}
Aggregations