use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class MTOMSample method retrieveContent.
// START SNIPPET: retrieveContent
public void retrieveContent(URL serviceURL, String id, OutputStream result) throws Exception {
// Build the SOAP request
SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope request = soapFactory.getDefaultEnvelope();
OMElement retrieveContent = soapFactory.createOMElement(new QName("urn:test", "retrieveContent"), request.getBody());
OMElement fileId = soapFactory.createOMElement(new QName("fileId"), retrieveContent);
fileId.setText(id);
// Use the java.net.URL API to connect to the service
URLConnection connection = serviceURL.openConnection();
connection.setDoOutput(true);
connection.addRequestProperty("Content-Type", "text/xml; charset=UTF-8");
OutputStream out = connection.getOutputStream();
// Send the request
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding("UTF-8");
request.serialize(out, format);
out.close();
// Get the SOAP response
InputStream in = connection.getInputStream();
MultipartBody multipartBody = MultipartBody.builder().setInputStream(in).setContentType(connection.getContentType()).build();
SOAPEnvelope response = OMXMLBuilderFactory.createSOAPModelBuilder(multipartBody).getSOAPEnvelope();
OMElement retrieveContentResponse = response.getBody().getFirstElement();
OMElement content = retrieveContentResponse.getFirstElement();
// Extract the DataHandler representing the optimized binary data
DataHandler dh = ((OMText) content.getFirstOMChild()).getDataHandler();
// Stream the content of the MIME part
InputStream contentStream = ((PartDataHandler) dh).getPart().getInputStream(false);
// Write the content to the result stream
IOUtils.copy(contentStream, result);
contentStream.close();
in.close();
}
use of org.apache.axiom.om.OMElement 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.om.OMElement in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testCreateSerializeAndSerializeOptimized.
/**
* Test reading a message containing XOP.
* Serialize the tree (with caching).
* Then ensure that the XOP is preserved when it is serialized again.
* <p>
* Regression test for AXIOM-264.
*
* @throws Exception
*/
public void testCreateSerializeAndSerializeOptimized() throws Exception {
OMElement root = createTestMTOMMessage();
// Serialize the tree (with caching).
root.serialize(new ByteArrayOutputStream());
// Write out the source
checkSerialization(root, true);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testCreateOMElement.
public void testCreateOMElement() throws Exception {
OMElement root = createTestMTOMMessage();
OMElement body = (OMElement) root.getFirstOMChild();
OMElement data = (OMElement) body.getFirstOMChild();
Iterator childIt = data.getChildren();
OMElement child = (OMElement) childIt.next();
OMText blob = (OMText) child.getFirstOMChild();
/*
* Following is the procedure the user has to follow to read objects in
* OBBlob User has to know the object type & whether it is serializable.
* If it is not he has to use a Custom Defined DataSource to get the
* Object.
*/
byte[] expectedObject = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 98 };
DataHandler actualDH;
actualDH = blob.getDataHandler();
//ByteArrayInputStream object = (ByteArrayInputStream) actualDH
//.getContent();
//byte[] actualObject= null;
// object.read(actualObject,0,10);
// assertEquals("Object check", expectedObject[5],actualObject[5] );
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class ElementSerializerTest method testDualNamespaces1.
public void testDualNamespaces1() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns1 = factory.createOMNamespace("bar", "x");
OMNamespace ns2 = factory.createOMNamespace("bar", "y");
OMElement root = factory.createOMElement("root", ns1);
OMElement elt11 = factory.createOMElement("foo1", ns1);
OMElement elt12 = factory.createOMElement("foo2", ns1);
OMElement elt21 = factory.createOMElement("yuck", ns2);
OMElement elt22 = factory.createOMElement("yuck", ns2);
elt11.addChild(elt21);
elt12.addChild(elt22);
root.addChild(elt11);
root.addChild(elt12);
root.serialize(writer);
}
Aggregations