source: trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/HTTPEventType.java @ 1417

Last change on this file since 1417 was 1417, checked in by pharms, 10 years ago
  • 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 size: 4.9 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.http.eventcore;
16
17import de.ugoe.cs.autoquest.eventcore.IEventType;
18import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange;
19import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpRequest;
20import de.ugoe.cs.autoquest.plugin.http.HTTPUtils;
21
22/**
23 * <p>
24 * the event type for HTTP events. Holds a reference to the HTTP exchange recorded by the HTTP
25 * monitor.
26 * </p>
27 *
28 * @author Patrick Harms
29 */
30public class HTTPEventType implements IEventType {
31
32    /**  */
33    private static final long serialVersionUID = 1L;
34
35    /**
36     * <p>
37     * the HTTP exchange recorded by the HTTP monitor
38     * </p>
39     */
40    private HttpExchange exchange;
41
42    /**
43     * <p>
44     * the name of the event type as required by AutoQUEST's framework
45     * </p>
46     */
47    private String name;
48
49    /**
50     * <p>
51     * initializes this event with the represented HTTP exchange
52     * </p>
53     *
54     * @param exchange the HTTP exchange recorded by the HTTP monitor
55     */
56    public HTTPEventType(HttpExchange exchange) {
57        if (exchange == null) {
58            throw new IllegalArgumentException("exchange must not be null");
59        }
60       
61        this.exchange = exchange;
62       
63        StringBuffer nameBuffer = new StringBuffer("HTTPEvent");
64       
65        boolean somethingAdded = false;
66       
67        if ((this.exchange.getRequest() != null) &&
68            (this.exchange.getRequest().getMethod() != null))
69        {
70            nameBuffer.append("(");
71            nameBuffer.append(this.exchange.getRequest().getMethod());
72            somethingAdded = true;
73        }
74       
75        String senderStr = HTTPUtils.toString(this.exchange.getSender());
76        String receiverStr = HTTPUtils.toString(this.exchange.getReceiver());
77       
78        if ((senderStr != null) && (receiverStr != null)) {
79            nameBuffer.append(somethingAdded ? ", " : "(");
80            nameBuffer.append(senderStr);
81            nameBuffer.append(" --> ");
82            nameBuffer.append(receiverStr);
83            somethingAdded = true;
84        }
85        else if (senderStr != null) {
86            nameBuffer.append(somethingAdded ? ", " : "(");
87            nameBuffer.append(senderStr);
88            somethingAdded = true;
89        }
90        else if (receiverStr != null) {
91            nameBuffer.append(somethingAdded ? ", " : "(");
92            nameBuffer.append(receiverStr);
93            somethingAdded = true;
94        }
95       
96        if (somethingAdded) {
97            nameBuffer.append(")");
98        }
99       
100        this.name = nameBuffer.toString();
101    }
102
103    /* (non-Javadoc)
104     * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName()
105     */
106    @Override
107    public String getName() {
108        return name;
109    }
110
111    /**
112     * @return the HTTP exchange recorded by the HTTP monitor
113     */
114    public HttpExchange getExchange() {
115        return exchange;
116    }
117
118    /* (non-Javadoc)
119     * @see java.lang.Object#toString()
120     */
121    @Override
122    public String toString() {
123        return name;
124    }
125
126    /* (non-Javadoc)
127     * @see java.lang.Object#equals(java.lang.Object)
128     */
129    @Override
130    public boolean equals(Object 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        }
150    }
151
152    /* (non-Javadoc)
153     * @see java.lang.Object#hashCode()
154     */
155    @Override
156    public int hashCode() {
157        return
158            exchange.getRequest().getMethod().hashCode() +
159            exchange.getRequest().getProtocol().hashCode() +
160            exchange.getRequest().getUrl().hashCode();
161    }
162
163}
Note: See TracBrowser for help on using the repository browser.