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

Last change on this file since 1924 was 1924, checked in by sherbold, 9 years ago
  • SimpleSOAPEvent now contains body of the SOAP request
  • SOAPUtils created
  • Property svn:mime-type set to text/plain
File size: 5.6 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        if (soapRequestBody == null) {
93            throw new IllegalArgumentException("soapRequestBody must not be null");
94        }
95        this.calledMethod = calledMethod;
96        this.serviceName = serviceName;
97        this.clientName = clientName;
98        this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody);
99    }
100
101    /**
102     * <p>
103     * the SOAP method called in this request
104     * </p>
105     *
106     * @return the SOAP method called in this request
107     */
108    public String getCalledMethod() {
109        return calledMethod;
110    }
111
112    /**
113     * <p>
114     * the name of the service called in this request
115     * </p>
116     *
117     * @return the name of the service called in this request
118     */
119    public String getServiceName() {
120        return serviceName;
121    }
122
123    /**
124     * <p>
125     * the name of the client calling in this request
126     * </p>
127     *
128     * @return the name of the client calling in this request
129     */
130    public String getClientName() {
131        return clientName;
132    }
133
134    public Element getSoapRequestBody() {
135        try {
136            return DocumentBuilderFactory.newInstance().newDocumentBuilder()
137                .parse(new ByteArrayInputStream(soapRequestBody.getBytes())).getDocumentElement();
138        }
139        catch (SAXException | IOException | ParserConfigurationException e) {
140            return null;
141        }
142    }
143
144    /*
145     * (non-Javadoc)
146     *
147     * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName()
148     */
149    @Override
150    public String getName() {
151        return "(" + serviceName + ", " + calledMethod + ")";
152    }
153
154    /*
155     * (non-Javadoc)
156     *
157     * @see de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType#equals(java.lang.Object)
158     */
159    @Override
160    public boolean equals(Object obj) {
161        if (this == obj) {
162            return true;
163        }
164        else if (obj instanceof SimpleSOAPEventType) {
165            return HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) &&
166                HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName) &&
167                HTTPUtils.equals(clientName, ((SimpleSOAPEventType) obj).clientName);
168        }
169        else {
170            return false;
171        }
172    }
173
174    /*
175     * (non-Javadoc)
176     *
177     * @see de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType#hashCode()
178     */
179    @Override
180    public int hashCode() {
181        int hashCode = calledMethod.hashCode() + serviceName.hashCode() + clientName.hashCode();
182        return hashCode;
183    }
184
185    /*
186     * (non-Javadoc)
187     *
188     * @see java.lang.Object#toString()
189     */
190    @Override
191    public String toString() {
192        return "SimpleSOAPEventType(" + serviceName + ", " + calledMethod + ")";
193    }
194}
Note: See TracBrowser for help on using the repository browser.