Examples of OutboundMessage


Examples of org.smslib.OutboundMessage

    Collection<OutboundMessage> msgList = new ArrayList<OutboundMessage>();
    while (true)
    {
      try
      {
        OutboundMessage msg;
        Statement cmd;
        PreparedStatement pst;
        ResultSet rs;
        int msgCount;
        msgCount = 1;
        con = getDbConnection();
        cmd = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        pst = con.prepareStatement("update " + getProperty("tables.sms_out", "smsserver_out") + " set status = 'Q' where id = ? ");
        rs = cmd.executeQuery("select id, type, recipient, text, wap_url, wap_expiry_date, wap_signal, create_date, originator, encoding, status_report, flash_sms, src_port, dst_port, sent_date, ref_no, priority, status, errors, gateway_id from " + getProperty("tables.sms_out", "smsserver_out") + " where status = 'U' order by priority desc, id");
        while (rs.next())
        {
          if (msgCount > Integer.parseInt(getProperty("batch_size"))) break;
          if (getServer().checkPriorityTimeFrame(rs.getInt("priority")))
          {
            switch (rs.getString("type").charAt(0))
            {
              case 'O':
                switch (rs.getString("encoding").charAt(0))
                {
                  case '7':
                    msg = new OutboundMessage(rs.getString("recipient").trim(), rs.getString("text").trim());
                    msg.setEncoding(MessageEncodings.ENC7BIT);
                    break;
                  case '8':
                  {
                    String text = rs.getString("text").trim();
                    byte bytes[] = new byte[text.length() / 2];
                    for (int i = 0; i < text.length(); i += 2)
                    {
                      int value = (Integer.parseInt("" + text.charAt(i), 16) * 16) + (Integer.parseInt("" + text.charAt(i + 1), 16));
                      bytes[i / 2] = (byte) value;
                    }
                    msg = new OutboundBinaryMessage(rs.getString("recipient").trim(), bytes);
                  }
                    break;
                  case 'U':
                    msg = new OutboundMessage(rs.getString("recipient").trim(), rs.getString("text").trim());
                    msg.setEncoding(MessageEncodings.ENCUCS2);
                    break;
                  default:
                    msg = new OutboundMessage(rs.getString("recipient").trim(), rs.getString("text").trim());
                    msg.setEncoding(MessageEncodings.ENC7BIT);
                    break;
                }
                if (rs.getInt("flash_sms") == 1) msg.setFlashSms(true);
                if (rs.getInt("src_port") != -1)
                {
                  msg.setSrcPort(rs.getInt("src_port"));
                  msg.setDstPort(rs.getInt("dst_port"));
                }
                break;
              case 'W':
                Date wapExpiryDate;
                WapSISignals wapSignal;
                if (rs.getTime("wap_expiry_date") == null)
                {
                  Calendar cal = Calendar.getInstance();
                  cal.setTime(new Date());
                  cal.add(Calendar.DAY_OF_YEAR, 7);
                  wapExpiryDate = cal.getTime();
                }
                else wapExpiryDate = rs.getTimestamp("wap_expiry_date");
                if (rs.getString("wap_signal") == null) wapSignal = WapSISignals.NONE;
                else
                {
                  switch (rs.getString("wap_signal").charAt(0))
                  {
                    case 'N':
                      wapSignal = WapSISignals.NONE;
                      break;
                    case 'L':
                      wapSignal = WapSISignals.LOW;
                      break;
                    case 'M':
                      wapSignal = WapSISignals.MEDIUM;
                      break;
                    case 'H':
                      wapSignal = WapSISignals.HIGH;
                      break;
                    case 'D':
                      wapSignal = WapSISignals.DELETE;
                      break;
                    default:
                      wapSignal = WapSISignals.NONE;
                  }
                }
                msg = new OutboundWapSIMessage(rs.getString("recipient").trim(), new URL(rs.getString("wap_url").trim()), rs.getString("text").trim(), wapExpiryDate, wapSignal);
                break;
              default:
                throw new Exception("Message type '" + rs.getString("type") + "' is unknown!");
            }
            msg.setPriority(rs.getInt("priority"));
            if (rs.getInt("status_report") == 1) msg.setStatusReport(true);
            if ((rs.getString("originator") != null) && (rs.getString("originator").length() > 0)) msg.setFrom(rs.getString("originator").trim());
            msg.setGatewayId(rs.getString("gateway_id").trim());
            msgList.add(msg);
            getMessageCache().put(msg.getMessageId(), rs.getInt("id"));
            pst.setInt(1, rs.getInt("id"));
            pst.executeUpdate();
            con.commit();
            msgCount++;
          }
View Full Code Here

Examples of org.smslib.OutboundMessage

          foundErrors = true;
          pushResponse(body, ERR_MISSING_PARMS, "Missing Parameters.");
        }
        else
        {
          OutboundMessage msg = new OutboundMessage(recipient, text);
          parm = getRequest().getParameter("encoding");
          if ((parm != null) && parm.length() != 0)
          {
            if (parm.equalsIgnoreCase("7")) msg.setEncoding(MessageEncodings.ENC7BIT);
            else if (parm.equalsIgnoreCase("8")) msg.setEncoding(MessageEncodings.ENC8BIT);
            else if (parm.equalsIgnoreCase("U")) msg.setEncoding(MessageEncodings.ENCUCS2);
            else
            {
              foundErrors = true;
              pushResponse(body, ERR_INVALID_PARMS, "Invalid encoding requested.");
            }
          }
          parm = getRequest().getParameter("priority");
          if ((parm != null) && (parm.length() != 0))
          {
            try
            {
              msg.setPriority(Integer.parseInt(parm));
            }
            catch (Exception e)
            {
              foundErrors = true;
              pushResponse(body, ERR_INVALID_PARMS, "Invalid priority requested.");
            }
          }
          parm = getRequest().getParameter("from");
          if ((parm != null) && (parm.length() != 0)) msg.setFrom(parm);
          parm = getRequest().getParameter("gateway");
          if ((parm != null) && (parm.length() != 0)) msg.setGatewayId(parm);
          if (!foundErrors)
          {
            try
            {
              Service.getInstance().sendMessage(msg);
View Full Code Here

Examples of org.smslib.OutboundMessage

    for (int i = 0; i < outFiles.length; i++)
    {
      try
      {
        /* Process each document and add message to the list */
        OutboundMessage msg = readDocument(outFiles[i]);
        if (msg == null) { throw new IllegalArgumentException("Missing required fieldes!"); }
        messageList.add(msg);
        getMessageCache().put(msg.getMessageId(), outFiles[i]);
      }
      catch (IllegalArgumentException e)
      {
        getService().getLogger().logWarn("Skipping outgoing file " + outFiles[i].getAbsolutePath() + ": File is not valid: " + e.getLocalizedMessage(), null, null);
        File brokenFile = new File(this.outBrokenDirectory, outFiles[i].getName());
View Full Code Here

Examples of org.smslib.OutboundMessage

        {
          originator = en.getTextContent();
        }
      }
      /* Create outbound message */
      OutboundMessage outMsg = new OutboundMessage(recipient, text);
      /* Set required fields */
      outMsg.setFrom(originator);
      if (!"".equals(e.getAttribute("create_date")))
      {
        outMsg.setDate(getISO8601AsDate(e.getAttribute("create_date")));
      }
      if (!"".equals(e.getAttribute("gateway_id")))
      {
        outMsg.setGatewayId(e.getAttribute("gateway_id"));
      }
      /* Read optional fields - priority */
      String priority = e.getAttribute("priority");
      if ("L".equalsIgnoreCase(priority))
      {
        outMsg.setPriority(-1);
      }
      else if ("N".equalsIgnoreCase(priority))
      {
        outMsg.setPriority(0);
      }
      else if ("H".equalsIgnoreCase(priority))
      {
        outMsg.setPriority(+1);
      }
      /* Read optional fields - encoding */
      String encoding = e.getAttribute("encoding");
      if ("7".equals(encoding))
      {
        outMsg.setEncoding(MessageEncodings.ENC7BIT);
      }
      else if ("8".equals(encoding))
      {
        outMsg.setEncoding(MessageEncodings.ENC8BIT);
      }
      else
      {
        outMsg.setEncoding(MessageEncodings.ENCUCS2);
      }
      /* Read optinal fields - status_report */
      if ("1".equals(e.getAttribute("status_report")))
      {
        outMsg.setStatusReport(true);
      }
      /* Read optinal fields - flash_sms */
      if ("1".equals(e.getAttribute("flash_sms")))
      {
        outMsg.setFlashSms(true);
      }
      /* Read optinal fields - src_port */
      if (!"".equals(e.getAttribute("src_port")))
      {
        outMsg.setSrcPort(Integer.parseInt(e.getAttribute("src_port")));
      }
      /* Read optinal fields - dst_port */
      if (!"".equals(e.getAttribute("dst_port")))
      {
        outMsg.setDstPort(Integer.parseInt(e.getAttribute("dst_port")));
      }
      return outMsg;
    }
    return null;
  }
View Full Code Here

Examples of org.smslib.OutboundMessage

    s.connect();
    Folder inbox = s.getFolder(getProperty("mailbox_name", "INBOX"));
    inbox.open(Folder.READ_WRITE);
    for (Message m : inbox.getMessages())
    {
      OutboundMessage om = new OutboundMessage(m.getSubject(), m.getContent().toString());
      om.setFrom(m.getFrom().toString());
      om.setDate(m.getReceivedDate());
      retValue.add(om);
      // Delete message from inbox
      m.setFlag(Flags.Flag.DELETED, true);
    }
    inbox.close(true);
View Full Code Here

Examples of org.smslib.OutboundMessage

    System.out.println("  SIM IMSI: " + gateway.getImsi());
    System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
    System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    System.out.println();
    // Send a message synchronously.
    OutboundMessage msg = new OutboundMessage("306974000000", "Hello from SMSLib!");
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    // Or, send out a WAP SI message.
    //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000",  new URL("http://www.smslib.org/"), "Visit SMSLib now!");
    //Service.getInstance().sendMessage(wapMsg);
View Full Code Here

Examples of org.smslib.OutboundMessage

    @Override
    public void process() throws Exception
    {
      Logger.getInstance().logDebug("DelayQueueManager running...", null, null);
      OutboundMessage message = pollDelayedMessage();
      if (message != null) queueMessage(message);
      //queueMessage(getDelayQueue().take().getMsg());
      Logger.getInstance().logDebug("DelayQueueManager end...", null, null);
    }
View Full Code Here

Examples of org.smslib.OutboundMessage

public class SendMessage
{
  public void doIt() throws Exception
  {
    GatewayStatusNotification statusNotification = new GatewayStatusNotification();
    OutboundMessage msg;
    System.out.println("Example: Send message through Kannel HTTP Interface.");
    System.out.println(Library.getLibraryDescription());
    System.out.println("Version: " + Library.getLibraryVersion());
    KannelHTTPGateway gateway = new KannelHTTPGateway("mysmsc", "http://localhost:13013/cgi-bin/sendsms", "simple", "elpmis");
    // Uncomment in order gateway to start and stop SMSC automatically on Kannel
    //gateway.setAutoStartSmsc(true);
    //gateway.setAutoStopSmsc(true);
    // Set Kannel's Admin URL and password to be used starting, stopping and checking SMSC status  
    gateway.setAdminUrl("http://localhost:13000");
    gateway.setAdminPassword("bar");
    gateway.setOutbound(true);
    Service.getInstance().addGateway(gateway);
    Service.getInstance().setGatewayStatusNotification(statusNotification);
    Service.getInstance().startService();
    // Send a message.
    msg = new OutboundMessage("+967712831950", "Hello from SMSLib (Kannel handler)");
    //msg.setEncoding(MessageEncodings.ENCUCS2);
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    System.out.println("Now Sleeping - Hit <enter> to terminate.");
    System.in.read();
View Full Code Here

Examples of org.smslib.OutboundMessage

{
  public void doIt() throws Exception
  {
    try
    {
      OutboundMessage msg;
      System.out.println("Example: Send message from BulkSMS HTTP Interface.");
      System.out.println(Library.getLibraryDescription());
      System.out.println("Version: " + Library.getLibraryVersion());
      BulkSmsHTTPGateway gateway = new BulkSmsHTTPGateway("bulksms.http.1", "username", "password");
      gateway.setOutbound(true);
      Service.getInstance().addGateway(gateway);
      Service.getInstance().startService();
      // Query the service to find out our credit balance.
      System.out.println("Remaining credit: " + gateway.queryBalance());
      // Send a message synchronously.
      msg = new OutboundMessage("+30...", "Hello from SMSLib (BULKSMS handler)");
      Service.getInstance().sendMessage(msg);
      System.out.println(msg);
      System.out.println("Now Sleeping - Hit <enter> to terminate.");
      System.in.read();
      Service.getInstance().stopService();
View Full Code Here

Examples of org.smslib.OutboundMessage

    gateways.add(gateway);
    gateway=new GatewayMock("G3");
    gateways.add(gateway);
   
    ARouter router=new DefaultRouter();
    OutboundMessage message=new OutboundMessage("77374847", "test");
   
    Collection<AGateway> candidates= router.route(message, gateways);
    Assert.assertEquals("No route expected. No started gateways and no outbound gateways.", 0, candidates.size());
   
    gateway.setAttributes(AGateway.GatewayAttributes.SEND);
    gateway.setOutbound(true);
    message.setGatewayId("G3");
   
    gateway=gateways.get(0);
    gateway.startGateway();
     
    candidates= router.route(message, gateways);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.