Esempio n. 1
0
  public void testMessageResequencer() throws Exception {
    MuleSession session = getTestSession(getTestService(), muleContext);
    Service testService = getTestService("test", Apple.class);
    assertNotNull(testService);

    SimpleEventResequencer router = new SimpleEventResequencer(3);
    router.setMuleContext(muleContext);
    router.initialise();

    MuleMessage message1 = new DefaultMuleMessage("test event A");
    MuleMessage message2 = new DefaultMuleMessage("test event B");
    MuleMessage message3 = new DefaultMuleMessage("test event C");
    message1.setCorrelationId(message1.getUniqueId());
    message2.setCorrelationId(message1.getUniqueId());
    message3.setCorrelationId(message1.getUniqueId());

    ImmutableEndpoint endpoint = getTestOutboundEndpoint("Test1Provider");
    MuleEvent event1 = new DefaultMuleEvent(message1, endpoint, session, false);
    MuleEvent event2 = new DefaultMuleEvent(message2, endpoint, session, false);
    MuleEvent event3 = new DefaultMuleEvent(message3, endpoint, session, false);
    assertTrue(router.isMatch(event1));
    assertTrue(router.isMatch(event2));
    assertTrue(router.isMatch(event3));

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    MuleEvent[] results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event B", results[0].getMessageAsString());
    assertEquals("test event C", results[1].getMessageAsString());
    assertEquals("test event A", results[2].getMessageAsString());

    // set a resequencing comparator. We need to reset the router since it will not process the same
    // event group
    // twice
    router = new SimpleEventResequencer(3);
    router.setMuleContext(muleContext);
    router.setEventComparator(new EventPayloadComparator());
    router.initialise();

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event A", results[0].getMessageAsString());
    assertEquals("test event B", results[1].getMessageAsString());
    assertEquals("test event C", results[2].getMessageAsString());
  }
Esempio n. 2
0
  public MuleMessage route(MuleMessage message, MuleSession session) throws RoutingException {
    if (messageSize == 0 && numberOfMessages < 2) {
      return super.route(message, session);
    } else if (messageSize > 0) {
      byte[] data = new byte[0];
      try {
        data = message.getPayloadAsBytes();
      } catch (Exception e) {
        throw new RoutingException(
            CoreMessages.failedToReadPayload(), message, getEndpoint(0, message), e);
      }

      int parts = data.length / messageSize;
      if ((parts * messageSize) < data.length) {
        parts++;
      }
      int len = messageSize;
      MuleMessage part = null;
      int count = 0;
      int pos = 0;
      byte[] buffer = null;
      try {
        for (; count < parts; count++) {
          if ((pos + len) > data.length) {
            len = data.length - pos;
          }
          buffer = new byte[len];
          System.arraycopy(data, pos, buffer, 0, buffer.length);
          pos += len;
          part = new DefaultMuleMessage(buffer, message);
          part.setCorrelationId(message.getUniqueId());
          part.setCorrelationGroupSize(parts);
          part.setCorrelationSequence(count);
          // TODO - remove or downgrade once MULE-1718 is fixed,
          // for now these really help see the problem if you set the level for this class to INFO
          if (logger.isInfoEnabled()) {
            logger.info("sending part " + count + " of " + parts);
          }
          super.route(part, session);
          if (logger.isInfoEnabled()) {
            logger.info("sent");
          }
        }

      } catch (RoutingException e) {
        // we'll want to send the whole message to the Exception handler
        e =
            new RoutingException(
                e.getI18nMessage(), e.getMuleMessage(), e.getEndpoint(), e.getCause());
        // e.addInfo("chunking", "true");
        // buffer = new byte[data.length - len];
        // System.arraycopy(data, len, buffer, 0, buffer.length);
        // e.addInfo("remaining data", buffer);
        throw e;
      }
    }
    return message;
  }
Esempio n. 3
0
  public void testResponseEventsCleanedUp() throws Exception {
    // relax access to get to the responseEvents
    RelaxedResponseAggregator aggregator = new RelaxedResponseAggregator();

    MuleEvent event = getTestEvent("message1");
    final MuleMessage message = event.getMessage();
    final String id = message.getUniqueId();
    message.setCorrelationId(id);
    message.setCorrelationGroupSize(1);
    aggregator.process(event);

    aggregator.getResponse(message);

    Map responseEvents = aggregator.getResponseEvents();
    assertTrue("Response events should be cleaned up.", responseEvents.isEmpty());
  }
  public void handleMessage(Message m) throws Fault {
    if (!(m instanceof SoapMessage)) {
      return;
    }

    SoapMessage message = (SoapMessage) m;
    if (!message.hasHeaders()) {
      return;
    }
    Header mule_header = message.getHeader(MULE_HEADER_Q);
    if (mule_header == null) {
      return;
    }
    Object obj = mule_header.getObject();
    if (!(obj instanceof Element)) {
      // Error? We can't work with it at any rate.
      return;
    }

    Element header_element = (Element) obj;
    NodeList mule_headers = header_element.getChildNodes();
    int idx = 0;
    Node child;
    while ((child = mule_headers.item(idx++)) != null) {
      if (child.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element child_el = (Element) child;
      if (child_el.getNamespaceURI() == null || !child_el.getNamespaceURI().equals(MULE_NS_URI)) {
        continue;
      }

      if (SUPPORTED_HEADERS.contains(child_el.getLocalName())) {
        message.put(child_el.getLocalName(), collectTextFrom(child_el));
      }
    }

    MuleMessage reqMsg =
        ((MuleEvent) message.getExchange().get(CxfConstants.MULE_EVENT)).getMessage();

    // Copy correlation headers nto message
    String replyTo = (String) message.get(MuleProperties.MULE_REPLY_TO_PROPERTY);
    if (replyTo != null) {
      reqMsg.setReplyTo(replyTo);
    }

    String corId = (String) message.get(MuleProperties.MULE_CORRELATION_ID_PROPERTY);
    if (corId != null) {
      reqMsg.setCorrelationId(corId);
    }

    String corGroupSize = (String) message.get(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY);
    if (corGroupSize != null) {
      reqMsg.setCorrelationGroupSize(Integer.valueOf(corGroupSize));
    }

    String corSeq = (String) message.get(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY);
    if (corSeq != null) {
      reqMsg.setCorrelationSequence(Integer.valueOf(corSeq));
    }
  }