use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class TestDataHandlerSerializationWithMTOM method runTest.
@Override
protected void runTest() throws Throwable {
SOAPFactory factory = metaFactory.getSOAP11Factory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
// Construct the original message
DocumentBean object = new DocumentBean();
object.setId("123456");
object.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
orgEnvelope.getBody().addChild(element);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
orgEnvelope.serialize(out, format);
out.close();
assertFalse(element.isExpanded());
// Parse the serialized message
MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
assertEquals(2, mb.getPartCount());
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
OMText content = (OMText) contentElement.getFirstOMChild();
assertTrue(content.isBinary());
assertTrue(content.isOptimized());
DataHandler dh = content.getDataHandler();
assertEquals("some content", dh.getContent());
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class TestSerializeAsChild method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.createDefaultSOAPMessage().getSOAPEnvelope();
soapFactory.createOMElement("echo", soapFactory.createOMNamespace("urn:test", "p"), envelope.getBody());
OMElement log = soapFactory.createOMElement("log", null);
OMElement entry = soapFactory.createOMElement("entry", null, log);
entry.addChild(envelope);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
envelope.serialize(out);
out.close();
assertAbout(xml()).that(blob.getInputStream()).hasSameContentAs(xml(OMElement.class, envelope));
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class ElementHelper method toSOAPHeaderBlock.
/**
* This is a method to convert regular OMElements to SOAPHeaderBlocks.
*
* @param omElement
* @param factory
* @return TODO
* @throws Exception
*/
public static SOAPHeaderBlock toSOAPHeaderBlock(OMElement omElement, SOAPFactory factory) throws Exception {
if (omElement instanceof SOAPHeaderBlock)
return (SOAPHeaderBlock) omElement;
QName name = omElement.getQName();
String localName = name.getLocalPart();
OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix());
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
omElement.serialize(out);
out.close();
BlobOMDataSource ds = new BlobOMDataSource(blob, "utf-8");
SOAPHeaderBlock block = factory.createSOAPHeaderBlock(localName, namespace, ds);
return block;
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class AttachmentsTest method testGetRootPartContentID.
private void testGetRootPartContentID(String contentTypeStartParam, String contentId) throws Exception {
MimeMessage message = new MimeMessage((Session) null);
MimeMultipart mp = new MimeMultipart("related");
MimeBodyPart rootPart = new MimeBodyPart();
rootPart.setText("<root/>", "utf-8", "xml");
rootPart.addHeader("Content-Transfer-Encoding", "binary");
rootPart.addHeader("Content-ID", "<" + contentId + ">");
mp.addBodyPart(rootPart);
message.setContent(mp);
message.saveChanges();
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
mp.writeTo(out);
out.close();
Attachments attachments = new Attachments(blob.getInputStream(), new ContentType(message.getContentType()).toBuilder().setParameter("start", contentTypeStartParam).build().toString());
assertEquals("Did not obtain correct content ID", contentId, attachments.getRootPartContentID());
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class TestRegisterCustomBuilderForPayloadJAXBPlain method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(10000));
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
createTestDocument(dh).serialize(out);
out.close();
test(dh, OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), blob.getInputStream()), false);
}
Aggregations