Changeset 1417 for trunk/autoquest-plugin-http
- Timestamp:
- 02/28/14 12:23:40 (11 years ago)
- 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 15 15 package de.ugoe.cs.autoquest.plugin.http; 16 16 17 import java.io.ByteArrayInputStream; 17 18 import java.io.File; 19 import java.io.InputStream; 18 20 import java.util.Collection; 19 21 import java.util.LinkedList; 20 22 import java.util.List; 23 import java.util.logging.Level; 21 24 22 25 import javax.xml.bind.JAXBContext; … … 24 27 import javax.xml.bind.JAXBException; 25 28 import javax.xml.bind.Unmarshaller; 29 import javax.xml.soap.MessageFactory; 30 import javax.xml.soap.SOAPMessage; 26 31 import javax.xml.transform.stream.StreamSource; 27 32 … … 29 34 30 35 import de.ugoe.cs.autoquest.eventcore.Event; 36 import de.ugoe.cs.autoquest.eventcore.IEventType; 37 import de.ugoe.cs.autoquest.httpmonitor.exchange.Content; 31 38 import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange; 32 39 import de.ugoe.cs.autoquest.httpmonitor.exchange.Session; 33 40 import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType; 34 41 import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPTarget; 42 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 43 import de.ugoe.cs.util.console.Console; 35 44 36 45 /** 37 46 * <p> 38 47 * 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. 40 50 * </p> 41 51 * … … 50 60 */ 51 61 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; 52 69 53 70 /** … … 97 114 List<Event> sequence = new LinkedList<Event>(); 98 115 for (HttpExchange exchange : session.getHttpExchange()) { 99 sequence.add(new Event( new HTTPEventType(exchange),116 sequence.add(new Event(createEvent(exchange), 100 117 new HTTPTarget(exchange.getReceiver()))); 101 118 } … … 107 124 /** 108 125 * <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> 109 192 * returns the sequences parsed by this parser 110 193 * </p> -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/HTTPUtils.java
r1383 r1417 62 62 return null; 63 63 } 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 } 64 96 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 65 117 /** 66 118 * <p> -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/HTTPEventType.java
r1383 r1417 17 17 import de.ugoe.cs.autoquest.eventcore.IEventType; 18 18 import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange; 19 import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpRequest; 19 20 import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 20 21 … … 128 129 @Override 129 130 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 } 131 150 } 132 151 … … 136 155 @Override 137 156 public int hashCode() { 138 return super.hashCode(); 157 return 158 exchange.getRequest().getMethod().hashCode() + 159 exchange.getRequest().getProtocol().hashCode() + 160 exchange.getRequest().getUrl().hashCode(); 139 161 } 140 162 -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/HTTPTarget.java
r1383 r1417 75 75 76 76 /* (non-Javadoc) 77 * @see java.lang.Object#toString() 78 */ 79 @Override 80 public String toString() { 81 return stringIdentifier; 82 } 83 84 /* (non-Javadoc) 77 85 * @see java.lang.Object#equals(java.lang.Object) 78 86 */
Note: See TracChangeset
for help on using the changeset viewer.