Changeset 1924


Ignore:
Timestamp:
03/18/15 09:58:50 (9 years ago)
Author:
sherbold
Message:
  • SimpleSOAPEvent now contains body of the SOAP request
  • SOAPUtils created
Location:
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http
Files:
1 added
3 edited

Legend:

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

    r1923 r1924  
    1515package de.ugoe.cs.autoquest.plugin.http; 
    1616 
    17 import java.util.Iterator; 
    18 import java.util.LinkedList; 
    19 import java.util.List; 
    20  
    21 import de.ugoe.cs.autoquest.eventcore.Event; 
    22 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
    23 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 
    2417import de.ugoe.cs.autoquest.plugin.http.logdata.Address; 
    2518 
     
    128121    /** 
    129122     * <p> 
    130      * Replaces events with a {@link SOAPEventType} with new events of {@link SimpleSOAPEventType} 
    131      * and no target. 
    132      * </p> 
    133      *  
    134      * @param sequence 
    135      *            sequence where the events are replaced 
    136      * @param keepOnlySOAPEvents 
    137      *            if true, all events that are not of SOAPEventType or SimpleSOAPEventType are 
    138      *            removed 
    139      * @return sequence with {@link SimpleSOAPEventType}s instead of {@link SOAPEventType}s 
    140      */ 
    141     public static List<Event> convertToSimpleSOAPEvent(List<Event> sequence, 
    142                                                        boolean keepOnlySOAPEvents) 
    143     { 
    144         List<Event> newSequence = null; 
    145         if (sequence != null) { 
    146             newSequence = new LinkedList<>(); 
    147             for (Event event : sequence) { 
    148                 if (event.getType() instanceof SOAPEventType) { 
    149                     SOAPEventType eventType = (SOAPEventType) event.getType(); 
    150                     newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(), 
    151                                                                       eventType.getServiceName(), 
    152                                                                       eventType.getClientName()))); 
    153                 } 
    154                 else { 
    155                     if (!keepOnlySOAPEvents || event.getType() instanceof SimpleSOAPEventType) { 
    156                         newSequence.add(event); 
    157                     } 
    158                 } 
    159             } 
    160         } 
    161         return newSequence; 
    162     } 
    163      
    164     /** 
    165      * <p> 
    166      * Removes all non SOAP events from a sequence. Warning: this change is performed in-place! 
    167      * </p> 
    168      *  
    169      * @param sequence 
    170      *            sequence where the events are replaced 
    171      */ 
    172     public static void removeNonSOAPEvents(List<Event> sequence) 
    173     { 
    174         for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
    175             Event event = eventIter.next(); 
    176             if (!(event.getType() instanceof SOAPEventType)) { 
    177                 eventIter.remove(); 
    178             } 
    179         } 
    180     } 
    181  
    182     /** 
    183      * <p> 
    184123     * prevent instantiation 
    185124     * </p> 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SOAPEventType.java

    r1912 r1924  
    2323import javax.xml.soap.SOAPMessage; 
    2424 
     25import org.w3c.dom.Element; 
     26 
    2527import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 
    2628import de.ugoe.cs.autoquest.plugin.http.logdata.Header; 
     
    256258        return soapResponse; 
    257259    } 
     260     
     261    /** 
     262     * @return the body of the soapRequest 
     263     */ 
     264    public Element getSoapRequestBody() { 
     265        try { 
     266            return soapRequest.getSOAPBody(); 
     267        } 
     268        catch (SOAPException e) { 
     269            return null; 
     270        } 
     271    } 
    258272 
    259273    /* (non-Javadoc) 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java

    r1913 r1924  
    1515package de.ugoe.cs.autoquest.plugin.http.eventcore; 
    1616 
     17import java.io.ByteArrayInputStream; 
     18import java.io.IOException; 
     19 
     20import javax.xml.parsers.DocumentBuilderFactory; 
     21import javax.xml.parsers.ParserConfigurationException; 
     22 
     23import org.w3c.dom.Element; 
     24import org.xml.sax.SAXException; 
     25 
    1726import de.ugoe.cs.autoquest.eventcore.IEventType; 
    1827import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 
     28import de.ugoe.cs.autoquest.plugin.http.SOAPUtils; 
    1929 
    2030/** 
     
    4454     */ 
    4555    private final String serviceName; 
    46      
     56 
    4757    /** 
    4858     * <p> 
    49      * the name of the client; this is either the host/ip and port of the sender or, if a path 
    50      * map is available, a human readable name that may be based also on the receiver 
     59     * the name of the client; this is either the host/ip and port of the sender or, if a path map 
     60     * is available, a human readable name that may be based also on the receiver 
    5161     * </p> 
    5262     */ 
    5363    private final String clientName; 
     64 
     65    /** 
     66     * <p> 
     67     * the body of the SOAP request; storage as serialized XML string to allow object serialization 
     68     * </p> 
     69     */ 
     70    private final String soapRequestBody; 
    5471 
    5572    /** 
     
    5976     *  
    6077     */ 
    61     public SimpleSOAPEventType(String calledMethod, String serviceName, String clientName) { 
     78    public SimpleSOAPEventType(String calledMethod, 
     79                               String serviceName, 
     80                               String clientName, 
     81                               Element soapRequestBody) 
     82    { 
    6283        if (calledMethod == null) { 
    6384            throw new IllegalArgumentException("called method must not be null"); 
     
    6990            throw new IllegalArgumentException("clientName must not be null"); 
    7091        } 
     92        if (soapRequestBody == null) { 
     93            throw new IllegalArgumentException("soapRequestBody must not be null"); 
     94        } 
    7195        this.calledMethod = calledMethod; 
    7296        this.serviceName = serviceName; 
    7397        this.clientName = clientName; 
     98        this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody); 
    7499    } 
    75100 
     
    95120        return serviceName; 
    96121    } 
    97      
     122 
    98123    /** 
    99124     * <p> 
    100125     * the name of the client calling in this request 
    101126     * </p> 
    102      * 
     127     *  
    103128     * @return the name of the client calling in this request 
    104129     */ 
    105130    public String getClientName() { 
    106131        return clientName; 
     132    } 
     133 
     134    public Element getSoapRequestBody() { 
     135        try { 
     136            return DocumentBuilderFactory.newInstance().newDocumentBuilder() 
     137                .parse(new ByteArrayInputStream(soapRequestBody.getBytes())).getDocumentElement(); 
     138        } 
     139        catch (SAXException | IOException | ParserConfigurationException e) { 
     140            return null; 
     141        } 
    107142    } 
    108143 
     
    129164        else if (obj instanceof SimpleSOAPEventType) { 
    130165            return HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) && 
    131                 HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName); 
     166                HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName) && 
     167                HTTPUtils.equals(clientName, ((SimpleSOAPEventType) obj).clientName); 
    132168        } 
    133169        else { 
     
    143179    @Override 
    144180    public int hashCode() { 
    145         int hashCode = calledMethod.hashCode() + serviceName.hashCode(); 
     181        int hashCode = calledMethod.hashCode() + serviceName.hashCode() + clientName.hashCode(); 
    146182        return hashCode; 
    147183    } 
    148      
    149     /* (non-Javadoc) 
     184 
     185    /* 
     186     * (non-Javadoc) 
     187     *  
    150188     * @see java.lang.Object#toString() 
    151189     */ 
Note: See TracChangeset for help on using the changeset viewer.