PayloadNameRequestWrapper extends HttpServletRequestWrapper { static boolean scanForChildTag(XMLStreamReader reader, String tagName) throws XMLStreamException { assert reader.isStartElement(); int level = -1; while (reader.hasNext()) { if (reader.isStartElement()) { level++; } else if (reader.isEndElement()) { level--; } if (level < 0) { break; } reader.next(); if (level == 0 && reader.isStartElement() && reader.getLocalName().equals(tagName)) { return true; } } return false; } PayloadNameRequestWrapper(HttpServletRequest request); @Override BufferedReader getReader(); @Override ServletInputStream getInputStream(); String getPayloadRequestName(); String getPayloadRequestType();  }
@Test public void testScanForChildTag() throws XMLStreamException { assertTrue("Could not find child tag", scanForChildTag("child", "<parent><child/></parent>")); assertFalse("Found wrong tag", scanForChildTag("notChild", "<parent><child/></parent>")); assertFalse("Found descendant tag", scanForChildTag("descendant", "<parent><child><descendant/></child></parent>")); }