use of org.apache.axiom.ts.soap.SOAPSample 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.ts.soap.SOAPSample in project webservices-axiom by apache.
the class TestCreateSOAPModelBuilderFromSAXSource method runTest.
@Override
protected void runTest() throws Throwable {
SAXParserFactory parserFactory = SAXImplementation.XERCES.newSAXParserFactory();
parserFactory.setNamespaceAware(true);
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
SOAPSample sample = SOAPSampleSet.SIMPLE_FAULT.getMessage(spec);
InputStream in = sample.getInputStream();
InputSource is = new InputSource(in);
is.setEncoding(sample.getEncoding());
SOAPMessage message = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new SAXSource(reader, is)).getSOAPMessage();
assertAbout(xml()).that(xml(OMDocument.class, message)).ignoringWhitespaceInPrologAndEpilog().hasSameContentAs(sample.getEnvelope());
assertThat(message.getSOAPEnvelope().getBody().getFault()).isNotNull();
}
Aggregations