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
File:
1 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> 
Note: See TracChangeset for help on using the changeset viewer.