Skip to content

Commit

Permalink
Guard against exceptions in message receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Thorvardarson committed Feb 18, 2012
1 parent 179ac70 commit 430ddfd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 14 deletions.
58 changes: 47 additions & 11 deletions jsmpp/src/main/java/org/jsmpp/session/SMPPServerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,19 @@ public void processBind(Bind bind) {

public MessageId processSubmitSm(SubmitSm submitSm)
throws ProcessRequestException {
MessageId messageId = fireAcceptSubmitSm(submitSm);
if (messageId == null) {
String msg = "Invalid message_id, shouldn't null value. " + ServerMessageReceiverListener.class + "#onAcceptSubmitSm(SubmitSm) return null value";
logger.error(msg);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RX_R_APPN);
try {
MessageId messageId = fireAcceptSubmitSm(submitSm);
if (messageId == null) {
String msg = "Invalid message_id, shouldn't null value. " + ServerMessageReceiverListener.class + "#onAcceptSubmitSm(SubmitSm) return null value";
logger.error(msg);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RX_R_APPN);
}
return messageId;
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing SubmitSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
return messageId;
}

public void sendSubmitSmResponse(MessageId messageId, int sequenceNumber)
Expand All @@ -366,7 +372,13 @@ public void sendSubmitSmResponse(MessageId messageId, int sequenceNumber)

public SubmitMultiResult processSubmitMulti(SubmitMulti submitMulti)
throws ProcessRequestException {
return fireAcceptSubmitMulti(submitMulti);
try {
return fireAcceptSubmitMulti(submitMulti);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing SubmitMultiSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
}

public void sendSubmitMultiResponse(
Expand Down Expand Up @@ -395,7 +407,13 @@ public void sendSubmitMultiResponse(

public QuerySmResult processQuerySm(QuerySm querySm)
throws ProcessRequestException {
return fireAcceptQuerySm(querySm);
try {
return fireAcceptQuerySm(querySm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing QuerySm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
}

public void sendQuerySmResp(String messageId, String finalDate,
Expand All @@ -414,7 +432,13 @@ public void sendQuerySmResp(String messageId, String finalDate,

public DataSmResult processDataSm(DataSm dataSm)
throws ProcessRequestException {
return fireAcceptDataSm(dataSm);
try {
return fireAcceptDataSm(dataSm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing DataSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
}

// TODO uudashr: we can generalize this method
Expand All @@ -435,7 +459,13 @@ public void sendDataSmResp(DataSmResult dataSmResult, int sequenceNumber)

public void processCancelSm(CancelSm cancelSm)
throws ProcessRequestException {
fireAcceptCancelSm(cancelSm);
try {
fireAcceptCancelSm(cancelSm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing CancelSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
}

public void sendCancelSmResp(int sequenceNumber) throws IOException {
Expand All @@ -445,7 +475,13 @@ public void sendCancelSmResp(int sequenceNumber) throws IOException {

public void processReplaceSm(ReplaceSm replaceSm)
throws ProcessRequestException {
fireAcceptReplaceSm(replaceSm);
try {
fireAcceptReplaceSm(replaceSm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing ReplaceSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RSYSERR);
}
}

public void sendReplaceSmResp(int sequenceNumber) throws IOException {
Expand Down
23 changes: 20 additions & 3 deletions jsmpp/src/main/java/org/jsmpp/session/SMPPSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,33 @@ private void fireAcceptAlertNotification(AlertNotification alertNotification) {
private class ResponseHandlerImpl implements ResponseHandler {

public void processDeliverSm(DeliverSm deliverSm) throws ProcessRequestException {
fireAcceptDeliverSm(deliverSm);
try {
fireAcceptDeliverSm(deliverSm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing DeliverSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RX_T_APPN);
}
}

public DataSmResult processDataSm(DataSm dataSm)
throws ProcessRequestException {
return fireAcceptDataSm(dataSm);
try {
return fireAcceptDataSm(dataSm);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing DataSm";
logger.error(msg, e);
throw new ProcessRequestException(msg, SMPPConstant.STAT_ESME_RX_T_APPN);
}
}

public void processAlertNotification(AlertNotification alertNotification) {
fireAcceptAlertNotification(alertNotification);
try {
fireAcceptAlertNotification(alertNotification);
} catch(Exception e) {
String msg = "Invalid runtime exception thrown when processing AlertSm";
logger.error(msg, e);
}
}

public void sendDataSmResp(DataSmResult dataSmResult, int sequenceNumber)
Expand Down

0 comments on commit 430ddfd

Please sign in to comment.