use of org.apache.axiom.mime.ContentType 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.mime.ContentType 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.mime.ContentType in project webservices-axiom by apache.
the class Attachments method getAttachmentSpecType.
/**
* Identify the type of message (MTOM or SOAP with attachments) represented by this object. Note
* that this method is only meaningful if the instance was created from a stream.
*
* @return One of the {@link MTOMConstants#MTOM_TYPE}, {@link MTOMConstants#SWA_TYPE} or
* {@link MTOMConstants#SWA_TYPE_12} constants.
* @throws OMException
* if the message doesn't have one of the supported types (i.e. is neither MTOM nor
* SOAP with attachments) or if the instance was not created from a stream
*/
public String getAttachmentSpecType() {
if (this.applicationType == null) {
ContentType contentType = delegate.getContentType();
if (contentType == null) {
throw new OMException("Unable to determine the attachment spec type because the " + "Attachments object doesn't have a known content type");
}
applicationType = contentType.getParameter("type");
if ((MTOMConstants.MTOM_TYPE).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.MTOM_TYPE;
} else if ((MTOMConstants.SWA_TYPE).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.SWA_TYPE;
} else if ((MTOMConstants.SWA_TYPE_12).equalsIgnoreCase(applicationType)) {
this.applicationType = MTOMConstants.SWA_TYPE_12;
} else {
throw new OMException("Invalid Application type. Support available for MTOM & SwA only.");
}
}
return this.applicationType;
}
Aggregations