Package org.mokai

Examples of org.mokai.Message


    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");
      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, "3002175604"));
      deliverSM.setSourceAddress(new Address((byte) 0, (byte) 0, "3542"));
      deliverSM.setShortMessage("id:98765432101 sub:1 dlvrd:1 submit date:1101010000 done date:1101010000 stat:DELIVRD err:0 text:This is a ... ".getBytes());

      session.sendRequest(deliverSM);

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

      Message receivedMessage = (Message) messageProducer.getMessage(0);
      Assert.assertNotNull(receivedMessage);
    } finally {
      connector.doStop();
    }
  }
View Full Code Here


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

        log.warn("MessageStore is null: ignoring delivery receipt: " + dr.deliverSm.toString());
        return;
      }

      // retrieve the delivery receipt message and try to find the original message that originated the dr
      Message drMessage = dr.message;

      Message originalMessage = findOriginalMessage(drMessage);

      if (originalMessage != null) {
        deliveryReceipts.remove(dr);

        // update original message
        String receiptStatus = drMessage.getProperty("finalStatus", String.class);
        Date doneDate = drMessage.getProperty("doneDate", Date.class);

        originalMessage.setProperty("receiptStatus", receiptStatus);
        originalMessage.setProperty("receiptTime", doneDate);
        messageStore.saveOrUpdate(originalMessage);

        log.debug("message with id " + originalMessage.getId() + " updated with receiptStatus: "
            + receiptStatus);

        // update the reference of the delivery receipt
        drMessage.setProperty("originalReference", originalMessage.getReference());

        // only route delivery receipt if original message contains a receiptDestination
        String receiptDestination = originalMessage.getProperty("receiptDestination", String.class);
        if (receiptDestination != null && !"".equals(receiptDestination)) {
          drMessage.setDestination(receiptDestination); // this skips the routing mechanism
          messageProducer.produce(drMessage);
        }
      } else {
View Full Code Here

   */
  private class ConnectorProcessor implements org.apache.camel.Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
      Message message = exchange.getIn().getBody(Message.class);

      // we know we support the message
      boolean success = process(message, 1);
      if (!success) {
        exchange.setProperty(Exchange.ROUTE_STOP, true);
View Full Code Here

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

   */
  private class OutboundMessageProcessor implements org.apache.camel.Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
      Message message = exchange.getIn().getBody(Message.class);

      message.setDestination(id);
    }
View Full Code Here

     *
     * @param drMessage the delivery receipt message.
     * @return the Message that originated the delivery receipt, or null if not found.
     */
    private Message findOriginalMessage(Message drMessage) {
      Message originalMessage = null; // this is what we are returning

      String messageId = drMessage.getProperty("messageId", String.class);
      messageId = convertMessageId(messageId);
      String to = drMessage.getProperty("to", String.class);
      String from = drMessage.getProperty("from", String.class);

      MessageCriteria criteria = new MessageCriteria()
        .direction(context.getDirection())
        .addProperty("destination", context.getId())
        .addProperty("smsc_messageid", messageId);

      long startTime = new Date().getTime();
      Collection<Message> messages = messageStore.list(criteria);
      long endTime = new Date().getTime();

      log.trace(getLogHead() + "retrieve message with smsc_messageid: " + messageId + ", to: " + to + ", from: " + from + " took "
          + (endTime - startTime) + " milis");

      if (messages.size() == 1) {
        originalMessage = messages.iterator().next();
      } else if (messages.size() > 1) {
        log.debug(messages.size() + " messages matched the id: " + messageId);

        // iterate through the matched messages to find one that matches exactly
        Iterator<Message> iterMessages = messages.iterator();
        while (iterMessages.hasNext() && originalMessage == null) {
          Message message = iterMessages.next();

          String mTo = message.getProperty("to", String.class);
          if (mTo.equals(to) || mTo.equals(from)) {
            originalMessage = message;
          }
        }
      }
View Full Code Here

   */
  private class InboundMessageProcessor implements org.apache.camel.Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
      Message message = exchange.getIn().getBody(Message.class);

      message.setSource(id);

      // set the direction of the message
      if (getDirection().equals(Direction.TO_APPLICATIONS)) {
        message.setDirection(Direction.TO_CONNECTIONS);
      } else if (getDirection().equals(Direction.TO_CONNECTIONS)) {
        message.setDirection(Direction.TO_APPLICATIONS);
      } else {
        message.setDirection(Direction.UNKNOWN);
      }

    }
View Full Code Here

    this.resourceRegistry = resourceRegistry;
  }

  @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() == null;

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

*/
public class PersistenceRouter {

  @RecipientList
  public final String route(Exchange exchange) {
    Message message = exchange.getIn().getBody(Message.class);

    if (message.getStatus() == Message.STATUS_PROCESSED) {
      return "direct:processedmessages";
    }

    return "activemq:failedmessages";
  }
View Full Code Here

TOP

Related Classes of org.mokai.Message

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.