Ejemplo n.º 1
0
  private void init() {
    switch (bindAttributes.getBindType()) {
      case RECEIVER:
        bindType = BindType.BIND_RX;
        setInbound(true);
        setOutbound(false);
        break;
      case TRANSMITTER:
        bindType = BindType.BIND_TX;
        setInbound(false);
        setOutbound(true);
        break;
      case TRANSCEIVER:
        bindType = BindType.BIND_TRX;
        setInbound(true);
        setOutbound(true);
        break;
      default:
        IllegalArgumentException illegalArgumentException =
            new IllegalArgumentException("Unknown BindType " + bindAttributes.getBindType());
        Logger.getInstance()
            .logError(
                illegalArgumentException.getMessage(), illegalArgumentException, getGatewayId());
        throw illegalArgumentException;
    }

    bindTypeOfNumber =
        TypeOfNumber.valueOf(bindAttributes.getBindAddress().getTypeOfNumber().value());
    bindNumberingPlanIndicator =
        NumberingPlanIndicator.valueOf(
            bindAttributes.getBindAddress().getNumberingPlanIndicator().value());

    initSession();
  }
Ejemplo n.º 2
0
  @Override
  public void execute(Exchange exchange) throws SmppException {
    DataSm dataSm = createDataSm(exchange);

    if (log.isDebugEnabled()) {
      log.debug("Sending a data short message for exchange id '{}'...", exchange.getExchangeId());
    }

    DataSmResult result;
    try {
      result =
          session.dataShortMessage(
              dataSm.getServiceType(),
              TypeOfNumber.valueOf(dataSm.getSourceAddrTon()),
              NumberingPlanIndicator.valueOf(dataSm.getSourceAddrNpi()),
              dataSm.getSourceAddr(),
              TypeOfNumber.valueOf(dataSm.getDestAddrTon()),
              NumberingPlanIndicator.valueOf(dataSm.getDestAddrNpi()),
              dataSm.getDestAddress(),
              new ESMClass(dataSm.getEsmClass()),
              new RegisteredDelivery(dataSm.getRegisteredDelivery()),
              DataCodings.newInstance(dataSm.getDataCoding()),
              dataSm.getOptionalParameters());
    } catch (Exception e) {
      throw new SmppException(e);
    }

    if (log.isDebugEnabled()) {
      log.debug(
          "Sent a data short message for exchange id '{}' and message id '{}'",
          exchange.getExchangeId(),
          result.getMessageId());
    }

    Message message = getResponseMessage(exchange);
    message.setHeader(SmppConstants.ID, result.getMessageId());
    // message.setHeader(SmppConstants.OPTIONAL_PARAMETERS,
    // createOptionalParameterByName(result.getOptionalParameters()));
    message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, null);
    message.setHeader(
        SmppConstants.OPTIONAL_PARAMETER,
        createOptionalParameterByCode(result.getOptionalParameters()));
  }
Ejemplo n.º 3
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;
  }