use of org.apache.axiom.om.ds.AbstractPushOMDataSource in project webservices-axiom by apache.
the class TestGetSAXSourceWithPushOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement sourcedElement = factory.createOMElement(new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
scenario.serialize(writer);
}
@Override
public boolean isDestructiveWrite() {
return false;
}
});
Iterator<Map.Entry<String, String>> it = scenario.getNamespaceContext().entrySet().iterator();
OMElement parent;
if (it.hasNext()) {
Map.Entry<String, String> binding = it.next();
parent = factory.createOMElement("parent", factory.createOMNamespace(binding.getValue(), binding.getKey()));
while (it.hasNext()) {
binding = it.next();
parent.declareNamespace(factory.createOMNamespace(binding.getValue(), binding.getKey()));
}
} else {
parent = factory.createOMElement("parent", null);
}
parent.addChild(sourcedElement);
SAXSource saxSource = (serializeParent ? parent : sourcedElement).getSAXSource(true);
OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, saxSource, false).getDocumentElement();
if (serializeParent) {
element = element.getFirstElement();
}
scenario.validate(element, false);
}
use of org.apache.axiom.om.ds.AbstractPushOMDataSource 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);
}
}
use of org.apache.axiom.om.ds.AbstractPushOMDataSource in project webservices-axiom by apache.
the class TestGetSAXSourceWithPushOMDataSourceThrowingException method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = metaFactory.getOMFactory().createOMElement(new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
throw new XMLStreamException("TEST");
}
@Override
public boolean isDestructiveWrite() {
return false;
}
});
SAXSource saxSource = element.getSAXSource(true);
XMLReader reader = saxSource.getXMLReader();
reader.setContentHandler(SAX.createNullContentHandler());
try {
reader.parse(saxSource.getInputSource());
fail("Expected SAXException");
} catch (SAXException ex) {
Throwable cause = ex.getCause();
assertThat(cause).isInstanceOf(XMLStreamException.class);
assertThat(cause.getMessage()).isEqualTo("TEST");
}
}
Aggregations