Ignore:
Timestamp:
02/28/14 12:23:40 (11 years ago)
Author:
pharms
Message:
  • made the plugin a real plugin
  • added first extraction of SOAP information
  • implemented equals and hash code correctly
  • parsed events can now be used to generate task trees
Location:
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http
Files:
2 added
4 edited

Legend:

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

    r1383 r1417  
    1515package de.ugoe.cs.autoquest.plugin.http; 
    1616 
     17import java.io.ByteArrayInputStream; 
    1718import java.io.File; 
     19import java.io.InputStream; 
    1820import java.util.Collection; 
    1921import java.util.LinkedList; 
    2022import java.util.List; 
     23import java.util.logging.Level; 
    2124 
    2225import javax.xml.bind.JAXBContext; 
     
    2427import javax.xml.bind.JAXBException; 
    2528import javax.xml.bind.Unmarshaller; 
     29import javax.xml.soap.MessageFactory; 
     30import javax.xml.soap.SOAPMessage; 
    2631import javax.xml.transform.stream.StreamSource; 
    2732 
     
    2934 
    3035import de.ugoe.cs.autoquest.eventcore.Event; 
     36import de.ugoe.cs.autoquest.eventcore.IEventType; 
     37import de.ugoe.cs.autoquest.httpmonitor.exchange.Content; 
    3138import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange; 
    3239import de.ugoe.cs.autoquest.httpmonitor.exchange.Session; 
    3340import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType; 
    3441import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPTarget; 
     42import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
     43import de.ugoe.cs.util.console.Console; 
    3544 
    3645/** 
    3746 * <p> 
    3847 * Parser for HTTP Monitor logs. Uses JAXB for parsing and is therefore quite simple. For each 
    39  * exchange in the log, it creates an appropriate event. 
     48 * exchange in the log, it creates an appropriate event. It differes between default HTTP events 
     49 * and SOAP events. 
    4050 * </p> 
    4151 *  
     
    5060     */ 
    5161    private Collection<List<Event>> sequences = new LinkedList<List<Event>>(); 
     62     
     63    /** 
     64     * <p> 
     65     * the message factory used for parsing SOAP messages 
     66     * </p> 
     67     */ 
     68    private MessageFactory soapMessageFactory; 
    5269 
    5370    /** 
     
    97114            List<Event> sequence = new LinkedList<Event>(); 
    98115            for (HttpExchange exchange : session.getHttpExchange()) { 
    99                 sequence.add(new Event(new HTTPEventType(exchange), 
     116                sequence.add(new Event(createEvent(exchange), 
    100117                                       new HTTPTarget(exchange.getReceiver()))); 
    101118            } 
     
    107124    /** 
    108125     * <p> 
     126     * instantiates the appropriate event type. If it encounters a SOAP exchange, a SOAP event type 
     127     * is instantiated. Otherwise a normal HTTP event type is created. 
     128     * </p> 
     129     * 
     130     * @param exchange the exchange for which an event type is to be created 
     131     *  
     132     * @return as described 
     133     */ 
     134    private IEventType createEvent(HttpExchange exchange) { 
     135        Content requestContent = 
     136            exchange.getRequest() != null ? exchange.getRequest().getContent() : null; 
     137         
     138        SOAPMessage soapRequest = getSOAPMessage(requestContent); 
     139         
     140        Content responseContent = 
     141            exchange.getResponse() != null ? exchange.getResponse().getContent() : null; 
     142             
     143        SOAPMessage soapResponse = getSOAPMessage(responseContent); 
     144         
     145        if (soapRequest != null) { 
     146            return new SOAPEventType(exchange, soapRequest, soapResponse); 
     147        } 
     148        else { 
     149            return new HTTPEventType(exchange); 
     150        } 
     151    } 
     152 
     153    /** 
     154     * <p> 
     155     * convenience method to convert the content of an HTTP request or response into a SOAP message 
     156     * </p> 
     157     * 
     158     * @param content the content to be converted into a SOAP message 
     159     *  
     160     * @return the SOAP message contained in the content or null if either the content is null or 
     161     *         the content does not contain a SOAP message 
     162     */ 
     163    private SOAPMessage getSOAPMessage(Content content) { 
     164        if ((content != null) && (content.getData() != null)) { 
     165            try { 
     166                if (soapMessageFactory == null) { 
     167                    soapMessageFactory = MessageFactory.newInstance(); 
     168                } 
     169             
     170                String encoding = content.getEncoding(); 
     171                if (encoding == null) { 
     172                    encoding = "UTF-8"; 
     173                } 
     174                 
     175                InputStream in = new ByteArrayInputStream(content.getData().getBytes(encoding)); 
     176                return soapMessageFactory.createMessage(null, in); 
     177            } 
     178            catch (Exception e) { 
     179                if (content.getData().toLowerCase().indexOf("envelope") > 0) { 
     180                    Console.traceln(Level.WARNING, "HTTP message seems to be a SOAP message but " + 
     181                                    "it could not be parsed as such: " + e); 
     182                    Console.logException(e); 
     183                } 
     184            } 
     185        } 
     186         
     187        return null; 
     188    } 
     189 
     190    /** 
     191     * <p> 
    109192     * returns the sequences parsed by this parser 
    110193     * </p> 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/HTTPUtils.java

    r1383 r1417  
    6262        return null; 
    6363    } 
     64 
     65    /** 
     66     * <p> 
     67     * compares two addresses and returns true, if they are equal and false else. The addresses 
     68     * are equal, if either the ip-addresses and the ports match or the host names and the 
     69     * ports match. 
     70     * </p> 
     71     * 
     72     * @param address1 the first address to compare 
     73     * @param address2 the second address to compare 
     74     *  
     75     * @return as described 
     76     */ 
     77    public static boolean equals(Address address1, Address address2) { 
     78        if (address1 == null) { 
     79            return address2 == null; 
     80        } 
     81        else if (address2 == null) { 
     82            return false; 
     83        } 
     84         
     85        if (!equals(address1.getPort(), address2.getPort())) { 
     86            return false; 
     87        } 
     88         
     89        if (address1.getIp() != null) { 
     90            return equals(address1.getIp(), address2.getIp()); 
     91        } 
     92        else { 
     93            return equals(address1.getHost(), address2.getHost()); 
     94        } 
     95    } 
    6496     
     97    /** 
     98     * <p> 
     99     * convenience method to compare to objects. They are considered equal if they both are null, 
     100     * or if their equals method returns true. 
     101     * </p> 
     102     * 
     103     * @param object1 the first object to compare 
     104     * @param object2 the second object to compare 
     105     *  
     106     * @return as described 
     107     */ 
     108    public static <T> boolean equals(T object1, T object2) { 
     109        if (object1 == null)  { 
     110            return object2 == null; 
     111        } 
     112        else { 
     113            return object1.equals(object2); 
     114        } 
     115    } 
     116 
    65117    /** 
    66118     * <p> 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/HTTPEventType.java

    r1383 r1417  
    1717import de.ugoe.cs.autoquest.eventcore.IEventType; 
    1818import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange; 
     19import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpRequest; 
    1920import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 
    2021 
     
    128129    @Override 
    129130    public boolean equals(Object obj) { 
    130         return super.equals(obj); 
     131        if (this == obj) { 
     132            return true; 
     133        } 
     134         
     135        if (obj instanceof HTTPEventType) { 
     136            HTTPEventType other = (HTTPEventType) obj; 
     137             
     138            HttpRequest request1 = exchange.getRequest(); 
     139            HttpRequest request2 = other.exchange.getRequest(); 
     140             
     141            return (HTTPUtils.equals(exchange.getSender(), other.exchange.getSender()) && 
     142                    HTTPUtils.equals(exchange.getReceiver(), other.exchange.getReceiver()) && 
     143                    HTTPUtils.equals(request1.getMethod(), request2.getMethod()) && 
     144                    HTTPUtils.equals(request1.getProtocol(), request2.getProtocol()) && 
     145                    HTTPUtils.equals(request1.getUrl(), request2.getUrl())); 
     146        } 
     147        else { 
     148            return false; 
     149        } 
    131150    } 
    132151 
     
    136155    @Override 
    137156    public int hashCode() { 
    138         return super.hashCode(); 
     157        return 
     158            exchange.getRequest().getMethod().hashCode() + 
     159            exchange.getRequest().getProtocol().hashCode() + 
     160            exchange.getRequest().getUrl().hashCode(); 
    139161    } 
    140162 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/HTTPTarget.java

    r1383 r1417  
    7575 
    7676    /* (non-Javadoc) 
     77     * @see java.lang.Object#toString() 
     78     */ 
     79    @Override 
     80    public String toString() { 
     81        return stringIdentifier; 
     82    } 
     83 
     84    /* (non-Javadoc) 
    7785     * @see java.lang.Object#equals(java.lang.Object) 
    7886     */ 
Note: See TracChangeset for help on using the changeset viewer.