use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class XSLTMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
XSLTMediator transformMediator = new XSLTMediator();
OMAttribute attXslt = elem.getAttribute(ATT_KEY);
OMAttribute attSource = elem.getAttribute(ATT_SOURCE);
OMAttribute attTarget = elem.getAttribute(ATT_TARGET);
OMAttribute attUseCache = elem.getAttribute(ATT_USECACHE);
if (attXslt != null) {
// ValueFactory for creating dynamic or static Value
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
// set generated key as the Value
transformMediator.setXsltKey(generatedKey);
} else {
handleException("The '" + XMLConfigConstants.KEY + "' " + "attribute is required for the XSLT mediator");
}
if (attSource != null) {
try {
transformMediator.setSourceXPathString(attSource.getAttributeValue());
transformMediator.setSource(SynapseXPathFactory.getSynapseXPath(elem, ATT_SOURCE));
} catch (JaxenException e) {
handleException("Invalid XPath specified for the source attribute : " + attSource.getAttributeValue());
}
}
if (attTarget != null) {
transformMediator.setTargetPropertyName(attTarget.getAttributeValue());
}
if (attUseCache != null) {
transformMediator.setUseCache(Boolean.parseBoolean(attUseCache.getAttributeValue()));
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(transformMediator, elem);
// set the features
for (Map.Entry<String, String> entry : collectNameValuePairs(elem, FEATURE_Q).entrySet()) {
String value = entry.getValue();
boolean isFeatureEnabled;
if ("true".equals(value)) {
isFeatureEnabled = true;
} else if ("false".equals(value)) {
isFeatureEnabled = false;
} else {
handleException("The feature must have value true or false");
break;
}
transformMediator.addFeature(entry.getKey(), isFeatureEnabled);
}
for (Map.Entry<String, String> entry : collectNameValuePairs(elem, ATTRIBUTE_Q).entrySet()) {
transformMediator.addAttribute(entry.getKey(), entry.getValue());
}
transformMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
transformMediator.setResourceMap(ResourceMapFactory.createResourceMap(elem));
return transformMediator;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class SequenceMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
SequenceMediator seqMediator = new SequenceMediator();
OMAttribute n = elem.getAttribute(ATT_NAME);
OMAttribute e = elem.getAttribute(ATT_ONERROR);
if (n != null) {
seqMediator.setName(n.getAttributeValue());
if (e != null) {
seqMediator.setErrorHandler(e.getAttributeValue());
}
processAuditStatus(seqMediator, elem);
addChildren(elem, seqMediator, properties);
} else {
n = elem.getAttribute(ATT_KEY);
if (n != null) {
// ValueFactory for creating dynamic or static Value
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
// setKey
seqMediator.setKey(generatedKey);
if (e != null) {
String msg = "A sequence mediator with a reference to another " + "sequence can not have 'ErrorHandler'";
log.error(msg);
throw new SynapseException(msg);
}
} else {
String msg = "A sequence mediator should be a named sequence or a reference " + "to another sequence (i.e. a name attribute or key attribute is required)";
log.error(msg);
throw new SynapseException(msg);
}
}
return seqMediator;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class RecipientListEndpointFactory method createEndpoint.
@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement recipientListElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
if (recipientListElement != null) {
// create endpoint
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
// set endpoints or members
if (recipientListElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
if (recipientListElement.getChildrenWithName((MEMBER)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Endpoint> endpoints = getEndpoints(recipientListElement, recipientListEndpoint, properties);
recipientListEndpoint.setChildren(endpoints);
} else if (recipientListElement.getFirstChildWithName(MEMBER) != null) {
if (recipientListElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "recipientListElement element cannot have both member & endpoint " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Member> members = getMembers(recipientListElement);
recipientListEndpoint.setMembers(members);
} else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) {
OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET);
Value dynamicEndpointSet = new ValueFactory().createValue("value", dynamicSetElement);
String maxStr = dynamicSetElement.getAttributeValue(new QName("max-cache"));
int maxCache = -1;
try {
maxCache = Integer.parseInt(maxStr);
} catch (NumberFormatException e) {
}
recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache);
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet);
}
if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) {
String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements.";
log.error(msg);
throw new SynapseException(msg);
}
// process the parameters
processProperties(recipientListEndpoint, epConfig);
return recipientListEndpoint;
}
return null;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class PayloadFactoryMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
processAuditStatus(payloadFactoryMediator, elem);
String mediaTypeValue = elem.getAttributeValue(TYPE_Q);
// for the backward compatibility.
if (mediaTypeValue != null) {
// set the mediaType for the PF
payloadFactoryMediator.setType(mediaTypeValue);
} else {
payloadFactoryMediator.setType(XML_TYPE);
}
OMElement formatElem = elem.getFirstChildWithName(FORMAT_Q);
if (formatElem != null) {
OMAttribute n = formatElem.getAttribute(ATT_KEY);
if (n == null) {
// OMElement copy = formatElem.getFirstElement().cloneOMElement();
OMElement copy = formatElem.cloneOMElement();
removeIndentations(copy);
if (mediaTypeValue != null && (mediaTypeValue.contains(JSON_TYPE) || mediaTypeValue.contains(TEXT_TYPE))) {
payloadFactoryMediator.setFormat(copy.getText());
} else {
payloadFactoryMediator.setFormat(copy.getFirstElement().toString());
}
} else {
ValueFactory keyFac = new ValueFactory();
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, formatElem);
payloadFactoryMediator.setFormatKey(generatedKey);
payloadFactoryMediator.setFormatDynamic(true);
}
} else {
handleException("format element of payloadFactoryMediator is required");
}
OMElement argumentsElem = elem.getFirstChildWithName(ARGS_Q);
if (argumentsElem != null) {
Iterator itr = argumentsElem.getChildElements();
while (itr.hasNext()) {
OMElement argElem = (OMElement) itr.next();
Argument arg = new Argument();
String value;
boolean isLiteral = false;
String isLiteralString = argElem.getAttributeValue(ATT_LITERAL);
if (isLiteralString != null) {
// if literal is 'true' then set literal to true. defaults to false.
isLiteral = Boolean.parseBoolean(isLiteralString);
}
arg.setLiteral(isLiteral);
if ((value = argElem.getAttributeValue(ATT_VALUE)) != null) {
arg.setValue(value);
arg.setExpression(null);
payloadFactoryMediator.addPathArgument(arg);
} else if ((value = argElem.getAttributeValue(ATT_EXPRN)) != null) {
if (value.trim().length() == 0) {
handleException("Attribute value for xpath cannot be empty");
} else {
try {
// set the evaluator
String evaluator = argElem.getAttributeValue(ATT_EVAL);
if (evaluator != null && evaluator.equals(JSON_TYPE)) {
if (value.startsWith("json-eval(")) {
value = value.substring(10, value.length() - 1);
}
arg.setExpression(SynapseJsonPathFactory.getSynapseJsonPath(value));
// we have to explicitly define the path type since we are not going to mark
// JSON Path's with prefix "json-eval(".
arg.getExpression().setPathType(SynapsePath.JSON_PATH);
payloadFactoryMediator.addPathArgument(arg);
} else {
SynapseXPath sxp = SynapseXPathFactory.getSynapseXPath(argElem, ATT_EXPRN);
// we need to disable stream Xpath forcefully
sxp.setForceDisableStreamXpath(Boolean.TRUE);
arg.setExpression(sxp);
arg.getExpression().setPathType(SynapsePath.X_PATH);
payloadFactoryMediator.addPathArgument(arg);
}
} catch (JaxenException e) {
handleException("Invalid XPath expression for attribute expression : " + value, e);
}
}
} else {
handleException("Unsupported arg type. value or expression attribute required");
}
}
}
return payloadFactoryMediator;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class SendMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
SendMediator sm = new SendMediator();
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(sm, elem);
OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
if (epElement != null) {
// create the endpoint and set it in the send mediator
Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
if (endpoint != null) {
sm.setEndpoint(endpoint);
}
}
String receivingSequence = elem.getAttributeValue(RECEIVING_SEQUENCE);
if (receivingSequence != null) {
ValueFactory valueFactory = new ValueFactory();
Value value = valueFactory.createValue(XMLConfigConstants.RECEIVE, elem);
sm.setReceivingSequence(value);
}
String buildMessage = elem.getAttributeValue(BUILD_MESSAGE);
if ("true".equals(buildMessage)) {
sm.setBuildMessage(true);
}
return sm;
}
Aggregations