use of org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport in project webservices-axiom by apache.
the class TestRegisterCustomBuilder method runTest.
@Override
protected void runTest() throws Throwable {
SOAPModelBuilder builder = SOAPSampleSet.WSA.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
((CustomBuilderSupport) builder).registerCustomBuilder(new CustomBuilder.Selector() {
@Override
public boolean accepts(OMContainer parent, int depth, String namespaceURI, String localName) {
return depth == 3 && namespaceURI.equals("http://www.w3.org/2005/08/addressing") && localName.equals("To");
}
}, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
SOAPHeader header = builder.getSOAPEnvelope().getHeader();
ArrayList al = header.getHeaderBlocksWithNSURI("http://www.w3.org/2005/08/addressing");
assertEquals(al.size(), 4);
for (int i = 0; i < al.size(); i++) {
SOAPHeaderBlock shb = (SOAPHeaderBlock) al.get(i);
if ("To".equals(shb.getLocalName())) {
assertNotNull(shb.getDataSource());
}
}
}
use of org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayload method runTest.
@Override
protected void runTest() throws Throwable {
SOAPModelBuilder builder = message.getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
SOAPEnvelope envelope = builder.getSOAPEnvelope();
OMElement payload = envelope.getBody().getFirstElement();
if (message.getPayload() == null) {
assertThat(payload).isNull();
} else if (message.getPayload().getLocalName().equals("Fault")) {
assertThat(payload).isInstanceOf(SOAPFault.class);
} else {
assertThat(payload).isInstanceOf(OMSourcedElement.class);
BlobOMDataSource.Data data = (BlobOMDataSource.Data) ((OMSourcedElement) payload).getObject(BlobOMDataSource.class);
assertThat(data).isNotNull();
InputSource is = new InputSource(data.getBlob().getInputStream());
is.setEncoding(data.getEncoding());
assertAbout(xml()).that(is).ignoringNamespaceDeclarations().hasSameContentAs(message.getPayloadInputSource());
}
// We need to ignore redundant namespace declarations because the custom builder needs
// to preserve the namespace context when serializing to the blob.
assertAbout(xml()).that(envelope.getXMLStreamReader(false)).ignoringPrologAndEpilog().ignoringRedundantNamespaceDeclarations().hasSameContentAs(message.getInputStream());
if (payload instanceof OMSourcedElement) {
assertThat(((OMSourcedElement) payload).isExpanded()).isFalse();
}
}
use of org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadAfterSOAPFaultCheck method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
SOAPModelBuilder builder = (SOAPModelBuilder) envelope.getBuilder();
// Do a fault check. This is normally done in the engine (Axiom) and should
// not cause inteference with the custom builder processing
envelope.getBody().hasFault();
// Do the registration here...this simulates when it could occure in the engine
// (After the fault check and during phase processing...probably dispatch phase)
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
OMElement bodyElement = envelope.getBody().getFirstElement();
assertTrue(bodyElement instanceof OMSourcedElement);
}
use of org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport 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