use of org.apache.axiom.blob.MemoryBlob 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 org.apache.axiom.blob.MemoryBlob 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 org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class DetachableInputStream method detach.
@Override
public void detach() throws OMException {
MemoryBlob blob = Blobs.createMemoryBlob();
try {
blob.readFrom(target);
} catch (StreamCopyException ex) {
throw new OMException(ex.getCause());
}
if (closeOnDetach) {
try {
target.close();
} catch (IOException ex) {
throw new OMException(ex);
}
}
target = blob.readOnce();
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class DetachableReader method detach.
@Override
public void detach() {
MemoryBlob blob = Blobs.createMemoryBlob();
Writer out = new OutputStreamWriter(blob.getOutputStream(), UTF8);
char[] buffer = new char[2048];
int c;
try {
while ((c = target.read(buffer)) != -1) {
out.write(buffer, 0, c);
}
out.close();
} catch (IOException ex) {
throw new OMException(ex);
}
target = new InputStreamReader(blob.readOnce(), UTF8);
}
use of org.apache.axiom.blob.MemoryBlob in project webservices-axiom by apache.
the class AttachmentsTest method testFakeRootPartContentID.
/**
* Tests access to a root part that doesn't have a content ID. In this case, the
* {@link Attachments} API generates a fake content ID.
*
* @throws Exception
*/
public void testFakeRootPartContentID() throws Exception {
MimeMessage message = new MimeMessage((Session) null);
MimeMultipart mp = new MimeMultipart("related");
MimeBodyPart bp1 = new MimeBodyPart();
bp1.setText("<root/>", "utf-8", "xml");
bp1.addHeader("Content-Transfer-Encoding", "binary");
mp.addBodyPart(bp1);
MimeBodyPart bp2 = new MimeBodyPart();
bp2.setDataHandler(new DataHandler("Test", "text/plain"));
bp2.addHeader("Content-Transfer-Encoding", "binary");
mp.addBodyPart(bp2);
message.setContent(mp);
message.saveChanges();
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
mp.writeTo(out);
out.close();
String contentType = message.getContentType();
Attachments attachments = new Attachments(blob.getInputStream(), contentType);
String rootPartContentID = attachments.getRootPartContentID();
assertThat(rootPartContentID).isNotNull();
DataHandler rootPart = attachments.getDataHandler(rootPartContentID);
assertThat(rootPart.getContent()).isEqualTo("<root/>");
}
Aggregations