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));
}
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();
}
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();
}
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();
}
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();
}
Aggregations