use of javax.activation.DataHandler in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadJAXBWithXOP method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(10000));
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
createTestDocument(dh).serialize(out, format);
out.close();
MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb), false);
}
use of javax.activation.DataHandler 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.DataHandler 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.DataHandler in project webservices-axiom by apache.
the class TestUnmarshalWithDataHandler method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DocumentBean orgBean = new DocumentBean();
orgBean.setId("AB23498");
orgBean.setContent(new DataHandler("test content", "text/plain"));
OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
DocumentBean bean = (DocumentBean) element.unmarshal(context, null, true);
assertEquals(orgBean.getId(), bean.getId());
assertEquals(orgBean.getContent(), bean.getContent());
}
use of javax.activation.DataHandler 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());
}
Aggregations