[1635] | 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 |
|
---|
[1924] | 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 |
|
---|
[1635] | 26 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
| 27 | import de.ugoe.cs.autoquest.plugin.http.HTTPUtils;
|
---|
[1924] | 28 | import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
|
---|
[1635] | 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;
|
---|
[1924] | 56 |
|
---|
[1913] | 57 | /**
|
---|
| 58 | * <p>
|
---|
[1924] | 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
|
---|
[1913] | 61 | * </p>
|
---|
| 62 | */
|
---|
| 63 | private final String clientName;
|
---|
[1635] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * <p>
|
---|
[1924] | 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>
|
---|
[1635] | 74 | * Constructor. Creates a new SimpleSOAPEventType.
|
---|
| 75 | * </p>
|
---|
| 76 | *
|
---|
| 77 | */
|
---|
[1924] | 78 | public SimpleSOAPEventType(String calledMethod,
|
---|
| 79 | String serviceName,
|
---|
| 80 | String clientName,
|
---|
| 81 | Element soapRequestBody)
|
---|
| 82 | {
|
---|
[1635] | 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 | }
|
---|
[1913] | 89 | if (clientName == null) {
|
---|
| 90 | throw new IllegalArgumentException("clientName must not be null");
|
---|
| 91 | }
|
---|
[1924] | 92 | if (soapRequestBody == null) {
|
---|
| 93 | throw new IllegalArgumentException("soapRequestBody must not be null");
|
---|
| 94 | }
|
---|
[1635] | 95 | this.calledMethod = calledMethod;
|
---|
| 96 | this.serviceName = serviceName;
|
---|
[1913] | 97 | this.clientName = clientName;
|
---|
[1924] | 98 | this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody);
|
---|
[1635] | 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 | }
|
---|
[1924] | 122 |
|
---|
[1913] | 123 | /**
|
---|
| 124 | * <p>
|
---|
| 125 | * the name of the client calling in this request
|
---|
| 126 | * </p>
|
---|
[1924] | 127 | *
|
---|
[1913] | 128 | * @return the name of the client calling in this request
|
---|
| 129 | */
|
---|
| 130 | public String getClientName() {
|
---|
| 131 | return clientName;
|
---|
| 132 | }
|
---|
[1635] | 133 |
|
---|
[1924] | 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 |
|
---|
[1635] | 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) {
|
---|
[1642] | 165 | return HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) &&
|
---|
[1924] | 166 | HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName) &&
|
---|
| 167 | HTTPUtils.equals(clientName, ((SimpleSOAPEventType) obj).clientName);
|
---|
[1635] | 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() {
|
---|
[1924] | 181 | int hashCode = calledMethod.hashCode() + serviceName.hashCode() + clientName.hashCode();
|
---|
[1635] | 182 | return hashCode;
|
---|
| 183 | }
|
---|
[1924] | 184 |
|
---|
| 185 | /*
|
---|
| 186 | * (non-Javadoc)
|
---|
| 187 | *
|
---|
[1642] | 188 | * @see java.lang.Object#toString()
|
---|
| 189 | */
|
---|
| 190 | @Override
|
---|
| 191 | public String toString() {
|
---|
| 192 | return "SimpleSOAPEventType(" + serviceName + ", " + calledMethod + ")";
|
---|
| 193 | }
|
---|
[1635] | 194 | }
|
---|