コード例 #1
0
  /**
   * @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);
  }
コード例 #2
0
 @Override
 public boolean sendMessage(OutboundMessage msg)
     throws TimeoutException, GatewayException, IOException, InterruptedException {
   URL url = null;
   List<HttpHeader> request = new ArrayList<HttpHeader>();
   List<String> response;
   String reqLine;
   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(), false));
   request.add(new HttpHeader("msisdn", msg.getRecipient().substring(1), 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));
   reqLine = ExpandHttpHeaders(request);
   url = new URL(this.providerUrl + "/eapi/submission/send_sms/2/2.0" + "?" + reqLine);
   synchronized (this.SYNC_Commander) {
     response = HttpGet(url);
   }
   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;
 }