use of org.jsmpp.extra.NegativeResponseException in project camel by apache.
the class SmppSmCommand method splitBody.
protected byte[][] splitBody(Message message) throws SmppException {
byte[] shortMessage = getShortMessage(message);
SmppSplitter splitter = createSplitter(message);
byte[][] segments = splitter.split(shortMessage);
if (segments.length > 1) {
// Message body is split into multiple parts,
// check if this is permitted
SmppSplittingPolicy policy = getSplittingPolicy(message);
switch(policy) {
case ALLOW:
return segments;
case TRUNCATE:
return new byte[][] { java.util.Arrays.copyOfRange(shortMessage, 0, segments[0].length) };
case REJECT:
// FIXME - JSMPP needs to have an enum of the negative response
// codes instead of just using them like this
NegativeResponseException nre = new NegativeResponseException(SMPP_NEG_RESPONSE_MSG_TOO_LONG);
throw new SmppException(nre);
default:
throw new SmppException("Unknown splitting policy: " + policy);
}
} else {
return segments;
}
}
use of org.jsmpp.extra.NegativeResponseException in project dhis2-core by dhis2.
the class SMPPClient method send.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private OutboundMessageResponse send(SMPPSession session, String text, Set<String> recipients, SMPPGatewayConfig config) {
OutboundMessageResponse response = new OutboundMessageResponse();
SubmitMultiResult result = null;
try {
result = session.submitMultiple(config.getSystemType(), config.getTypeOfNumber(), config.getNumberPlanIndicator(), SOURCE, getAddresses(recipients), new ESMClass(), (byte) 0, (byte) 1, TIME_FORMATTER.format(new Date()), null, new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE), ReplaceIfPresentFlag.DEFAULT, new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1, config.isCompressed()), (byte) 0, text.getBytes());
log.info(String.format("Messages submitted, result is %s", result.getMessageId()));
} catch (PDUException e) {
log.error("Invalid PDU parameter", e);
} catch (ResponseTimeoutException e) {
log.error("Response timeout", e);
} catch (InvalidResponseException e) {
log.error("Receive invalid response", e);
} catch (NegativeResponseException e) {
log.error("Receive negative response", e);
} catch (IOException e) {
log.error("I/O error", e);
} catch (Exception e) {
log.error("Exception in submitting SMPP request", e);
}
if (result != null) {
if (result.getUnsuccessDeliveries() == null || result.getUnsuccessDeliveries().length == 0) {
log.info("Message pushed to broker successfully");
response.setOk(true);
response.setDescription(result.getMessageId());
response.setResponseObject(GatewayResponse.RESULT_CODE_0);
} else {
String failureCause = DeliveryReceiptState.valueOf(result.getUnsuccessDeliveries()[0].getErrorStatusCode()) + " - " + result.getMessageId();
log.error(failureCause);
response.setDescription(failureCause);
response.setResponseObject(GatewayResponse.FAILED);
}
} else {
response.setDescription(SENDING_FAILED);
response.setResponseObject(GatewayResponse.FAILED);
}
return response;
}
Aggregations