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