Index: trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java
===================================================================
--- trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java	(revision 1990)
+++ trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java	(revision 1992)
@@ -18,7 +18,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.transform.Transformer;
@@ -51,4 +53,19 @@
     /**
      * <p>
+     * Defines how sequences are ordered:
+     * <ul>
+     * <li>REQUEST: by the request order id</li>
+     * <li>RESPONSE: by the response order id</li>
+     * </ul>
+     * </p>
+     * 
+     * @author Steffen Herbold
+     */
+    public enum SequenceOrder {
+        REQUEST, RESPONSE
+    }
+
+    /**
+     * <p>
      * Replaces events with a {@link SOAPEventType} with new events of {@link SimpleSOAPEventType}
      * and no target.
@@ -63,9 +80,9 @@
      */
     public static Collection<List<Event>> convertToSimpleSOAPEvent(Collection<List<Event>> sequences,
-                                                       boolean keepOnlySOAPEvents)
+                                                                   boolean keepOnlySOAPEvents)
     {
         Collection<List<Event>> newSequences = new LinkedList<>();
         EqualSOAPDataMap equalSOAPDataMap = new EqualSOAPDataMap();
-        for( List<Event> sequence : sequences ) {
+        for (List<Event> sequence : sequences) {
             List<Event> newSequence = null;
             if (sequence != null) {
@@ -74,10 +91,7 @@
                     if (event.getType() instanceof SOAPEventType) {
                         SOAPEventType eventType = (SOAPEventType) event.getType();
-                        newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(),
-                                                                          eventType.getServiceName(),
-                                                                          eventType.getClientName(),
-                                                                          eventType
-                                                                              .getSoapRequestBody(),
-                                                                          equalSOAPDataMap)));
+                        newSequence.add(new Event(new SimpleSOAPEventType(eventType
+                            .getCalledMethod(), eventType.getServiceName(), eventType
+                            .getClientName(), eventType.getSoapRequestBody(), equalSOAPDataMap)));
                     }
                     else {
@@ -92,8 +106,24 @@
         return newSequences;
     }
-    
-    /**
-     * <p>
-     * Removes all non SOAP events from a sequence. Warning: this change is performed in-place!
+
+    /**
+     * <p>
+     * Removes all non SOAP events from the contained sequences
+     * </p>
+     * 
+     * @param sequences
+     *            sequences where the events are replaced
+     */
+    public static Collection<List<Event>> removeNonSOAPEvents(Collection<List<Event>> sequences) {
+        Collection<List<Event>> soapOnlySequences = new LinkedList<>();
+        for (List<Event> sequence : sequences) {
+            soapOnlySequences.add(removeNonSOAPEvents(sequence));
+        }
+        return soapOnlySequences;
+    }
+
+    /**
+     * <p>
+     * Removes all non SOAP events from a sequence
      * </p>
      * 
@@ -101,11 +131,12 @@
      *            sequence where the events are replaced
      */
-    public static void removeNonSOAPEvents(List<Event> sequence) {
-        for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) {
-            Event event = eventIter.next();
-            if (!(event.getType() instanceof SOAPEventType)) {
-                eventIter.remove();
-            }
-        }
+    public static List<Event> removeNonSOAPEvents(List<Event> sequence) {
+        List<Event> soapOnlySequence = new LinkedList<>();
+        for (Event event : sequence) {
+            if (event.getType() instanceof SOAPEventType) {
+                soapOnlySequence.add(event);
+            }
+        }
+        return soapOnlySequence;
     }
 
@@ -192,5 +223,5 @@
         return getSoapRequestBodyFromEvent(event, false);
     }
-    
+
     /**
      * <p>
@@ -210,7 +241,8 @@
         }
         else if (event.getType() instanceof SimpleSOAPEventType) {
-            if( useRandomRequestBodies ) {
+            if (useRandomRequestBodies) {
                 requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapRequestBody();
-            } else {
+            }
+            else {
                 requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody();
             }
@@ -316,15 +348,20 @@
         return attributeValues;
     }
-    
-    /**
-     * <p>
-     * Allows the removal of pre- and suffixes from SOAP operation names in {@link SimpleSOAPEventType}. 
-     * </p>
-     *
-     * @param sequences sequences where the operation names are normalized
-     */
-    public static Collection<List<Event>> normalizeOperationNames(Collection<List<Event>> sequences, String prefixToRemove, String suffixToRemove) {
+
+    /**
+     * <p>
+     * Allows the removal of pre- and suffixes from SOAP operation names in
+     * {@link SimpleSOAPEventType}.
+     * </p>
+     * 
+     * @param sequences
+     *            sequences where the operation names are normalized
+     */
+    public static Collection<List<Event>> normalizeOperationNames(Collection<List<Event>> sequences,
+                                                                  String prefixToRemove,
+                                                                  String suffixToRemove)
+    {
         Collection<List<Event>> normalizedSequences = new LinkedList<>();
-        for(List<Event> sequence : sequences ) {
+        for (List<Event> sequence : sequences) {
             List<Event> normalizedSequence = new LinkedList<>();
             for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) {
@@ -333,12 +370,19 @@
                     SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType();
                     String methodName = eventType.getCalledMethod();
-                    if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) {
-                        methodName = methodName.substring(prefixToRemove.length(), methodName.length());
+                    if (prefixToRemove != null && methodName.startsWith(prefixToRemove)) {
+                        methodName =
+                            methodName.substring(prefixToRemove.length(), methodName.length());
                         // remove prefix
-                    } 
-                    if( suffixToRemove!=null && methodName.endsWith(suffixToRemove) ) {
-                        methodName = methodName.substring(0, methodName.length()-suffixToRemove.length());
-                    }
-                    event = new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), eventType.getClientName(), eventType.getSoapRequestBody(), eventType.getEqualSOAPDataMap()), event.getTarget());
+                    }
+                    if (suffixToRemove != null && methodName.endsWith(suffixToRemove)) {
+                        methodName =
+                            methodName.substring(0, methodName.length() - suffixToRemove.length());
+                    }
+                    event =
+                        new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(),
+                                                          eventType.getClientName(),
+                                                          eventType.getSoapRequestBody(),
+                                                          eventType.getEqualSOAPDataMap()),
+                                  event.getTarget());
                 }
                 normalizedSequence.add(event);
