- Timestamp:
- 03/20/15 16:00:10 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java
r1928 r1929 16 16 17 17 import java.io.StringWriter; 18 import java.util.ArrayList; 18 19 import java.util.Iterator; 19 20 import java.util.LinkedList; … … 27 28 import javax.xml.transform.stream.StreamResult; 28 29 30 import org.w3c.dom.Attr; 29 31 import org.w3c.dom.Element; 30 32 import org.w3c.dom.Node; 33 import org.w3c.dom.NodeList; 31 34 32 35 import de.ugoe.cs.autoquest.eventcore.Event; … … 43 46 */ 44 47 public class SOAPUtils { 45 48 46 49 /** 47 50 * <p> … … 69 72 eventType.getServiceName(), 70 73 eventType.getClientName(), 71 eventType.getSoapRequestBody()))); 74 eventType 75 .getSoapRequestBody()))); 72 76 } 73 77 else { … … 80 84 return newSequence; 81 85 } 82 86 83 87 /** 84 88 * <p> … … 89 93 * sequence where the events are replaced 90 94 */ 91 public static void removeNonSOAPEvents(List<Event> sequence) 92 { 95 public static void removeNonSOAPEvents(List<Event> sequence) { 93 96 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 94 97 Event event = eventIter.next(); … … 188 191 return requestBody; 189 192 } 190 191 /** 192 * <p> 193 * returns the XML serialization of a DOM node; located here because it is used for SOAP request bodies 193 194 /** 195 * <p> 196 * returns the XML serialization of a DOM node; located here because it is used for SOAP request 197 * bodies 194 198 * </p> 195 199 * … … 199 203 */ 200 204 public static String getSerialization(Node node) { 201 if ( node==null) {205 if (node == null) { 202 206 return null; 203 207 } … … 214 218 } 215 219 } 216 220 221 /** 222 * <p> 223 * Fetches all {@link Element}s that are direct children of the parent node, whose name matches 224 * the given name. 225 * </p> 226 * 227 * @param typeNameRaw 228 * name of elements that are looked for 229 * @param parentNode 230 * DOM node in which the elements are searched for 231 * @return found {@link Element}s 232 */ 233 public static List<Element> getMatchingChildNode(String typeNameRaw, Element parentNode) { 234 List<Element> matchingNodes = new ArrayList<>(); 235 Node parameterNode = null; 236 if (parentNode != null) { 237 NodeList parameterNodes = parentNode.getChildNodes(); 238 String[] typeNameSplit = typeNameRaw.split(":"); 239 String typeName = typeNameSplit[typeNameSplit.length - 1]; 240 for (int i = 0; i < parameterNodes.getLength(); i++) { 241 parameterNode = parameterNodes.item(i); 242 if (parameterNode.getNodeType() == Node.ELEMENT_NODE) { 243 String[] parameterNodeSplit = parameterNode.getNodeName().split(":"); 244 String parameterNodeName = parameterNodeSplit[parameterNodeSplit.length - 1]; 245 if (typeName.equals(parameterNodeName)) { 246 matchingNodes.add((Element) parameterNode); 247 } 248 } 249 } 250 } 251 return matchingNodes; 252 } 253 254 /** 255 * <p> 256 * Returns the values found in a currentNode for a defined valueName. To this aim, this methods 257 * first determines if there is an attribute with the name "valueName". If this is the case, the 258 * value of this attribute is returned. Otherwise, the methods looks for {@link Element}s that 259 * are direct children of the provided DOM node with the given name and returns the text content 260 * of those nodes. 261 * </p> 262 * <p> 263 * In case no values can be found, an empty list is returned 264 * 265 * @param valueName 266 * name of the value that is retrieved 267 * @param node 268 * node for which the value is retrieved 269 * @return list of the found values. 270 */ 271 public static List<String> getValuesFromElement(String valueName, Element node) { 272 List<String> attributeValues = new LinkedList<>(); 273 274 if (node != null) { 275 // first check attributes of the node 276 Attr attribute = node.getAttributeNode(valueName); 277 if (attribute != null) { 278 attributeValues.add(attribute.getValue()); 279 } 280 else { 281 // now check elements 282 List<Element> elements = getMatchingChildNode(valueName, node); 283 for (Element element : elements) { 284 attributeValues.add(element.getTextContent()); 285 } 286 } 287 } 288 289 return attributeValues; 290 } 291 217 292 /** 218 293 * <p>
Note: See TracChangeset
for help on using the changeset viewer.