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

Last change on this file since 1928 was 1928, checked in by sherbold, 9 years ago
  • body of SOAP request can now be null in SimpleSOAPEventType
  • Property svn:mime-type set to text/plain
File size: 5.5 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 java.io.ByteArrayInputStream;
18import java.io.IOException;
19
20import javax.xml.parsers.DocumentBuilderFactory;
21import javax.xml.parsers.ParserConfigurationException;
22
23import org.w3c.dom.Element;
24import org.xml.sax.SAXException;
25
26import de.ugoe.cs.autoquest.eventcore.IEventType;
27import de.ugoe.cs.autoquest.plugin.http.HTTPUtils;
28import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
29
30/**
31 * <p>
32 * A simplified SOAP event type that only contains the name of the called method and the name of the
33 * service.
34 * </p>
35 *
36 * @author Steffen Herbold
37 */
38public class SimpleSOAPEventType implements IEventType {
39
40    /**  */
41    private static final long serialVersionUID = 1L;
42
43    /**
44     * <p>
45     * the SOAP method called in this request
46     * </p>
47     */
48    private final String calledMethod;
49
50    /**
51     * <p>
52     * the name of the service; this is either the path or, if a path map is available
53     * </p>
54     */
55    private final String serviceName;
56
57    /**
58     * <p>
59     * the name of the client; this is either the host/ip and port of the sender or, if a path map
60     * is available, a human readable name that may be based also on the receiver
61     * </p>
62     */
63    private final String clientName;
64
65    /**
66     * <p>
67     * the body of the SOAP request; storage as serialized XML string to allow object serialization
68     * </p>
69     */
70    private final String soapRequestBody;
71
72    /**
73     * <p>
74     * Constructor. Creates a new SimpleSOAPEventType.
75     * </p>
76     *
77     */
78    public SimpleSOAPEventType(String calledMethod,
79                               String serviceName,
80                               String clientName,
81                               Element soapRequestBody)
82    {
83        if (calledMethod == null) {
84            throw new IllegalArgumentException("called method must not be null");
85        }
86        if (serviceName == null) {
87            throw new IllegalArgumentException("serviceName must not be null");
88        }
89        if (clientName == null) {
90            throw new IllegalArgumentException("clientName must not be null");
91        }
92        this.calledMethod = calledMethod;
93        this.serviceName = serviceName;
94        this.clientName = clientName;
95        this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody);
96    }
97
98    /**
99     * <p>
100     * the SOAP method called in this request
101     * </p>
102     *
103     * @return the SOAP method called in this request
104     */
105    public String getCalledMethod() {
106        return calledMethod;
107    }
108
109    /**
110     * <p>
111     * the name of the service called in this request
112     * </p>
113     *
114     * @return the name of the service called in this request
115     */
116    public String getServiceName() {
117        return serviceName;
118    }
119
120    /**
121     * <p>
122     * the name of the client calling in this request
123     * </p>
124     *
125     * @return the name of the client calling in this request
126     */
127    public String getClientName() {
128        return clientName;
129    }
130
131    public Element getSoapRequestBody() {
132        try {
133            return DocumentBuilderFactory.newInstance().newDocumentBuilder()
134                .parse(new ByteArrayInputStream(soapRequestBody.getBytes())).getDocumentElement();
135        }
136        catch (SAXException | IOException | ParserConfigurationException e) {
137            return null;
138        }
139    }
140
141    /*
142     * (non-Javadoc)
143     *
144     * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName()
145     */
146    @Override
147    public String getName() {
148        return "(" + serviceName + ", " + calledMethod + ")";
149    }
150
151    /*
152     * (non-Javadoc)
153     *
154     * @see de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType#equals(java.lang.Object)
155     */
156    @Override
157    public boolean equals(Object obj) {
158        if (this == obj) {
159            return true;
160        }
161        else if (obj instanceof SimpleSOAPEventType) {
162            return HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) &&
163                HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName) &&
164                HTTPUtils.equals(clientName, ((SimpleSOAPEventType) obj).clientName);
165        }
166        else {
167            return false;
168        }
169    }
170
171    /*
172     * (non-Javadoc)
173     *
174     * @see de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType#hashCode()
175     */
176    @Override
177    public int hashCode() {
178        int hashCode = calledMethod.hashCode() + serviceName.hashCode() + clientName.hashCode();
179        return hashCode;
180    }
181
182    /*
183     * (non-Javadoc)
184     *
185     * @see java.lang.Object#toString()
186     */
187    @Override
188    public String toString() {
189        return "SimpleSOAPEventType(" + serviceName + ", " + calledMethod + ")";
190    }
191}
Note: See TracBrowser for help on using the repository browser.