Search in sources :

Example 1 with SOAPSample

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
    }
}
Also used : ContentType(org.apache.axiom.mime.ContentType) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) DataHandler(javax.activation.DataHandler) SOAPSample(org.apache.axiom.ts.soap.SOAPSample) MimeBodyPart(javax.mail.internet.MimeBodyPart) DataSource(javax.activation.DataSource)

Example 2 with SOAPSample

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();
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) InputStream(java.io.InputStream) SOAPSample(org.apache.axiom.ts.soap.SOAPSample) SOAPMessage(org.apache.axiom.soap.SOAPMessage) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

SOAPSample (org.apache.axiom.ts.soap.SOAPSample)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXSource (javax.xml.transform.sax.SAXSource)1 MemoryBlob (org.apache.axiom.blob.MemoryBlob)1 ContentType (org.apache.axiom.mime.ContentType)1 OMDocument (org.apache.axiom.om.OMDocument)1 SOAPMessage (org.apache.axiom.soap.SOAPMessage)1 SOAPProcessingException (org.apache.axiom.soap.SOAPProcessingException)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1