Exemple #1
0
 /**
  * This method is invoked if the shouldAggregate method is called and returns true. Once this
  * method returns an aggregated message the event group is removed from the router
  *
  * @param events the event group for this request
  * @return an aggregated message
  * @throws org.mule.routing.AggregationException if the aggregation fails. in this scenario the
  *     whole event group is removed and passed to the exception handler for this componenet
  */
 protected UMOMessage aggregateEvents(EventGroup events) throws AggregationException {
   List eventList = IteratorUtils.toList(events.iterator(), events.size());
   UMOEvent firstEvent = (UMOEvent) eventList.get(0);
   Collections.sort(eventList, SequenceComparator.getInstance());
   ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
   try {
     for (Iterator iterator = eventList.iterator(); iterator.hasNext(); ) {
       UMOEvent event = (UMOEvent) iterator.next();
       baos.write(event.getMessageAsBytes());
     }
     UMOMessage message = new MuleMessage(baos.toByteArray(), firstEvent.getMessage());
     message.setCorrelationGroupSize(-1);
     message.setCorrelationSequence(-1);
     return message;
   } catch (Exception e) {
     throw new AggregationException(events, firstEvent.getEndpoint(), e);
   } finally {
     IOUtils.closeQuietly(baos);
   }
 }
Exemple #2
0
 /**
  * Reterns the conents of the message as a byte array.
  *
  * @return the conents of the message as a byte array
  * @throws org.mule.umo.UMOException if the message cannot be converted into an array of bytes
  */
 public byte[] getMessageAsBytes() throws UMOException {
   return event.getMessageAsBytes();
 }