Search in sources :

Example 66 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class PayloadFactoryMediatorFactory method removeIndentations.

private void removeIndentations(OMElement element) {
    List<OMText> removables = new ArrayList<OMText>();
    removeIndentations(element, removables);
    for (OMText node : removables) {
        node.detach();
    }
}
Also used : OMText(org.apache.axiom.om.OMText) ArrayList(java.util.ArrayList)

Example 67 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class EntryFactory method createEntry.

public static Entry createEntry(OMElement elem, Properties properties) {
    String customFactory = SynapsePropertiesLoader.getPropertyValue("synapse.entry.factory", "");
    if (customFactory != null && !"".equals(customFactory)) {
        try {
            Class c = Class.forName(customFactory);
            Object o = c.newInstance();
            if (o instanceof IEntryFactory) {
                return ((IEntryFactory) o).createEntry(elem);
            }
        } catch (ClassNotFoundException e) {
            handleException("Class specified by the synapse.entry.factory " + "synapse property not found: " + customFactory, e);
        } catch (InstantiationException e) {
            handleException("Class specified by the synapse.entry.factory " + "synapse property cannot be instantiated: " + customFactory, e);
        } catch (IllegalAccessException e) {
            handleException("Class specified by the synapse.entry.factory " + "synapse property cannot be accessed: " + customFactory, e);
        }
    }
    OMAttribute key = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
    if (key == null) {
        handleException("The 'key' attribute is required for a local registry entry");
        return null;
    } else {
        Entry entry = new Entry(key.getAttributeValue());
        OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
        if (descriptionElem != null) {
            entry.setDescription(descriptionElem.getText());
            descriptionElem.detach();
        }
        String src = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "src"));
        // are initialized at startup
        if (src != null) {
            try {
                entry.setSrc(new URL(src.trim()));
                entry.setType(Entry.URL_SRC);
                entry.setValue(SynapseConfigUtils.getObject(entry.getSrc(), properties));
            } catch (MalformedURLException e) {
                handleException("The entry with key : " + key + " refers to an invalid URL");
            }
        } else {
            OMNode nodeValue = elem.getFirstOMChild();
            OMElement elemValue = elem.getFirstElement();
            if (elemValue != null) {
                entry.setType(Entry.INLINE_XML);
                entry.setValue(elemValue);
            } else if (nodeValue != null && nodeValue instanceof OMText) {
                entry.setType(Entry.INLINE_TEXT);
                entry.setValue(elem.getText().trim());
            }
        }
        return entry;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) URL(java.net.URL) OMNode(org.apache.axiom.om.OMNode) Entry(org.apache.synapse.config.Entry) OMText(org.apache.axiom.om.OMText) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 68 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class Target method insertElement.

private void insertElement(ArrayList<OMNode> sourceNodeList, OMElement e, SynapseLog synLog) {
    if (action.equals(ACTION_REPLACE)) {
        boolean isInserted = false;
        for (OMNode elem : sourceNodeList) {
            if (elem instanceof OMElement) {
                e.insertSiblingBefore(elem);
                isInserted = true;
            } else if (elem instanceof OMText) {
                e.setText(((OMText) elem).getText());
            } else {
                synLog.error("Invalid Source object to be inserted.");
            }
        }
        if (isInserted) {
            e.detach();
        }
    } else if (action.equals(ACTION_ADD_CHILD)) {
        for (OMNode elem : sourceNodeList) {
            if (elem instanceof OMElement) {
                synchronized (elem) {
                    e.addChild(elem);
                }
            }
        }
    } else if (action.equals(ACTION_ADD_SIBLING)) {
        for (OMNode elem : sourceNodeList) {
            if (elem instanceof OMElement) {
                e.insertSiblingAfter(elem);
            }
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 69 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class BinaryExtractMediator method mediate.

public boolean mediate(MessageContext msgCtx) {
    try {
        log.debug("BinaryExtractMediator Process, with offset: " + offset + " ,length " + length);
        SOAPBody soapBody = msgCtx.getEnvelope().getBody();
        OMElement firstElement = soapBody.getFirstElement();
        log.debug("First Element : " + firstElement.getLocalName());
        log.debug("First Element Text : " + firstElement.getText());
        OMText binaryNode = (OMText) firstElement.getFirstOMChild();
        log.debug("First Element Node Text : " + binaryNode.getText());
        DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler();
        InputStream inputStream = dataHandler.getInputStream();
        byte[] searchByte = new byte[length];
        inputStream.skip(offset - 1);
        int readBytes = inputStream.read(searchByte, 0, length);
        String outString = new String(searchByte, binaryEncoding);
        msgCtx.setProperty(variableName, outString);
        log.debug("Set property to MsgCtx, " + variableName + " = " + outString);
        inputStream.close();
    } catch (IOException e) {
        log.error("Excepton on mediation : " + e.getMessage());
    }
    return true;
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) InputStream(java.io.InputStream) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException)

Example 70 with OMText

use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.

the class MTOMSwASampleService method oneWayUploadUsingMTOM.

public void oneWayUploadUsingMTOM(OMElement element) throws Exception {
    OMText binaryNode = (OMText) element.getFirstOMChild();
    DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler();
    InputStream is = dataHandler.getInputStream();
    File tempFile = File.createTempFile("mtom-", ".gif");
    FileOutputStream fos = new FileOutputStream(tempFile);
    BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
    byte[] data = new byte[BUFFER];
    int count;
    while ((count = is.read(data, 0, BUFFER)) != -1) {
        dest.write(data, 0, count);
    }
    dest.flush();
    dest.close();
    System.out.println("Wrote to file : " + tempFile.getAbsolutePath());
}
Also used : OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler)

Aggregations

OMText (org.apache.axiom.om.OMText)92 OMElement (org.apache.axiom.om.OMElement)62 OMFactory (org.apache.axiom.om.OMFactory)39 DataHandler (javax.activation.DataHandler)26 OMNode (org.apache.axiom.om.OMNode)21 OMNamespace (org.apache.axiom.om.OMNamespace)10 QName (javax.xml.namespace.QName)8 OMException (org.apache.axiom.om.OMException)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 InputStream (java.io.InputStream)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 Entry (org.apache.synapse.config.Entry)6 ArrayList (java.util.ArrayList)5 DataSource (javax.activation.DataSource)5 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4