use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.
the class TestBuildWithAttachments method runTest.
@Override
protected void runTest() throws Throwable {
MTOMSample sample = MTOMSample.SAMPLE1;
InputStream in = sample.getInputStream();
MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
envelope.buildWithAttachments();
in.close();
Iterator<OMElement> it = envelope.getBody().getFirstElement().getChildElements();
OMElement image1 = it.next();
OMElement image2 = it.next();
IOTestUtils.compareStreams(((OMText) image1.getFirstOMChild()).getDataHandler().getInputStream(), sample.getPart(1));
IOTestUtils.compareStreams(((OMText) image2.getFirstOMChild()).getDataHandler().getInputStream(), sample.getPart(2));
}
use of org.apache.axiom.ts.soap.MTOMSample 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.ts.soap.MTOMSample in project webservices-axiom by apache.
the class AttachmentsTest method testGetIncomingAttachmentStreams2.
public void testGetIncomingAttachmentStreams2() throws Exception {
MTOMSample sample = MTOMSample.SAMPLE1;
IncomingAttachmentInputStream dataIs;
InputStream expectedDataIs;
InputStream inStream = sample.getInputStream();
Attachments attachments = new Attachments(inStream, sample.getContentType());
// Since SOAP part operated independently of other streams, access it
// directly, and then get to the streams. If this sequence throws an
// error, something is wrong with the stream handling code.
InputStream is = attachments.getRootPartInputStream();
while (is.read() != -1) ;
// Get the inputstream container
IncomingAttachmentStreams ias = attachments.getIncomingAttachmentStreams();
dataIs = ias.getNextStream();
expectedDataIs = sample.getPart(1);
IOTestUtils.compareStreams(dataIs, expectedDataIs);
dataIs = ias.getNextStream();
expectedDataIs = sample.getPart(2);
IOTestUtils.compareStreams(dataIs, expectedDataIs);
// Confirm that no more streams are left
assertNull(ias.getNextStream());
// After all is done, we should *still* be able to access and
// re-consume the SOAP part stream, as it should be cached.. can we?
is = attachments.getRootPartInputStream();
while (is.read() != -1) ;
}
use of org.apache.axiom.ts.soap.MTOMSample in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
MTOMSample testMessage = MTOMSample.SAMPLE1;
// Read in message: SOAPPart and 2 image attachments
InputStream inStream = testMessage.getInputStream();
MultipartBody mb = MultipartBody.builder().setInputStream(inStream).setContentType(testMessage.getContentType()).build();
OMOutputFormat oof = new OMOutputFormat();
oof.setDoOptimize(true);
oof.setMimeBoundary(testMessage.getBoundary());
oof.setRootContentId(testMessage.getStart());
if (base64) {
oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, Boolean.TRUE);
}
// Write out the message
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb);
OMElement om = builder.getDocumentElement();
om.serialize(baos, oof);
om.close(false);
String out = baos.toString();
if (base64) {
// Do a quick check to see if the data is base64 and is
// writing base64 compliant code.
assertTrue(out.indexOf("base64") != -1);
assertTrue(out.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
} else {
assertTrue(out.indexOf("base64") == -1);
}
}
Aggregations