Package org.smslib

Examples of org.smslib.InboundMessage


  }

  InboundMessage generateIncomingMessage()
  {
    incInboundMessageCount();
    InboundMessage msg = new InboundMessage(new java.util.Date(), "+1234567890", "Hello World! #" + getInboundMessageCount(), 0, null);
    msg.setGatewayId(this.getGatewayId());
    return msg;
  }
View Full Code Here


    int i, j, memIndex;
    int limit = (myLimit < 0 ? 0 : myLimit);
    String response, line, tmpLine, msgText, originator, dateStr, refNo;
    BufferedReader reader;
    StringTokenizer tokens;
    InboundMessage msg;
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    for (int ml = 0; ml < (getATHandler().getStorageLocations().length() / 2); ml++)
    {
      if (getATHandler().switchStorageLocation(getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2)))
      {
        response = getATHandler().listMessages(msgClass);
        response = response.replaceAll("\\s+OK\\s+", "\nOK");
        reader = new BufferedReader(new StringReader(response));
        for (;;)
        {
          line = reader.readLine();
          if (line == null) break;
          line = line.trim();
          if (line.length() > 0) break;
        }
        while (true)
        {
          if (line == null) break;
          if (line.length() <= 0 || line.equalsIgnoreCase("OK")) break;
          i = line.indexOf(':');
          j = line.indexOf(',');
          memIndex = 0;
          try
          {
            memIndex = Integer.parseInt(line.substring(i + 1, j).trim());
          }
          catch (NumberFormatException e)
          {
            // TODO: What to do here?
            Logger.getInstance().logWarn("Incorrect Memory Index number parsed!", e, getGatewayId());
          }
          tokens = new StringTokenizer(line, ",");
          tokens.nextToken();
          tokens.nextToken();
          tmpLine = "";
          if (Character.isDigit(tokens.nextToken().trim().charAt(0)))
          {
            line = line.replaceAll(",,", ", ,");
            tokens = new StringTokenizer(line, ",");
            tokens.nextToken();
            tokens.nextToken();
            tokens.nextToken();
            refNo = tokens.nextToken();
            tokens.nextToken();
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal1.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
            cal1.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
            cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
            cal1.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
            cal1.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal2.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
            cal2.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
            cal2.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
            cal2.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
            cal2.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
            msg = new StatusReportMessage(refNo, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2), cal1.getTime(), cal2.getTime());
            msg.setGatewayId(getGatewayId());
            Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex(), null, getGatewayId());
            msgList.add(msg);
            incInboundMessageCount();
          }
          else
          {
            line = line.replaceAll(",,", ", ,");
            tokens = new StringTokenizer(line, ",");
            tokens.nextToken();
            tokens.nextToken();
            originator = tokens.nextToken().replaceAll("\"", "");
            tokens.nextToken();
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal1.set(Calendar.YEAR, 2000 + Integer.parseInt(dateStr.substring(0, 2)));
            cal1.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(3, 5)) - 1);
            cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStr.substring(6, 8)));
            dateStr = tokens.nextToken().replaceAll("\"", "");
            cal1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateStr.substring(0, 2)));
            cal1.set(Calendar.MINUTE, Integer.parseInt(dateStr.substring(3, 5)));
            cal1.set(Calendar.SECOND, Integer.parseInt(dateStr.substring(6, 8)));
            msgText = "";
            while (true)
            {
              tmpLine = reader.readLine();
              if (tmpLine == null) break;
              if (tmpLine.startsWith("+CMGL")) break;
              if (tmpLine.startsWith("+CMGR")) break;
              msgText += (msgText.length() == 0 ? "" : "\n") + tmpLine;
            }
            msgText = msgText.trim();
            msg = new InboundMessage(cal1.getTime(), originator, msgText, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2));
            msg.setGatewayId(getGatewayId());
            Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex(), null, getGatewayId());
            msgList.add(msg);
            incInboundMessageCount();
          }
          while (true)
          {
View Full Code Here

            //       if the message is invalid, the message should
            //       be ignored and but logged
            if (pdu instanceof SmsDeliveryPdu)
            {
              Logger.getInstance().logDebug(pdu.toString(), null, getGatewayId());
              InboundMessage msg;
              String memLocation = getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2);
              if (pdu.isBinary())
              {
                msg = new InboundBinaryMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
                if (Service.getInstance().getKeyManager().getKey(msg.getOriginator()) != null) msg = new InboundEncryptedMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
              }
              else
              {
                msg = new InboundMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
              }
              msg.setGatewayId(getGatewayId());
              Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex() + " REF:" + msg.getMpRefNo() + " MAX:" + msg.getMpMaxNo() + " SEQ:" + msg.getMpSeqNo(), null, getGatewayId());
              if (msg.getMpRefNo() == 0)
              {
                // single message
                msgList.add(msg);
                incInboundMessageCount();
              }
              else
              {
                // multi-part message
                int k, l;
                List<InboundMessage> tmpList;
                InboundMessage listMsg;
                boolean found, duplicate;
                found = false;
                for (k = 0; k < this.mpMsgList.size(); k++)
                {
                  // List of List<InboundMessage>
                  tmpList = this.mpMsgList.get(k);
                  listMsg = tmpList.get(0);
                  // check if current message list is for this message
                  if (listMsg.getMpRefNo() == msg.getMpRefNo())
                  {
                    duplicate = false;
                    // check if the message is already in the message list
                    for (l = 0; l < tmpList.size(); l++)
                    {
                      listMsg = tmpList.get(l);
                      if (listMsg.getMpSeqNo() == msg.getMpSeqNo())
                      {
                        duplicate = true;
                        break;
                      }
                    }
View Full Code Here

  private void checkMpMsgList(Collection<InboundMessage> msgList) throws TimeoutException, GatewayException, IOException, InterruptedException
  {
    int k, l, m;
    List<InboundMessage> tmpList;
    InboundMessage listMsg, mpMsg;
    boolean found;
    mpMsg = null;
    Logger.getInstance().logDebug("CheckMpMsgList(): MAINLIST: " + this.mpMsgList.size(), null, getGatewayId());
    for (k = 0; k < this.mpMsgList.size(); k++)
    {
      tmpList = this.mpMsgList.get(k);
      Logger.getInstance().logDebug("CheckMpMsgList(): SUBLIST[" + k + "]: " + tmpList.size(), null, getGatewayId());
      listMsg = tmpList.get(0);
      found = false;
      if (listMsg.getMpMaxNo() == tmpList.size())
      {
        found = true;
        for (l = 0; l < tmpList.size(); l++)
          for (m = 0; m < tmpList.size(); m++)
          {
            listMsg = tmpList.get(m);
            if (listMsg.getMpSeqNo() == (l + 1))
            {
              if (listMsg.getMpSeqNo() == 1)
              {
                mpMsg = listMsg;
                mpMsg.setMpMemIndex(mpMsg.getMemIndex());
                if (listMsg.getMpMaxNo() == 1)
                {
                  msgList.add(mpMsg);
                  incInboundMessageCount();
                }
              }
              else
              {
                if (mpMsg != null)
                {
                  if (mpMsg instanceof InboundBinaryMessage)
                  {
                    InboundBinaryMessage mpMsgBinary = (InboundBinaryMessage) mpMsg;
                    InboundBinaryMessage listMsgBinary = (InboundBinaryMessage) listMsg;
                    mpMsgBinary.addDataBytes(listMsgBinary.getDataBytes());
                  }
                  else
                  {
                    // NEW
                    String textToAdd = listMsg.getText();
                    if (mpMsg.getEndsWithMultiChar())
                    {
                      // adjust first char of textToAdd
                      Logger.getInstance().logDebug("Adjusting dangling multi-char: " + textToAdd.charAt(0) + " --> " + PduUtils.getMultiCharFor(textToAdd.charAt(0)), null, getGatewayId());
                      textToAdd = PduUtils.getMultiCharFor(textToAdd.charAt(0)) + textToAdd.substring(1);
                    }
                    mpMsg.setEndsWithMultiChar(listMsg.getEndsWithMultiChar());
                    try
                    {
                      mpMsg.addText(textToAdd);
                    }
                    catch (UnsupportedEncodingException e)
                    {
                      // TODO: What to do with this?
                    }
                  }
                  mpMsg.setMpSeqNo(listMsg.getMpSeqNo());
                  mpMsg.setMpMemIndex(listMsg.getMemIndex());
                  if (listMsg.getMpSeqNo() == listMsg.getMpMaxNo())
                  {
                    mpMsg.setMemIndex(-1);
                    msgList.add(mpMsg);
                    incInboundMessageCount();
                    mpMsg = null;
View Full Code Here

         } 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));
     }
}
View Full Code Here

      messages = new JSONObject[messagesQueued];

      for(int i = 0 ; i < inbox.size(); i ++){

        InboundMessage newMessage = (InboundMessage) inbox.get(i);
        messages[i] = new JSONObject();

        logger.trace("MESSAGE: \n" + newMessage);

        try {


          messages[i].put("date", newMessage.getDate());
          messages[i].put("id", newMessage.getId());
          messages[i].put("originator", newMessage.getOriginator());
          messages[i].put("text", newMessage.getText())

          if(deleteMessageOnReceive) service.deleteMessage(newMessage);

          if(!messages[i].get("originator").equals("")) receiver.modemEvent(messages[i]);
View Full Code Here

      messagesQueued = service.readMessages( inbox, MessageClasses.ALL);
      message = new JSONObject[inbox.size()];

      for(int i = 0 ; i < inbox.size(); i ++){

        InboundMessage newMessage = (InboundMessage) inbox.get(i);

        logger.trace(newMessage);

        try {

          message[i].put("date", newMessage.getDate());
          message[i].put("id", newMessage.getId());
          message[i].put("originator", newMessage.getOriginator());
          message[i].put("text", newMessage.getText())

          if(deleteMessageOnReceive) service.deleteMessage(newMessage);

        } catch (JSONException e) {
          logger.warn(e);
View Full Code Here

TOP

Related Classes of org.smslib.InboundMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.