@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;
 }
Exemple #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;
  }