Ignore:
Timestamp:
07/14/15 10:57:19 (9 years ago)
Author:
sherbold
Message:
  • extended SOAP utils with function that removes all invalid request/response pairs from a sequence of SimpleSOAPEvents
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java

    r1994 r2003  
    2323import java.util.List; 
    2424import java.util.Set; 
     25import java.util.Stack; 
     26import java.util.logging.Level; 
    2527 
    2628import javax.xml.transform.Transformer; 
     
    4143import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 
    4244import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType; 
     45import de.ugoe.cs.util.console.Console; 
    4346 
    4447/** 
     
    690693    /** 
    691694     * <p> 
     695     * Drops all requests without responses as well as invalid request/response orders. Only the 
     696     * part of the sequence before the first invalid occurrence is kept. 
     697     * </p> 
     698     *  
     699     * @param sequences 
     700     *            sequences where the invalid pairs are dropped 
     701     * @return sequences with only valid and complete interactions 
     702     */ 
     703    public static Collection<List<Event>> dropInvalidResponseRequestPairs(Collection<List<Event>> sequences) 
     704    { 
     705        Collection<List<Event>> validSequences = new LinkedList<>(); 
     706        int i = 0; 
     707        for (List<Event> sequence : sequences) { 
     708            List<Event> validSequence = dropInvalidResponseRequestPairs(sequence); 
     709            if (validSequence.isEmpty() || 
     710                (validSequence.size() <= 2 && validSequence.get(0) == Event.STARTEVENT)) 
     711            { 
     712                Console.traceln(Level.INFO, "dropped sequence " + i + 
     713                    ": empty after removal of invalid request/response pairs"); 
     714            } 
     715            validSequences.add(validSequence); 
     716            i++; 
     717        } 
     718        return validSequences; 
     719    } 
     720 
     721    /** 
     722     * <p> 
     723     * Drops all requests without responses as well as invalid request/response orders. Only the 
     724     * part of the sequence before the first invalid occurrence is kept. 
     725     * </p> 
     726     *  
     727     * @param sequence 
     728     *            sequence where the invalid pairs are dropped 
     729     * @return sequence with only valid and complete interactions 
     730     */ 
     731    public static List<Event> dropInvalidResponseRequestPairs(List<Event> sequence) { 
     732        Stack<SimpleSOAPEventType> unrespondedRequests = new Stack<>(); 
     733        boolean hasStartEvent = false; 
     734        int lastValidIndex = 0; 
     735        int i = 0; 
     736        for (Event event : sequence) { 
     737            if (event == Event.STARTEVENT) { 
     738                hasStartEvent = true; 
     739                lastValidIndex = i; 
     740            } 
     741            else if (event.getType() instanceof SimpleSOAPEventType) { 
     742                SimpleSOAPEventType currentEventType = (SimpleSOAPEventType) event.getType(); 
     743                if (SOAPUtils.isSOAPRequest(event)) { 
     744                    unrespondedRequests.push(currentEventType); 
     745                } 
     746                else if (SOAPUtils.isSOAPResponse(event)) { 
     747                    if (unrespondedRequests.empty()) { 
     748                        break; // found a response without previous request; sequence invalid from 
     749                               // here 
     750                    } 
     751                    else { 
     752                        SimpleSOAPEventType lastRequest = unrespondedRequests.peek(); 
     753                        if (isRequestResponseMatch(lastRequest, currentEventType)) { 
     754                            unrespondedRequests.pop(); 
     755                            if (unrespondedRequests.empty()) { 
     756                                lastValidIndex = i; 
     757                            } 
     758                        } 
     759                    } 
     760 
     761                } 
     762            } 
     763            i++; 
     764        } 
     765        List<Event> validSequence = new LinkedList<>(sequence.subList(0, lastValidIndex + 1)); 
     766        if (hasStartEvent) { 
     767            validSequence.add(Event.ENDEVENT); 
     768        } 
     769        return validSequence; 
     770    } 
     771 
     772    /** 
     773     * <p> 
     774     * Checks if two {@link SimpleSOAPEventType} types are equal except their {@link CallType}, 
     775     * which must be {@value CallType#REQUEST} for the first parameter and {@link CallType#RESPONSE} 
     776     * for the second parameter. 
     777     * </p> 
     778     *  
     779     * @param request 
     780     *            request soap event 
     781     * @param response 
     782     *            response soap event 
     783     * @return true if they are a matching request/response pair 
     784     */ 
     785    public static boolean isRequestResponseMatch(SimpleSOAPEventType request, 
     786                                                 SimpleSOAPEventType response) 
     787    { 
     788        if (request == null && response == null) { 
     789            return true; 
     790        } 
     791        if ((request != null && response == null) || (request == null && response != null)) { 
     792            return false; 
     793        } 
     794        return request.getCallType().equals(CallType.REQUEST) && 
     795            response.getCallType().equals(CallType.RESPONSE) && 
     796            HTTPUtils.equals(request.getCalledMethod(), response.getCalledMethod()) && 
     797            HTTPUtils.equals(request.getServiceName(), response.getServiceName()) && 
     798            HTTPUtils.equals(request.getClientName(), response.getClientName()); 
     799    } 
     800 
     801    /** 
     802     * <p> 
    692803     * prevent instantiation 
    693804     * </p> 
Note: See TracChangeset for help on using the changeset viewer.