Example #1
0
    @Override
    public String getStyle(Object itemId, Object propertyId) {
      if (propertyId == null) {
        return null;
      }

      Message message = messagesMap.get((Long) itemId);

      if (propertyId.equals("Status")) {
        if (message.getStatus().equals(Status.FAILED)) {
          return "red";
        }
      }

      if (propertyId.equals("Cmd Status")) {
        int commandStatus = message.getProperty("commandStatus", Integer.class);
        if (commandStatus != 0) {
          return "red";
        }
      }

      if (propertyId.equals("Receipt")) {
        String receiptStatus = message.getProperty("receiptStatus", String.class);
        if ("DELIVRD".equals(receiptStatus)) {
          return "green";
        } else if (receiptStatus != null && !"".equals(receiptStatus)) {
          return "red";
        }
      }

      return null;
    }
Example #2
0
  @Override
  public final void process(Exchange exchange) throws Exception {
    Message message = (Message) exchange.getIn().getBody(Message.class);

    try {
      MessageStore messageStore = resourceRegistry.getResource(MessageStore.class);

      boolean insert = message.getId() == Message.NOT_PERSISTED;

      long startTime = new Date().getTime();
      messageStore.saveOrUpdate(message);
      long endTime = new Date().getTime();

      if (insert) {
        log.trace(
            "insert message with id "
                + message.getId()
                + " took "
                + (endTime - startTime)
                + " milis");
      } else {
        log.trace(
            "update message with id "
                + message.getId()
                + " took "
                + (endTime - startTime)
                + " milis");
      }

    } catch (RejectedException e) {
      log.warn("the message can't be persisted: " + e.getMessage());
    } catch (StoreException e) {
      log.error("StoreException saving a message: " + e.getMessage(), e);
    }
  }
Example #3
0
  @Test
  public void testReceiveDeliveryReceipt() throws Exception {
    log.info("starting testReceiveDeliveryReceipt ... ");

    server.setPacketProcessor(new CustomPacketProcessor("12000"));

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");

    MockMessageStore messageStore = new MockMessageStore();
    MockMessageProducer messageProducer = new MockMessageProducer();
    SmppConnector connector =
        createAndStartSmppConnector(configuration, messageStore, messageProducer);

    try {
      String from = "3542";
      String to = "3002175604";

      // send a message
      Message message = new Message();
      message.setProperty("to", to);
      message.setProperty("from", from);
      message.setProperty("text", "This is the test");
      message.setProperty("receiptDestination", "test");
      sendMessage(connector, messageStore, message);

      // retrieve the session
      Assert.assertEquals(server.getSessions().size(), 1);
      SmppSession session = server.getSessions().iterator().next();
      Assert.assertNotNull(session);

      DeliverSm deliverSM = new DeliverSm();
      deliverSM.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT);
      deliverSM.setDestAddress(new Address((byte) 0, (byte) 0, from));
      deliverSM.setSourceAddress(new Address((byte) 0, (byte) 0, to));
      deliverSM.setShortMessage(
          "id:12000 sub:1 dlvrd:1 submit date:1101010000 done date:1101010000 stat:DELIVRD err:0 text:This is a ... "
              .getBytes());

      session.sendRequest(deliverSM, DEFAULT_TIMEOUT);

      long timeout = 2000;
      if (!receiveMessage(messageProducer, timeout)) {
        Assert.fail("the delivery receipt was not received");
      }

      Message receivedMessage = (Message) messageProducer.getMessage(0);
      Assert.assertEquals(from, receivedMessage.getProperty("to", String.class));
      Assert.assertEquals(to, receivedMessage.getProperty("from", String.class));
      Assert.assertEquals(receivedMessage.getProperty("messageId", String.class), 12000 + "");
      Assert.assertEquals("DELIVRD", receivedMessage.getProperty("finalStatus", String.class));
    } finally {
      connector.doStop();
    }
  }
  @Test
  public void shouldAddSuffixIfFieldDoesntExists() throws Exception {

    AddSuffixAction action = new AddSuffixAction();
    action.setField("to");
    action.setSuffix("suf");

    Message message = new Message();

    action.execute(message);

    Assert.assertEquals(message.getProperty("to", String.class), "suf");
  }