@@ -347,4 +391,113 @@
         }
         return normalizedSequences;
+    }
+
+    /**
+     * <p>
+     * Sorts the sequences by the orderingId of the requests/responses. This function only supports
+     * the ordering of {@link Event}s with a {@link SOAPEventType}.
+     * </p>
+     * 
+     * @param sequences
+     *            sequences to be order
+     * @param orderType
+     *            determines if sequences are ordered by request or response
+     * @return sorted sequences
+     */
+    public static Collection<List<Event>> sortSequences(Collection<List<Event>> sequences,
+                                                        SequenceOrder orderType)
+    {
+        Collection<List<Event>> sortedSequences = new LinkedList<>();
+        for (List<Event> sequence : sequences) {
+            // use insertion sort
+            List<Event> sortedSequence = new LinkedList<>();
+            long lastOrderId = Long.MIN_VALUE;
+            long selectedOrderId;
+            Event selectedEvent;
+            while (sortedSequence.size() != sequence.size()) {
+                selectedEvent = null;
+                selectedOrderId = Long.MAX_VALUE;
+                for (Event event : sequence) {
+                    if (!(event.getType() instanceof SOAPEventType)) {
+                        throw new RuntimeException(
+                                                   "Can only order SOAPEventTypes. SimpleSOAPEvent is also not supported. Event type found: " +
+                                                       event.getType().getClass().getName());
+                    }
+                    SOAPEventType soapEventType = (SOAPEventType) event.getType();
+                    long eventOrderId;
+                    switch (orderType)
+                    {
+                        case REQUEST:
+                            eventOrderId = soapEventType.getExchange().getRequest().getOrderingId();
+                            break;
+                        case RESPONSE:
+                            eventOrderId =
+                                soapEventType.getExchange().getResponse().getOrderingId();
+                            break;
+                        default:
+                            throw new RuntimeException("unsupported order type: " +
+                                orderType.toString());
+                    }
+                    if (eventOrderId > lastOrderId && eventOrderId < selectedOrderId) {
+                        selectedOrderId = eventOrderId;
+                        selectedEvent = event;
+                    }
+                }
+                if (selectedEvent != null) {
+                    sortedSequence.add(selectedEvent);
+                    lastOrderId = selectedOrderId;
+                }
+                else {
+                    throw new RuntimeException(
+                                               "could not select next event; possibly the same order Id for multiple exchanges events!?");
+                }
+            }
+            sortedSequences.add(sortedSequence);
+        }
+        return sortedSequences;
+    }
+    
+    /**
+     * <p>
+     * Removes calls to and from all ignored services from the sequences.
+     * </p>
+     *
+     * @param sequences sequences where the ignored services are removed
+     * @param ignoredServicesString comma separted string that defines the ignored services
+     * @return sequences without events that reference the ignored services
+     */
+    public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, String ignoredServicesString) {
+        Set<String> ignoredServices = new HashSet<>();
+        if (ignoredServicesString != null) {
+            for (String service : ignoredServicesString.split(",")) {
+                ignoredServices.add(service.trim());
+            }
+        }
+        return removeCallsToIgnoredServices(sequences, ignoredServices);
+    }
+    
+    /**
+     * <p>
+     * Removes calls to and from all ignored services from the sequences.
+     * </p>
+     *
+     * @param sequences sequences where the ignored services are removed
+     * @param ignoredServices set with all ignored service names
+     * @return sequences without events that reference the ignored services
+     */
+    public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, Set<String> ignoredServices) {
+        Collection<List<Event>> onlyAcceptedServicesSequences = new LinkedList<>();
+        for (List<Event> sequence : sequences) {
+            List<Event> onlyAcceptedServicesSequence = new LinkedList<>();
+            for (Event event : sequence) {
+                SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType();
+                if (!ignoredServices.contains(eventType.getServiceName()) &&
+                    !ignoredServices.contains(eventType.getClientName()) ) {
+                    onlyAcceptedServicesSequence.add(event);
+                }
+            }
+            onlyAcceptedServicesSequences.add(onlyAcceptedServicesSequence);
+        }
+        return onlyAcceptedServicesSequences;
     }
 
