@Test public void testExtract_multipleFields() { Map<String, String> ret = xmlFieldExtractor.extract( new ByteArrayInputStream(REPORT_DOWNLOAD_ERROR.getBytes(UTF_8)), new String[] {"type", "trigger", "fieldPath"}); assertEquals("ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT", ret.get("type")); assertEquals("AdFormatt", ret.get("trigger")); assertEquals("foobar", ret.get("fieldPath")); }
public Map<String, String> extract(InputStream xml, String[] fields) { Map<String, String> parsedFields = Maps.newHashMap(); try { DocumentBuilder documentBuilder = documentBuilderSupplier.get(); if (documentBuilder == null) { logger.warn("Could not create DocumentBuilder"); return parsedFields; } Document doc = documentBuilder.parse(xml); for (String field : fields) { try { String value = extract(doc, field); if (value != null) { parsedFields.put(field, value); } } catch (XPathExpressionException e) { logger.warn("Invalid XPath: " + field, e); } } } catch (SAXException e) { logger.warn("Couldn't process XML into a Document", e); } catch (IOException e) { logger.warn("Problem reading input stream", e); } return parsedFields; }
XmlFieldExtractor { public Map<String, String> extract(InputStream xml, String[] fields) { Map<String, String> parsedFields = Maps.newHashMap(); try { DocumentBuilder documentBuilder = documentBuilderSupplier.get(); if (documentBuilder == null) { logger.warn("Could not create DocumentBuilder"); return parsedFields; } Document doc = documentBuilder.parse(xml); for (String field : fields) { try { String value = extract(doc, field); if (value != null) { parsedFields.put(field, value); } } catch (XPathExpressionException e) { logger.warn("Invalid XPath: " + field, e); } } } catch (SAXException e) { logger.warn("Couldn't process XML into a Document", e); } catch (IOException e) { logger.warn("Problem reading input stream", e); } return parsedFields; } }
XmlFieldExtractor { public Map<String, String> extract(InputStream xml, String[] fields) { Map<String, String> parsedFields = Maps.newHashMap(); try { DocumentBuilder documentBuilder = documentBuilderSupplier.get(); if (documentBuilder == null) { logger.warn("Could not create DocumentBuilder"); return parsedFields; } Document doc = documentBuilder.parse(xml); for (String field : fields) { try { String value = extract(doc, field); if (value != null) { parsedFields.put(field, value); } } catch (XPathExpressionException e) { logger.warn("Invalid XPath: " + field, e); } } } catch (SAXException e) { logger.warn("Couldn't process XML into a Document", e); } catch (IOException e) { logger.warn("Problem reading input stream", e); } return parsedFields; } @Inject  XmlFieldExtractor(
      @Named("soapXmlLogger") Logger soapXmlLogger,
      Supplier<DocumentBuilder> documentBuilderSupplier,
      Supplier<XPath> xpathSupplier); }
XmlFieldExtractor { public Map<String, String> extract(InputStream xml, String[] fields) { Map<String, String> parsedFields = Maps.newHashMap(); try { DocumentBuilder documentBuilder = documentBuilderSupplier.get(); if (documentBuilder == null) { logger.warn("Could not create DocumentBuilder"); return parsedFields; } Document doc = documentBuilder.parse(xml); for (String field : fields) { try { String value = extract(doc, field); if (value != null) { parsedFields.put(field, value); } } catch (XPathExpressionException e) { logger.warn("Invalid XPath: " + field, e); } } } catch (SAXException e) { logger.warn("Couldn't process XML into a Document", e); } catch (IOException e) { logger.warn("Problem reading input stream", e); } return parsedFields; } @Inject  XmlFieldExtractor(
      @Named("soapXmlLogger") Logger soapXmlLogger,
      Supplier<DocumentBuilder> documentBuilderSupplier,
      Supplier<XPath> xpathSupplier); Map<String, String> extract(InputStream xml, String[] fields); }
XmlFieldExtractor { public Map<String, String> extract(InputStream xml, String[] fields) { Map<String, String> parsedFields = Maps.newHashMap(); try { DocumentBuilder documentBuilder = documentBuilderSupplier.get(); if (documentBuilder == null) { logger.warn("Could not create DocumentBuilder"); return parsedFields; } Document doc = documentBuilder.parse(xml); for (String field : fields) { try { String value = extract(doc, field); if (value != null) { parsedFields.put(field, value); } } catch (XPathExpressionException e) { logger.warn("Invalid XPath: " + field, e); } } } catch (SAXException e) { logger.warn("Couldn't process XML into a Document", e); } catch (IOException e) { logger.warn("Problem reading input stream", e); } return parsedFields; } @Inject  XmlFieldExtractor(
      @Named("soapXmlLogger") Logger soapXmlLogger,
      Supplier<DocumentBuilder> documentBuilderSupplier,
      Supplier<XPath> xpathSupplier); Map<String, String> extract(InputStream xml, String[] fields);  }