Example #5
0
  @Test
  public void shouldCopyProperty() throws Exception {
    CopyAction action = new CopyAction();
    action.setFrom("prop-1");
    action.setTo("prop-2");

    Message message = new Message();
    message.setProperty("prop-1", "value");

    action.execute(message);

    Assert.assertEquals(message.getProperty("prop-1"), "value");
    Assert.assertEquals(message.getProperty("prop-2"), "value");
  }
Example #6
0
  @Test
  public void testReceiveMessage() throws Exception {
    log.info("starting testReceiveMessage ... ");

    MockMessageProducer messageProducer = new MockMessageProducer();

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");

    SmppConnector connector = new SmppConnector(configuration);
    injectResource(new MockProcessorContext(), connector);
    injectResource(messageProducer, connector);
    connector.doStart();

    waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK);

    try {
      String to = "3542";
      String from = "3002175604";
      String text = "this is a test";

      // retrieve the session
      Assert.assertEquals(server.getSessions().size(), 1);
      SmppSession session = server.getSessions().iterator().next();
      Assert.assertNotNull(session);

      // create and send the request
      DeliverSm deliverSM = new DeliverSm();
      deliverSM.setDestAddress(new Address((byte) 0, (byte) 0, to));
      deliverSM.setSourceAddress(new Address((byte) 0, (byte) 0, from));
      deliverSM.setShortMessage(text.getBytes());

      session.sendRequest(deliverSM, DEFAULT_TIMEOUT);

      long timeout = 2000;
      if (!receiveMessage(messageProducer, timeout)) {
        Assert.fail("the message was not received");
      }

      Message message = (Message) messageProducer.getMessage(0);
      Assert.assertEquals(to, message.getProperty("to", String.class));
      Assert.assertEquals(from, message.getProperty("from", String.class));
      Assert.assertEquals(text, message.getProperty("text", String.class));
    } finally {
      connector.doStop();
    }
  }
Example #7
0
    @Override
    public Collection<Message> list(MessageCriteria criteria) throws StoreException {
      if (criteria != null && criteria.getProperties().get("smsc_messageid") != null) {
        Collection<Message> ret = new ArrayList<Message>();

        // check messageId
        String messageId = (String) criteria.getProperties().get("smsc_messageid");
        if (messageId != null) {
          for (Message message : messages) {
            String testId = message.getProperty("messageId", String.class);
            if (testId != null && messageId.equals(testId)) {
              ret.add(message);
            }
          }
        }

        return ret;
      }

      return messages;
    }
Example #8
0
  private void waitMessageUntilStatus(Message message, long timeout, byte status) {
    boolean isValid = false;

    long startTime = new Date().getTime();
    long actualTime = new Date().getTime();
    while (!isValid && (actualTime - startTime) <= timeout) {
      if (message.getStatus() == status) {
        isValid = true;
      } else {
        synchronized (this) {
          try {
            this.wait(200);
          } catch (Exception e) {
          }
        }
      }

      actualTime = new Date().getTime();
    }

    Assert.assertEquals(message.getStatus(), status);
  }
Example #9
0
  @Test
  public void shouldNotRouteDeliveryReceipt() throws Exception {
    MockMessageProducer messageProducer = new MockMessageProducer();

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");

    MessageStore messageStore = new MockMessageStore();

    SmppConnector connector = new SmppConnector(configuration);
    injectResource(new MockProcessorContext(), connector);
    injectResource(messageStore, connector);
    injectResource(messageProducer, connector);
    connector.doStart();
    waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK);

    try {
      Message message = new Message();
      message.setProperty("to", "3542");
      message.setProperty("from", "3002175604");
      message.setProperty("text", "This is the test");
      message.setProperty("sequenceNumber", 1);
      message.setProperty("messageId", "12000");
      message.setProperty("commandStatus", 0);

      messageStore.saveOrUpdate(message);

      DeliverSm deliverSm = new DeliverSm();
      deliverSm.setEsmClass(SmppConstants.ESM_CLASS_MT_SMSC_DELIVERY_RECEIPT);
      deliverSm.setDestAddress(new Address((byte) 0, (byte) 0, "3002175604"));
      deliverSm.setSourceAddress(new Address((byte) 0, (byte) 0, "3542"));
      deliverSm.setShortMessage(
          "id:12000 sub:1 dlvrd:1 submit date:1101010000 done date:1101010000 stat:DELIVRD err:0 text:This is a ... "
              .getBytes());

      // retrieve the session
      Assert.assertEquals(server.getSessions().size(), 1);
      SmppSession session = server.getSessions().iterator().next();
      Assert.assertNotNull(session);

      // send the delivery receipt
      session.sendRequest(deliverSm, DEFAULT_TIMEOUT);

      long timeout = 2000;
      if (receiveMessage(messageProducer, timeout)) {
        Assert.fail("the message was received");
      }
    } finally {
      connector.doStop();
    }
  }
