use of org.apache.axiom.soap.SOAPModelBuilder 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.soap.SOAPModelBuilder 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.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class TestBuilderDetach method runTest.
@Override
protected void runTest() throws Throwable {
MTOMSample sample = MTOMSample.SAMPLE1;
InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
SOAPEnvelope envelope = builder.getSOAPEnvelope();
long countBeforeDetach = in.getCount();
builder.detach();
assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
assertThat(in.isClosed()).isFalse();
int binaryCount = 0;
for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
OMNode node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
binaryCount++;
}
}
}
assertThat(binaryCount).isGreaterThan(0);
in.close();
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class AttachmentsTest method testSWAWriteWithIncomingOrder.
public void testSWAWriteWithIncomingOrder() throws Exception {
// Read the stream that has soap xml followed by BAttachment then AAttachment
InputStream inStream = SwASample.SAMPLE1.getInputStream();
Attachments attachments = new Attachments(inStream, SwASample.SAMPLE1.getContentType());
// Get the contentIDs to force the reading
attachments.getAllContentIDs();
// Get the root
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments.getRootPartInputStream(), "UTF-8");
OMElement root = builder.getDocumentElement();
StringWriter xmlWriter = new StringWriter();
root.serialize(xmlWriter);
// Serialize the message using the legacy behavior (order by content id)
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding("utf-8");
format.setDoingSWA(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MIMEOutputUtils.writeSOAPWithAttachmentsMessage(xmlWriter, baos, attachments, format);
String text = baos.toString();
// Assert that AAttachment occurs before BAttachment since
// that is the natural ordering of the content ids.
assertTrue(text.indexOf("BAttachment") < text.indexOf("AAttachment"));
}
use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.
the class TestDTD method runTest.
@Override
protected void runTest() throws Throwable {
String message = "<!DOCTYPE test []>" + soapFactory.getDefaultEnvelope();
XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(message));
;
try {
SOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(metaFactory, parser);
// The processing must fail before we can get the SOAPEnvelope
builder.getSOAPEnvelope();
fail("Expected SOAPProcessingException");
} catch (SOAPProcessingException ex) {
// Expected
}
}
Aggregations