Пример #1
0
 private String sendMT(
     final String message,
     final TypeOfNumber sourceTon,
     final String source,
     final TypeOfNumber destinationTon,
     final String destination,
     OptionalParameter... optionalParameters)
     throws InvalidResponseException, PDUException, IOException, NegativeResponseException,
         ResponseTimeoutException {
   try {
     final String messageId =
         smppSession.submitShortMessage(
             serviceType,
             sourceTon,
             NumberingPlanIndicator.UNKNOWN,
             source,
             destinationTon,
             NumberingPlanIndicator.UNKNOWN,
             destination,
             new ESMClass(),
             (byte) 0,
             (byte) 1,
             null,
             null,
             new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE),
             (byte) 0,
             provider.getDataCoding(),
             (byte) 0,
             message.getBytes("ISO-8859-1"),
             optionalParameters);
     logger.info(
         "MT sent - messageId:{} to:{} from:{} text:{}{} - {}",
         messageId,
         destination,
         source,
         message,
         paramsToString(optionalParameters),
         this.toShortString());
     return messageId;
   } catch (final PDUException e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw e;
   } catch (final ResponseTimeoutException e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw e;
   } catch (final InvalidResponseException e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw e;
   } catch (final NegativeResponseException e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw e;
   } catch (final IOException e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw e;
   } catch (final Throwable e) {
     logger.error(
         "Failed to send MT - to:"
             + destination
             + " from:"
             + source
             + " text:"
             + message
             + paramsToString(optionalParameters)
             + " - "
             + this.toShortString(),
         e);
     throw new RuntimeException(e);
   }
 }
Пример #2
0
  @Override
  public boolean sendMessage(OutboundMessage msg)
      throws TimeoutException, GatewayException, IOException, InterruptedException {

    Alphabet encoding = Alphabet.ALPHA_DEFAULT;

    switch (msg.getEncoding()) {
      case ENC8BIT:
        encoding = Alphabet.ALPHA_8_BIT;
        break;
      case ENCUCS2:
        encoding = Alphabet.ALPHA_UCS2;
        break;
      case ENCCUSTOM:
        encoding = Alphabet.ALPHA_RESERVED;
        break;
    }
    GeneralDataCoding dataCoding;

    switch (msg.getDCSMessageClass()) {
      case MSGCLASS_FLASH:
        dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS0, encoding);
        break;
      case MSGCLASS_ME:
        dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS1, encoding);
        break;
      case MSGCLASS_SIM:
        dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS2, encoding);
        break;
      case MSGCLASS_TE:
        dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS3, encoding);
        break;
      default:
        dataCoding = new GeneralDataCoding();
        dataCoding.setAlphabet(encoding);
    }
    try {
      final RegisteredDelivery registeredDelivery = new RegisteredDelivery();
      registeredDelivery.setSMSCDeliveryReceipt(
          (msg.getStatusReport())
              ? SMSCDeliveryReceipt.SUCCESS_FAILURE
              : SMSCDeliveryReceipt.DEFAULT);

      String msgId =
          session.submitShortMessage(
              bindAttributes.getSystemType(),
              TypeOfNumber.valueOf(sourceAddress.getTypeOfNumber().value()),
              NumberingPlanIndicator.valueOf(sourceAddress.getNumberingPlanIndicator().value()),
              (msg.getFrom() != null) ? msg.getFrom() : getFrom(),
              TypeOfNumber.valueOf(destinationAddress.getTypeOfNumber().value()),
              NumberingPlanIndicator.valueOf(
                  destinationAddress.getNumberingPlanIndicator().value()),
              msg.getRecipient(),
              new ESMClass(),
              (byte) 0,
              (byte) msg.getPriority(),
              null,
              formatTimeFromHours(msg.getValidityPeriod()),
              registeredDelivery,
              (byte) 0,
              dataCoding,
              (byte) 0,
              msg.getText().getBytes());
      msg.setRefNo(msgId);
      msg.setDispatchDate(new Date());
      msg.setGatewayId(getGatewayId());
      msg.setMessageStatus(MessageStatuses.SENT);
      incOutboundMessageCount();
    } catch (PDUException e) {
      msg.setGatewayId(getGatewayId());
      msg.setMessageStatus(MessageStatuses.FAILED);
      msg.setFailureCause(FailureCauses.BAD_FORMAT);
      Logger.getInstance().logError("Message Format not accepted.", e, getGatewayId());
      return false;
    } catch (ResponseTimeoutException e) {
      Logger.getInstance().logError("Message could not be sent.", e, getGatewayId());
      throw new TimeoutException(e.getMessage());
    } catch (InvalidResponseException e) {
      Logger.getInstance().logError("Message could not be sent.", e, getGatewayId());
      throw new IOException("InvalidResponseException: ", e);
    } catch (NegativeResponseException e) {
      Logger.getInstance().logError("Message could not be sent.", e, getGatewayId());
      throw new IOException("NegativeResponseException: ", e);
    }

    return true;
  }