Changeset 1417


Ignore:
Timestamp:
02/28/14 12:23:40 (10 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
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-http-test/.classpath

    r1369 r1417  
    77                </attributes> 
    88        </classpathentry> 
     9        <classpathentry kind="src" path="src/test/resources"/> 
    910        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> 
    1011                <attributes> 
  • trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/HTTPLogParserTest.java

    r1369 r1417  
    2121import java.util.Collection; 
    2222import java.util.Iterator; 
     23import java.util.LinkedList; 
    2324import java.util.List; 
    2425import java.util.logging.Level; 
     
    3940import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType; 
    4041import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPTarget; 
     42import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
    4143import de.ugoe.cs.util.console.TextConsole; 
    4244 
     
    126128        } 
    127129    } 
    128  
     130     
     131    /** 
     132     * Tests the parseFile method with a given trace file. 
     133     * @throws Exception 
     134     */ 
     135    @Test 
     136    public void testParseFile_2() throws Exception { 
     137        HTTPLogParser parser = new HTTPLogParser(); 
     138        parser.parseFile 
     139            (new File(ClassLoader.getSystemResource("httpmonitor_testtrace_1.xml").getFile())); 
     140        Collection<List<Event>> events = parser.getSequences(); 
     141 
     142        assertNotNull(events); 
     143        assertEquals(1, events.size()); 
     144         
     145        Iterator<List<Event>> iterator = events.iterator(); 
     146        assertNotNull(iterator); 
     147        assertEquals(876, iterator.next().size()); 
     148        assertFalse(iterator.hasNext()); 
     149 
     150        List<Event> soapEvents = new LinkedList<Event>(); 
     151        System.out.println("{"); 
     152        for (List<Event> session : events) { 
     153            System.out.println("  {"); 
     154            for (Event event : session) { 
     155                System.out.print("    "); 
     156                System.out.print(event); 
     157                System.out.println(","); 
     158                 
     159                if (event.getType() instanceof SOAPEventType) { 
     160                    assertNotNull(((SOAPEventType) event.getType()).getCalledMethod()); 
     161                    soapEvents.add(event); 
     162                } 
     163            } 
     164            System.out.println("  }"); 
     165        } 
     166        System.out.println("}"); 
     167        System.out.println("\n\n"); 
     168         
     169        assertEquals(870, soapEvents.size()); 
     170    } 
     171     
    129172    /** 
    130173     * 
  • 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.