コード例 #1
0
  @Override
  public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg) {

    if (SystemPrevayler.getSystemPrevaylerModel().addReceivedMessage(msg)) {
      switch (msgType) {
        case STATUSREPORT:
          if (msg instanceof StatusReportMessage) {
            StatusReportMessage statusReportMessage = (StatusReportMessage) msg;
            String recipient =
                ContactFactory.getInstance()
                    .createContact(
                        Long.valueOf(statusReportMessage.getRecipient().replaceAll("\\D", "0")))
                    .getFormattedContact();
            LOGGER.info(
                "Processing a "
                    + MessageTypes.STATUSREPORT.name()
                    + " from Recipient: "
                    + recipient);
            Logger.getLogger("validContacts").info("recipient: " + recipient);
          }
          break;
        default:
          String originator =
              ContactFactory.getInstance()
                  .createContact(Long.valueOf(msg.getOriginator().replaceAll("\\D", "0")))
                  .getFormattedContact();
          LOGGER.info(
              "Processing a "
                  + MessageTypes.INBOUND.name()
                  + " Message Notification from Originator: "
                  + originator
                  + "; Text: "
                  + msg.getText());
          if (isFunctionMessage(msg)) {
            Integer requiredFunction = -1;
            try {
              requiredFunction = Integer.valueOf(msg.getText().trim());
            } catch (Exception e) {
              LOGGER.error(
                  "Error when parsing ReportRequiredType for value: " + msg.getText().trim());
            }

            switch (ReportRequiredType.parse(requiredFunction)) {
              case SMS_RATING:
                new Thread(new SmsRatingReport()).start();
                break;

              case EMAIL_RATING:
                new Thread(new EmailRatingReport()).start();
                break;

              case CLEAR_RECEIVED_MESSAGES:
                LOGGER.error("Cleanning the received messages...");
                SystemPrevayler.getSystemPrevaylerModel().clearReceivedMessages();
                break;

              case NOT_DEFINED:
                new Thread(new NotSupportedReport()).start();
                break;
            }
            SystemPrevayler.getSystemPrevaylerModel().getReceivedMessages().remove(msg);
          }
          break;
      }
      SystemPrevayler.takeSnapShot();
    }
    deleteMessage(msg);
  }
コード例 #2
0
ファイル: JSMPPGateway.java プロジェクト: pvangeel/onesms
    public void onAcceptDeliverSm(DeliverSm deliverSm) throws ProcessRequestException {
      if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) {

        try {
          DeliveryReceipt delReceipt = deliverSm.getShortMessageAsDeliveryReceipt();

          StatusReportMessage statusReportMessage =
              new StatusReportMessage(
                  delReceipt.getId(),
                  deliverSm.getDestAddress(),
                  deliverSm.getSourceAddr(),
                  delReceipt.getText(),
                  delReceipt.getSubmitDate(),
                  delReceipt.getDoneDate());

          switch (delReceipt.getFinalStatus()) {
            case DELIVRD:
              statusReportMessage.setStatus(DeliveryStatuses.DELIVERED);
              break;
            case REJECTD:
            case EXPIRED:
            case UNDELIV:
              statusReportMessage.setStatus(DeliveryStatuses.ABORTED);
              break;
            default:
              statusReportMessage.setStatus(DeliveryStatuses.UNKNOWN);
          }

          statusReportMessage.setGatewayId(getGatewayId());
          Service.getInstance()
              .getNotifyQueueManager()
              .getNotifyQueue()
              .add(
                  new InboundMessageNotification(
                      getMyself(), MessageTypes.STATUSREPORT, statusReportMessage));
        } catch (InvalidDeliveryReceiptException e) {
          Logger.getInstance().logError("Failed getting delivery receipt.", e, getGatewayId());
        }
      } else {
        InboundMessage msg =
            new InboundMessage(
                new java.util.Date(),
                deliverSm.getSourceAddr(),
                new String(deliverSm.getShortMessage()),
                0,
                null);
        msg.setGatewayId(JSMPPGateway.this.getGatewayId());
        if (Alphabet.ALPHA_DEFAULT.value() == deliverSm.getDataCoding()) {
          msg.setEncoding(MessageEncodings.ENC7BIT);
        } else if (Alphabet.ALPHA_8_BIT.value() == deliverSm.getDataCoding()) {
          msg.setEncoding(MessageEncodings.ENC8BIT);
        } else if (Alphabet.ALPHA_UCS2.value() == deliverSm.getDataCoding()) {
          msg.setEncoding(MessageEncodings.ENCUCS2);
        } else {
          msg.setEncoding(MessageEncodings.ENCCUSTOM);
        }
        incInboundMessageCount();
        Service.getInstance()
            .getNotifyQueueManager()
            .getNotifyQueue()
            .add(new InboundMessageNotification(getMyself(), MessageTypes.INBOUND, msg));
      }
    }