use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class FirstElementNameWithParserTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
runTest(body);
if (supportsOptimization) {
// The expectation is that even after looking at the payload element name, registering
// a custom builder still transforms the element.
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
element.getXMLStreamReaderWithoutCaching().close();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
return new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
}
@Override
public boolean isDestructiveWrite() {
return false;
}
};
}
});
assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
}
}
Aggregations