Example #10
0
  @Test
  public void testFailedCommandStatuses() throws Exception {
    server.setPacketProcessor(
        new PacketProcessor() {

          @Override
          public void processPacket(SmppRequest packet, ResponseSender responseSender) {
            if (packet.getCommandId() == SmppPacket.SUBMIT_SM) {
              responseSender.send(Response.MESSAGE_QUEUE_FULL.withMessageId("12000"));
              return;
            }

            responseSender.send(Response.OK);
          }
        });

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");
    configuration.addFailedCommandStatus(Response.MESSAGE_QUEUE_FULL.getCommandStatus());

    MockMessageStore messageStore = new MockMessageStore();
    MockMessageProducer messageProducer = new MockMessageProducer();
    SmppConnector connector =
        createAndStartSmppConnector(configuration, messageStore, messageProducer);

    try {
      // send a message
      Message message = new Message();
      message.setProperty("to", "3542");
      message.setProperty("from", "3002175604");
      message.setProperty("text", "This is the test");
      sendMessage(connector, messageStore, message);

      Assert.assertEquals(messageStore.messages.size(), 1);

      Message m1 = messageStore.messages.iterator().next();
      Assert.assertNotNull(m1);

      waitMessageUntilStatus(m1, DEFAULT_TIMEOUT, Message.STATUS_FAILED);
      Assert.assertEquals(m1.getStatus(), Message.STATUS_FAILED);
    } finally {
      connector.doStop();
    }
  }
Example #11
0
  @Test
  public void testProcessLongMessage() throws Exception {
    log.info("starting testProcessLongMessage ... ");

    MockPacketProcessor pp =
        new MockPacketProcessor(
            new PacketProcessor() {

              @Override
              public void processPacket(SmppRequest packet, ResponseSender responseSender) {
                if (packet.getCommandId() == SmppPacket.SUBMIT_SM) {
                  responseSender.send(Response.OK.withMessageId("12000"));
                  return;
                }

                responseSender.send(Response.OK);
              }
            });
    server.setPacketProcessor(pp);

    MessageStore messageStore = Mockito.mock(MessageStore.class);

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");
    configuration.setDataCoding(3);

    SmppConnector connector = new SmppConnector(configuration);
    injectResource(new MockProcessorContext(), connector);
    injectResource(messageStore, connector);
    connector.doStart();
    waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK);

    try {
      Message message = new Message();
      message.setProperty("to", "3002175604");
      message.setProperty("from", "3542");
      message.setProperty(
          "text",
          "This is a long message to test how the smpp is working with long message splitting them by the 160 character and sending two messages. Finish the first message This is the second message.");

      connector.process(message);

      Assert.assertNotNull(message.getReference());

      List<SmppPacket> packets = pp.getPackets(2, DEFAULT_TIMEOUT);
      Assert.assertNotNull(packets);
      Assert.assertEquals(packets.size(), 2);

      SmppPacket packet = packets.get(0);
      Assert.assertNotNull(packet);
      Assert.assertEquals(packet.getCommandId(), SmppPacket.SUBMIT_SM);

      SubmitSm submitSm = (SubmitSm) packet;
      Assert.assertEquals(
          submitSm.getShortMessage(),
          "This is a long message to test how the smpp is working with long message splitting them by the 160 character and sending two messages. Finish the first message ");

      Tlv totalTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
      Assert.assertNotNull(totalTlv);
      Assert.assertEquals(ByteArrayUtil.toByte(totalTlv.getValue()), 2);

      Tlv segmentTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
      Assert.assertNotNull(segmentTlv);
      Assert.assertEquals(ByteArrayUtil.toByte(segmentTlv.getValue()), 1);

      Tlv msgRefTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
      Assert.assertNotNull(msgRefTlv);

      packet = packets.get(1);
      Assert.assertNotNull(packet);
      Assert.assertEquals(packet.getCommandId(), SmppPacket.SUBMIT_SM);

      submitSm = (SubmitSm) packet;
      Assert.assertEquals(submitSm.getShortMessage(), "This is the second message.");

      totalTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
      Assert.assertNotNull(totalTlv);
      Assert.assertEquals(ByteArrayUtil.toByte(totalTlv.getValue()), 2);

      segmentTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
      Assert.assertNotNull(segmentTlv);
      Assert.assertEquals(ByteArrayUtil.toByte(segmentTlv.getValue()), 2);

      msgRefTlv = submitSm.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
      Assert.assertNotNull(msgRefTlv);
    } finally {
      connector.doStop();
    }
  }
