Search in sources :

Example 51 with OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLJsonWithStringValue.

@Test(description = "Convert a json object with string value only")
public void testToXMLJsonWithStringValue() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLStringValue");
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(((OMText) returnElement).getText(), "value");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) Test(org.testng.annotations.Test)

Example 52 with OMNode

use of org.apache.axiom.om.OMNode in project carbon-apimgt by wso2.

the class TenantWorkflowConfigHolder method loadProperties.

private void loadProperties(OMElement executorElem, Object workflowClass) throws WorkflowException {
    for (Iterator it = executorElem.getChildrenWithName(PROP_Q); it.hasNext(); ) {
        OMElement propertyElem = (OMElement) it.next();
        OMAttribute attribute = propertyElem.getAttribute(ATT_NAME);
        if (attribute == null) {
            handleException("An Executor class property must specify the name attribute");
        } else {
            String propName = attribute.getAttributeValue();
            OMNode omElt = propertyElem.getFirstElement();
            if (omElt != null) {
                setInstanceProperty(propName, omElt, workflowClass);
            } else if (propertyElem.getText() != null) {
                String value = MiscellaneousUtil.resolve(propertyElem, secretResolver);
                setInstanceProperty(propName, value, workflowClass);
            } else {
                handleException("An Executor class property must specify " + "name and text value, or a name and a child XML fragment");
            }
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 53 with OMNode

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

the class MediatorFactoryFinder method buildParamteres.

private void buildParamteres(OMElement connectorElem, InvokeMediator invokeMediator) {
    Iterator parameters = connectorElem.getChildElements();
    while (parameters.hasNext()) {
        OMNode paramNode = (OMNode) parameters.next();
        if (paramNode instanceof OMElement) {
            // ((OMElement) paramNode).getAttributeValue(new QName("name"));
            String paramName = ((OMElement) paramNode).getLocalName();
            // ((OMElement) paramNode).getAttributeValue(new QName("value"));
            String paramValueStr = ((OMElement) paramNode).getText();
            if (paramName != null && !paramName.equals("") && paramValueStr != null && !paramValueStr.equals("")) {
                Value paramValue = new ValueFactory().createTextValue((OMElement) paramNode);
                invokeMediator.addExpressionForParamName(paramName, paramValue);
            }
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) Iterator(java.util.Iterator) Value(org.apache.synapse.mediators.Value) OMElement(org.apache.axiom.om.OMElement)

Example 54 with OMNode

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

the class JsonUtil method removeJsonPayload.

/**
 * Removes the existing JSON payload of a message context if any.<br/>
 * This method can only remove a JSON payload that has been set with {@link #getNewJsonPayload(org.apache.axis2.context.MessageContext, java.io.InputStream, boolean, boolean)}
 * and its variants.
 *
 * @param messageContext Axis2 Message context from which the JSON stream must be removed.
 * @return <tt>true</tt> if the operation is successful.
 */
public static boolean removeJsonPayload(MessageContext messageContext) {
    messageContext.removeProperty(Constants.ORG_APACHE_SYNAPSE_COMMONS_JSON_JSON_INPUT_STREAM);
    messageContext.removeProperty(ORG_APACHE_SYNAPSE_COMMONS_JSON_IS_JSON_OBJECT);
    boolean removeChildren = true;
    if (!removeChildren) {
        // don't change this.
        if (logger.isTraceEnabled()) {
            logger.trace("#removeJsonPayload. Removed JSON stream. MessageID: " + messageContext.getMessageID());
        }
        return true;
    }
    SOAPEnvelope e = messageContext.getEnvelope();
    if (e != null) {
        SOAPBody b = e.getBody();
        if (b != null) {
            Iterator children = b.getChildren();
            while (children.hasNext()) {
                Object o = children.next();
                if (o instanceof OMNode) {
                    // ((OMNode) o).detach();
                    children.remove();
                }
            }
            if (logger.isTraceEnabled()) {
                logger.trace("#removeJsonPayload. Removed JSON stream and child elements of payload. MessageID: " + messageContext.getMessageID());
            }
        }
    }
    return true;
}
Also used : OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) Iterator(java.util.Iterator) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 55 with OMNode

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

the class SynapseConfiguration method getEndpointTemplate.

public Template getEndpointTemplate(String key) {
    Object o = getEntry(key);
    if (o instanceof Template) {
        return (Template) o;
    }
    Entry entry = null;
    if (o == null) {
        entry = new Entry(key);
        entry.setType(Entry.REMOTE_ENTRY);
    } else {
        Object object = localRegistry.get(key);
        if (object instanceof Entry) {
            entry = (Entry) object;
        }
    }
    assertEntryNull(entry, key);
    // noinspection ConstantConditions
    if (entry.getMapper() == null) {
        entry.setMapper(new XMLToTemplateMapper(this));
    }
    if (entry.getType() == Entry.REMOTE_ENTRY) {
        if (registry != null) {
            o = registry.getResource(entry, getProperties());
            if (o != null && o instanceof Template) {
                localRegistry.put(key, entry);
                return (Template) o;
            } else if (o instanceof OMNode) {
                Template m = new TemplateFactory().createEndpointTemplate((OMElement) o, properties);
                if (m != null) {
                    entry.setValue(m);
                    return m;
                }
            }
        }
    } else {
        Object value = entry.getValue();
        if (value instanceof OMNode) {
            Object object = entry.getMapper().getObjectFromOMNode((OMNode) value, getProperties());
            if (object instanceof Template) {
                entry.setValue(object);
                return (Template) object;
            }
        }
    }
    // load from available libraries
    Template templateFromLib = LibDeployerUtils.getLibArtifact(synapseLibraries, key, Template.class);
    if (templateFromLib != null) {
        return templateFromLib;
    }
    return null;
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) XMLToTemplateMapper(org.apache.synapse.config.xml.XMLToTemplateMapper) TemplateFactory(org.apache.synapse.config.xml.endpoints.TemplateFactory) Template(org.apache.synapse.endpoints.Template)

Aggregations

OMNode (org.apache.axiom.om.OMNode)150 OMElement (org.apache.axiom.om.OMElement)87 Iterator (java.util.Iterator)28 OMText (org.apache.axiom.om.OMText)23 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 BXMLItem (org.ballerinalang.model.values.BXMLItem)18 StringReader (java.io.StringReader)17 SynapseException (org.apache.synapse.SynapseException)15 OMAttribute (org.apache.axiom.om.OMAttribute)14 OMFactory (org.apache.axiom.om.OMFactory)14 BValue (org.ballerinalang.model.values.BValue)14 BXML (org.ballerinalang.model.values.BXML)14 Test (org.testng.annotations.Test)14 QName (javax.xml.namespace.QName)13 BJSON (org.ballerinalang.model.values.BJSON)13 OMDocument (org.apache.axiom.om.OMDocument)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 SOAPHeader (org.apache.axiom.soap.SOAPHeader)10 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)10