Beispiel #1
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;
  }
Beispiel #2
0
 public void testSyncResponse() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage message = client.send("http://localhost:28081", "request", null);
   assertNotNull(message);
   assertEquals("Received: request", new String(message.getPayloadAsBytes()));
 }