use of javax.activation.DataSource in project webservices-axiom by apache.
the class TestBase64StreamingWithGetSAXSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement elem = factory.createOMElement("test", null);
// Create a data source that would eat up all memory when loaded. If the test
// doesn't fail with an OutOfMemoryError, we know that the OMText implementation
// supports streaming.
DataSource ds = new RandomDataSource(654321L, Runtime.getRuntime().maxMemory());
OMText text = factory.createOMText(new DataHandler(ds), false);
elem.addChild(text);
SAXSource saxSource = elem.getSAXSource(true);
XMLReader xmlReader = saxSource.getXMLReader();
xmlReader.setContentHandler(new Base64Comparator(ds.getInputStream()));
xmlReader.parse(saxSource.getInputSource());
}
use of javax.activation.DataSource in project webservices-axiom by apache.
the class TestCreateSOAPModelBuilderMTOMContentTypeMismatch method runTest.
@Override
protected void runTest() throws Throwable {
final SOAPSample sample = SOAPSampleSet.NO_HEADER.getMessage(spec);
// Generate an MTOM message with the wrong content type
MimeMessage message = new MimeMessage((Session) null);
MimeMultipart mp = new MimeMultipart("related");
MimeBodyPart bp = new MimeBodyPart();
String contentID = "<" + UIDGenerator.generateContentId() + ">";
bp.setDataHandler(new DataHandler(new DataSource() {
@Override
public String getContentType() {
return "application/xop+xml; charset=\"" + sample.getEncoding() + "\"; type=\"" + spec.getAltSpec().getContentType() + "\"";
}
@Override
public InputStream getInputStream() throws IOException {
return sample.getInputStream();
}
@Override
public String getName() {
return null;
}
@Override
public OutputStream getOutputStream() {
throw new UnsupportedOperationException();
}
}));
bp.addHeader("Content-Transfer-Encoding", "binary");
bp.addHeader("Content-ID", contentID);
mp.addBodyPart(bp);
message.setContent(mp);
message.saveChanges();
ContentType contentType = new ContentType(message.getContentType()).toBuilder().setParameter("type", "application/xop+xml").setParameter("start", contentID).setParameter("start-info", spec.getAltSpec().getContentType()).build();
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
mp.writeTo(out);
out.close();
// Now attempt to create an Axiom builder
try {
OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(contentType).build());
fail("Expected SOAPProcessingException");
} catch (SOAPProcessingException ex) {
// Expected
}
}
use of javax.activation.DataSource in project webservices-axiom by apache.
the class TestGetDataHandlerFromElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
RandomDataSource orgDS = new RandomDataSource(64 * 1024);
OMElement orgRoot = factory.createOMElement(new QName("root"));
OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
XMLStreamReader reader = root.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
use of javax.activation.DataSource in project webservices-axiom by apache.
the class PartOnFileTest method testHeaderGetSet.
public void testHeaderGetSet() throws Exception {
InputStream inStream = MTOMSample.SAMPLE1.getInputStream();
Attachments attachments = new Attachments(inStream, MTOMSample.SAMPLE1.getContentType(), true, temp.getPath(), "1");
DataHandler dh = attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
assertNotNull(dh);
DataSource ds = dh.getDataSource();
assertNotNull(ds);
// The attachment cleanup code in Axis2 relies on the assumption that attachments written
// to disk produce CachedFileDataSource instances.
assertThat(ds).isInstanceOf(CachedFileDataSource.class);
assertEquals("image/jpeg", dh.getContentType());
}
use of javax.activation.DataSource in project webservices-axiom by apache.
the class TestGetObject method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new BlobDataSource(Blobs.createBlob("test".getBytes("utf-8")), "text/plain; charset=utf-8");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), ds, Charset.forName("utf-8")));
// getObject returns null if the data source is not of the expected type
assertNull(element.getObject(StringOMDataSource.class));
// Test with the right data source type
assertSame(ds, element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
assertSame(ds, element.getObject(WrappedTextNodeOMDataSource.class));
// Now modify the content of the element
factory.createOMComment(element, "comment");
assertNull(element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
}
Aggregations