コード例 #1
0
  // //@Override
  protected void initialise(MuleMessage message) {
    if (message.getPayload() instanceof List) {
      // get a copy of the list
      List payload = new LinkedList((List) message.getPayload());
      payloadContext.set(payload);

      if (enableCorrelation != ENABLE_CORRELATION_NEVER) {
        // always set correlation group size, even if correlation id
        // has already been set (usually you don't have group size yet
        // by this point.
        final int groupSize = payload.size();
        message.setCorrelationGroupSize(groupSize);
        if (logger.isDebugEnabled()) {
          logger.debug(
              "java.util.List payload detected, setting correlation group size to " + groupSize);
        }
      }
    } else {
      throw new IllegalArgumentException(
          "The payload for this router must be of type java.util.List");
    }

    // Cache the properties here because for some message types getting the
    // properties can be expensive
    Map props = new HashMap();
    for (Iterator iterator = message.getPropertyNames().iterator(); iterator.hasNext(); ) {
      String propertyKey = (String) iterator.next();
      props.put(propertyKey, message.getProperty(propertyKey));
    }

    propertiesContext.set(props);
  }
コード例 #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;
  }
コード例 #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());
  }
コード例 #4
0
  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));
    }
  }