in testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderMTOMContentTypeMismatch.java [57:119]
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
}
}