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 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.http.eventcore;
|
---|
16 |
|
---|
17 | import java.io.ByteArrayInputStream;
|
---|
18 | import java.io.IOException;
|
---|
19 |
|
---|
20 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
21 | import javax.xml.parsers.ParserConfigurationException;
|
---|
22 |
|
---|
23 | import org.w3c.dom.Element;
|
---|
24 | import org.xml.sax.SAXException;
|
---|
25 |
|
---|
26 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
27 | import de.ugoe.cs.autoquest.plugin.http.HTTPUtils;
|
---|
28 | import 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 | */
|
---|
38 | public 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 | }
|
---|