/**
   * @param smsMessage
   * @param msg
   * @return
   * @throws PersistenceException
   */
  @Override
  public SendModem2Info saveOrUpdate(SendSMSMessage smsMessage, OutboundMessage msg)
      throws PersistenceException {
    SendModem2Info config = new SendModem2Info();

    config.setGatewayID(msg.getGatewayId());

    config.setMessageId(String.valueOf(msg.getMessageId()));
    config.setMessageUUID(msg.getUuid());
    config.setEncoding(msg.getEncoding().toString());
    config.setDataGerada(msg.getDate().toString());
    config.setSmscRefNum(msg.getRefNo());
    config.setNumDestinatario(smsMessage.getNumero());
    if (msg.getDispatchDate() == null) {

      config.setDataExapedicao("Não há data prevista para expedição");

    } else {
      config.setDataExapedicao(msg.getDispatchDate().toString());
    }
    config.setMsgStatus(msg.getMessageStatus().toString());
    config.setCausaFalha(String.valueOf(msg.getFailureCause()));
    config.setPeriodoValido(String.valueOf(msg.getValidityPeriod()));
    config.setRelatorioStatus(msg.getStatusReport());
    config.setPortaDestino(String.valueOf(msg.getSrcPort()));
    config.setFlashSMS(msg.getFlashSms());
    config.setMensagem(smsMessage.getMensagem());
    config.setPduData(msg.getPduUserData());

    if (msg.getScheduledDeliveryDate() == null) {

      config.setEntregaPrevista("SEM DATA PREVISTA");
    } else {
      config.setEntregaPrevista(msg.getScheduledDeliveryDate().toString());
    }
    return new BaseRepository<SendModem2Info>(SendModem2Info.class).saveOrUpdate(config);
  }
Beispiel #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;
  }
 @Override
 public boolean sendMessage(OutboundMessage msg)
     throws TimeoutException, GatewayException, IOException, InterruptedException {
   URL url = null;
   List<HttpHeader> request = new ArrayList<HttpHeader>();
   List<String> response;
   boolean ok = false;
   request.add(new HttpHeader("username", this.username, false));
   request.add(new HttpHeader("password", this.password, false));
   request.add(
       new HttpHeader("message", msg.getText(), msg.getEncoding() == MessageEncodings.ENCUCS2));
   if (msg.getEncoding() == MessageEncodings.ENCUCS2)
     request.add(new HttpHeader("dca", "16bit", false));
   if (msg.getRecipient().charAt(0) == '+')
     request.add(new HttpHeader("msisdn", msg.getRecipient().substring(1), false));
   else request.add(new HttpHeader("msisdn", msg.getRecipient(), false));
   request.add(new HttpHeader("allow_concat_text_sms", "1", false));
   if (msg.getStatusReport()) request.add(new HttpHeader("want_report", "1", false));
   if (msg.getFlashSms()) request.add(new HttpHeader("msg_class", "0", false));
   if (msg.getFrom() != null && msg.getFrom().length() != 0)
     request.add(new HttpHeader("source_id", msg.getFrom(), false));
   else if (getFrom() != null && getFrom().length() != 0)
     request.add(new HttpHeader("source_id", getFrom(), false));
   url = new URL(this.providerUrl + "/eapi/submission/send_sms/2/2.0");
   synchronized (this.SYNC_Commander) {
     response = HttpPost(url, request);
   }
   if (response.get(0).charAt(0) == '0') {
     StringTokenizer tokens = new StringTokenizer(response.get(0), "|");
     tokens.nextToken();
     tokens.nextToken();
     msg.setRefNo(tokens.nextToken());
     msg.setDispatchDate(new Date());
     msg.setGatewayId(getGatewayId());
     msg.setMessageStatus(MessageStatuses.SENT);
     incOutboundMessageCount();
     ok = true;
   } else {
     StringTokenizer tokens = new StringTokenizer(response.get(0), "|");
     switch (Integer.parseInt(tokens.nextToken())) {
       case 22:
         msg.setFailureCause(FailureCauses.GATEWAY_FAILURE);
         break;
       case 23:
         msg.setFailureCause(FailureCauses.GATEWAY_AUTH);
         break;
       case 24:
         msg.setFailureCause(FailureCauses.BAD_FORMAT);
         break;
       case 25:
       case 26:
       case 27:
       case 28:
         msg.setFailureCause(FailureCauses.NO_CREDIT);
         break;
       case 40:
         msg.setFailureCause(FailureCauses.GATEWAY_FAILURE);
         break;
     }
     msg.setRefNo(null);
     msg.setDispatchDate(null);
     msg.setMessageStatus(MessageStatuses.FAILED);
     ok = false;
   }
   return ok;
 }