use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testDeferredLoadingOfAttachments.
/**
* Test that MIME parts are not loaded before requesting the DataHandlers from the corresponding
* OMText nodes.
*
* @throws Exception
*/
public void testDeferredLoadingOfAttachments() throws Exception {
Attachments attachments = createAttachmentsForTestMTOMMessage();
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
OMDocument doc = builder.getDocument();
// Find all the binary nodes
List<OMText> binaryNodes = new ArrayList<>();
for (Iterator<OMSerializable> it = doc.getDescendants(false); it.hasNext(); ) {
OMSerializable node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
binaryNodes.add(text);
}
}
}
assertFalse(binaryNodes.isEmpty());
// At this moment only the SOAP part should have been loaded
assertEquals(1, attachments.getContentIDList().size());
for (OMText node : binaryNodes) {
// Request the DataHandler and do something with it to make sure
// the part is loaded
node.getDataHandler().getInputStream().close();
}
assertEquals(binaryNodes.size() + 1, attachments.getContentIDList().size());
}
use of org.apache.axiom.om.OMText 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.OMText in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMElement
*
* @param element
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest value
*/
public byte[] getDigest(OMElement element, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(1);
dos.write(getExpandedName(element).getBytes("UnicodeBigUnmarked"));
dos.write((byte) 0);
dos.write((byte) 0);
Collection<OMAttribute> attrs = getAttributesWithoutNS(element);
dos.writeInt(attrs.size());
for (Iterator<OMAttribute> itr = attrs.iterator(); itr.hasNext(); ) {
dos.write(getDigest(itr.next(), digestAlgorithm));
}
OMNode node = element.getFirstOMChild();
// adjoining Texts are merged,
// there is no 0-length Text, and
// comment nodes are removed.
int length = 0;
for (Iterator<OMNode> itr = element.getChildren(); itr.hasNext(); ) {
OMNode child = itr.next();
if (child instanceof OMElement || child instanceof OMText || child instanceof OMProcessingInstruction) {
length++;
}
}
dos.writeInt(length);
while (node != null) {
dos.write(getDigest(node, digestAlgorithm));
node = node.getNextOMSibling();
}
dos.close();
md.update(baos.toByteArray());
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (IOException e) {
throw new OMException(e);
}
return digest;
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestDiscardPartiallyBuilt method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><element><a><b>text</b></a><c/></element><sibling/></root>")).getDocumentElement();
OMElement element = root.getFirstElement();
// Navigate to the text node so that the element is partially built
OMElement b = element.getFirstElement().getFirstElement();
OMText text = (OMText) b.getFirstOMChild();
assertEquals("text", text.getText());
element.discard();
assertAbout(xml()).that(xml(OMElement.class, root)).hasSameContentAs("<root><sibling/></root>");
// Force the builder to complete the document. If the discard method didn't adjust the
// element depth correctly, then an exception will occur here
assertNull(root.getNextOMSibling());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestInsertSiblingBeforeOnSelf method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("test", null);
OMText text = factory.createOMText("test");
parent.addChild(text);
try {
text.insertSiblingBefore(text);
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
Aggregations