Example #12
0
  @Test
  public void testProcessMessage() throws Exception {
    log.info("starting testProcessMessage ... ");

    MockPacketProcessor pp =
        new MockPacketProcessor(
            new PacketProcessor() {

              @Override
              public void processPacket(SmppRequest packet, ResponseSender responseSender) {
                if (packet.getCommandId() == SmppPacket.SUBMIT_SM) {
                  responseSender.send(Response.OK.withMessageId("12000"));
                  return;
                }

                responseSender.send(Response.OK);
              }
            });
    server.setPacketProcessor(pp);

    MessageStore messageStore = Mockito.mock(MessageStore.class);

    Message m = new Message();
    m.setProperty("to", "3002175604");
    m.setProperty("from", "3542");

    Mockito.when(messageStore.list(Mockito.any(MessageCriteria.class)))
        .thenReturn(Collections.singletonList(m));

    SmppConfiguration configuration = new SmppConfiguration();
    configuration.setHost("localhost");
    configuration.setPort(SERVER_PORT);
    configuration.setSystemId("test");
    configuration.setPassword("test");
    configuration.setDataCoding(3);

    SmppConnector connector = new SmppConnector(configuration);
    injectResource(new MockProcessorContext(), connector);
    injectResource(messageStore, connector);
    connector.doStart();
    waitUntilStatus(connector, DEFAULT_TIMEOUT, Status.OK);

    try {
      Message message = new Message();
      message.setProperty("to", "3002175604");
      message.setProperty("from", "3542");
      message.setProperty("text", "This is the test with ñ");

      connector.process(message);

      Assert.assertNotNull(message.getReference());

      Mockito.verify(messageStore, Mockito.timeout(1000)).saveOrUpdate(Mockito.any(Message.class));

      List<SmppPacket> packets = pp.getPackets(1, DEFAULT_TIMEOUT);
      Assert.assertNotNull(packets);
      Assert.assertEquals(packets.size(), 1);

      SubmitSm submitSM = (SubmitSm) packets.get(0);
      Assert.assertNotNull(submitSM);
      Assert.assertEquals(submitSM.getDestAddress().getAddress(), "3002175604");
      Assert.assertEquals(submitSM.getSourceAddress().getAddress(), "3542");
      Assert.assertEquals(submitSM.getDataCoding(), 3);

      Assert.assertEquals(submitSM.getShortMessage(), "This is the test with ñ");
    } finally {
      connector.doStop();
    }
  }
Example #13
0
  /** Cleans the table and reloads the data. */
  public void loadData() {
    removeAllItems();

    MessageCriteria criteria =
        new MessageCriteria()
            .direction(Direction.TO_CONNECTIONS)
            .orderBy("id")
            .orderType(OrderType.DOWNWARDS)
            .numRecords(2000);
    Collection<Message> messages = messageStore.list(criteria);

    messagesMap = new HashMap<Long, Message>();
    for (Message message : messages) {
      messagesMap.put(message.getId(), message);
    }

    for (Message message : messages) {

      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

      Timestamp receiptDate = message.getProperty("receiptTime", Timestamp.class);
      String strReceiptDate = "";
      if (receiptDate != null) {
        strReceiptDate = sdf.format(receiptDate);
      }

      Object[] data =
          new Object[] {
            message.getId(),
            sdf.format(message.getCreationTime()),
            message.getSource(),
            message.getDestination(),
            message.getStatus().toString(),
            message.getProperty("to", String.class),
            message.getProperty("from", String.class),
            message.getProperty("sequenceNumber", Integer.class),
            message.getProperty("messageId", String.class),
            message.getProperty("commandStatus", Integer.class),
            message.getProperty("receiptStatus", String.class),
            strReceiptDate,
            message.getProperty("text", String.class)
          };
      addItem(data, message.getId());
    }
  }