use of org.smpp.pdu.InvalidPDUException in project opensmpp by OpenSmpp.
the class Receiver method receiveAsync.
/**
* This method receives a PDU from connection and stores it into
* <code>pduQueue</code>. It's called from the <code>ReceiverBase</code>'s
* p<code>process</code> method which is called in loop from
* <code>ProcessingThread</code>'s <code>run</code> method.
* <p>
* If an exception occurs during receiving, depending on type
* of the exception this method either just reports the exception to
* debug & event objects or stops processing to indicate
* that it isn't able to process the exception. The function
* <code>setTermException</code> is then called with the caught exception.
*
* @see ReceiverBase#run()
*/
protected void receiveAsync() {
PDU pdu = null;
try {
debug.write(DRXTXD2, "Receiver.receiveAsync() going to receive pdu.");
pdu = receivePDUFromConnection(connection, unprocessed);
// we must catch every exception as this is thread running
// on the background and we don't want the thread to be terminated
} catch (InvalidPDUException e) {
// thrown when enough data were received but further parsing
// required more than indicated by CommandLength, i.e. pdu is
// corrupted or further parsing didn't find terminating zero
// of a c-string i.e. pdu is corrupted
// must send generic nack anyway
event.write(e, "Receiver.receiveAsync(): received PDU is invalid.");
PDU expdu = e.getPDU();
int seqNr = expdu == null ? 0 : expdu.getSequenceNumber();
if (automaticNack) {
sendGenericNack(Data.ESME_RINVMSGLEN, seqNr);
} else {
pdu = new GenericNack(Data.ESME_RINVMSGLEN, seqNr);
}
} catch (UnknownCommandIdException e) {
// if received unknown pdu, we must send generic nack
event.write(e, "Receiver.receiveAsync(): Unknown command id.");
if (automaticNack) {
sendGenericNack(Data.ESME_RINVCMDID, e.getSequenceNumber());
} else {
pdu = new GenericNack(Data.ESME_RINVCMDID, e.getSequenceNumber());
}
} catch (TimeoutException e) {
// too long had unprocessed data
debug.write(DRXTX, "Receiver.receiveAsync() too long had an uncomplete message.");
} catch (PDUException e) {
// something wrong with the PDU
event.write(e, "Receiver.receiveAsync()");
PDU expdu = e.getPDU();
int seqNr = expdu == null ? 0 : expdu.getSequenceNumber();
if (automaticNack) {
sendGenericNack(e.getErrorCode(), seqNr);
} else {
pdu = new GenericNack(e.getErrorCode(), seqNr);
}
} catch (Exception e) {
// don't know what happen, let's end the show
event.write(e, "Receiver.receiveAsync()");
stopProcessing(e);
}
if (pdu != null) {
debug.write(DRXTX, "Receiver.receiveAsync(): PDU received, processing " + pdu.debugString());
if (asynchronous) {
process(pdu);
} else {
enqueue(pdu);
}
}
}
Aggregations