use of com.zx.sms.codec.smpp.msg.DataSmResp in project SMSGate by Lihuanghe.
the class DefaultPduTranscoder method doDecode.
protected Pdu doDecode(int commandLength, ByteBuf buffer) throws UnrecoverablePduException, RecoverablePduException {
// skip the length field because we already parsed it
buffer.skipBytes(SmppConstants.PDU_INT_LENGTH);
// read the remaining portion of the PDU header
int commandId = buffer.readInt();
int commandStatus = buffer.readInt();
int sequenceNumber = buffer.readInt();
Pdu pdu = null;
// any command id with its 31st bit set to true is a response
if (PduUtil.isRequestCommandId(commandId)) {
if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK) {
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();
} else if (commandId == SmppConstants.CMD_ID_DATA_SM) {
pdu = new DataSm();
} else if (commandId == SmppConstants.CMD_ID_CANCEL_SM) {
pdu = new CancelSm();
} else if (commandId == SmppConstants.CMD_ID_QUERY_SM) {
pdu = new QuerySm();
} else if (commandId == SmppConstants.CMD_ID_REPLACE_SM) {
pdu = new ReplaceSm();
} else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER) {
pdu = new BindTransceiver();
} else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER) {
pdu = new BindTransmitter();
} else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER) {
pdu = new BindReceiver();
} else if (commandId == SmppConstants.CMD_ID_UNBIND) {
pdu = new Unbind();
} else if (commandId == SmppConstants.CMD_ID_ALERT_NOTIFICATION) {
pdu = new AlertNotification();
} else {
pdu = new PartialPdu(commandId);
}
} else {
if (commandId == SmppConstants.CMD_ID_SUBMIT_SM_RESP) {
pdu = new SubmitSmResp();
} else if (commandId == SmppConstants.CMD_ID_DELIVER_SM_RESP) {
pdu = new DeliverSmResp();
} else if (commandId == SmppConstants.CMD_ID_DATA_SM_RESP) {
pdu = new DataSmResp();
} else if (commandId == SmppConstants.CMD_ID_CANCEL_SM_RESP) {
pdu = new CancelSmResp();
} else if (commandId == SmppConstants.CMD_ID_QUERY_SM_RESP) {
pdu = new QuerySmResp();
} else if (commandId == SmppConstants.CMD_ID_REPLACE_SM_RESP) {
pdu = new ReplaceSmResp();
} else if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK_RESP) {
pdu = new EnquireLinkResp();
} else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP) {
pdu = new BindTransceiverResp();
} else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER_RESP) {
pdu = new BindReceiverResp();
} else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP) {
pdu = new BindTransmitterResp();
} else if (commandId == SmppConstants.CMD_ID_UNBIND_RESP) {
pdu = new UnbindResp();
} else if (commandId == SmppConstants.CMD_ID_GENERIC_NACK) {
pdu = new GenericNack();
} else {
pdu = new PartialPduResp(commandId);
}
}
// set pdu header values
pdu.setCommandLength(commandLength);
pdu.setCommandStatus(commandStatus);
pdu.setSequenceNumber(sequenceNumber);
// check if we need to throw an exception
if (pdu instanceof PartialPdu) {
throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU request commandId [0x" + HexUtil.toHexString(commandId) + "]");
} else if (pdu instanceof PartialPduResp) {
throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU response commandId [0x" + HexUtil.toHexString(commandId) + "]");
}
// see if we can map the command status into a message
if (pdu instanceof PduResponse) {
PduResponse response = (PduResponse) pdu;
response.setResultMessage(context.lookupResultMessage(commandStatus));
}
try {
// parse pdu body parameters (may throw exception)
pdu.readBody(buffer);
// parse pdu optional parameters (may throw exception)
pdu.readOptionalParameters(buffer, context);
} catch (RecoverablePduException e) {
// check if we should add the partial pdu to the exception
if (e.getPartialPdu() == null) {
e.setPartialPdu(pdu);
}
// rethrow it
throw e;
}
return pdu;
}
Aggregations