Search in sources :

Example 1 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class ValidateSample method validate.

// START SNIPPET: sax
public void validate(InputStream in, URL schemaUrl) throws Exception {
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8");
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    OMElement bodyContent = envelope.getBody().getFirstElement();
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(schemaUrl);
    Validator validator = schema.newValidator();
    validator.validate(bodyContent.getSAXSource(true));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Validator(javax.xml.validation.Validator)

Example 2 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class CharacterEncoding2Test method testISO99591.

public void testISO99591() throws Exception {
    ByteArrayInputStream byteInStr = new ByteArrayInputStream(xml.getBytes("iso-8859-1"));
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(byteInStr, null);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    envelope.build();
    assertEquals("iso-8859-1", builder.getDocument().getXMLStreamReader().getCharacterEncodingScheme());
    ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding("iso-8859-1");
    envelope.serialize(byteOutStr, outputFormat);
    assertAbout(xml()).that(new InputStreamReader(new ByteArrayInputStream(byteOutStr.toByteArray()), "iso-8859-1")).hasSameContentAs(new InputStreamReader(new ByteArrayInputStream(xml.getBytes("iso-8859-1")), "iso-8859-1"));
    builder.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 3 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class CharacterEncodingTest method runTest.

public void runTest(String value, String expected) throws XMLStreamException, FactoryConfigurationError, IOException {
    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    String ns = "http://testuri.org";
    OMNamespace namespace = factory.createOMNamespace(ns, "tst");
    String ln = "Child";
    OMElement bodyChild = factory.createOMElement(ln, namespace);
    bodyChild.addChild(factory.createOMText(value));
    envelope.getBody().addChild(bodyChild);
    ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();
    OMOutputFormat outputFormat = new OMOutputFormat();
    outputFormat.setCharSetEncoding(UTF_16);
    envelope.serialize(byteOutStr, outputFormat);
    ByteArrayInputStream byteInStr = new ByteArrayInputStream(byteOutStr.toByteArray());
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(byteInStr, UTF_16);
    SOAPEnvelope resultEnv = builder.getSOAPEnvelope();
    OMElement bodyChildResult = resultEnv.getBody().getFirstElement();
    assertNotNull("No child in body element", bodyChildResult);
    String result = bodyChildResult.getText();
    assertNotNull("No value for testParam param", result);
    assertEquals("Expected result not received.", expected, result);
    builder.close();
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 4 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class ConvertLLOMToDOOMTest method testConvert1.

public void testConvert1() {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    fac.createOMElement(new QName("http://test.org", "Test"), env.getBody());
    env.build();
    SOAPModelBuilder doomBuilder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM), env.getXMLStreamReader());
    SOAPEnvelope doomEnv = doomBuilder.getSOAPEnvelope();
    doomEnv.build();
}
Also used : QName(javax.xml.namespace.QName) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 5 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class TestBuilderDetach method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample sample = MTOMSample.SAMPLE1;
    InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
    MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    long countBeforeDetach = in.getCount();
    builder.detach();
    assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
    assertThat(in.isClosed()).isFalse();
    int binaryCount = 0;
    for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
        OMNode node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
                binaryCount++;
            }
        }
    }
    assertThat(binaryCount).isGreaterThan(0);
    in.close();
}
Also used : OMNode(org.apache.axiom.om.OMNode) MultipartBody(org.apache.axiom.mime.MultipartBody) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMText(org.apache.axiom.om.OMText) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)19 OMElement (org.apache.axiom.om.OMElement)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringReader (java.io.StringReader)4 CustomBuilderSupport (org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 BlobOMDataSourceCustomBuilder (org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder)3 SOAPBody (org.apache.axiom.soap.SOAPBody)3 SOAPFactory (org.apache.axiom.soap.SOAPFactory)3 ArrayList (java.util.ArrayList)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 Schema (javax.xml.validation.Schema)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 Validator (javax.xml.validation.Validator)2 Attachments (org.apache.axiom.attachments.Attachments)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 OMText (org.apache.axiom.om.OMText)2