Changeset 2003 for trunk/autoquest-plugin-http/src
- Timestamp:
- 07/14/15 10:57:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java
r1994 r2003 23 23 import java.util.List; 24 24 import java.util.Set; 25 import java.util.Stack; 26 import java.util.logging.Level; 25 27 26 28 import javax.xml.transform.Transformer; … … 41 43 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 42 44 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType; 45 import de.ugoe.cs.util.console.Console; 43 46 44 47 /** … … 690 693 /** 691 694 * <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> 692 803 * prevent instantiation 693 804 * </p>
Note: See TracChangeset
for help on using the changeset viewer.