use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class DynamicLoadbalanceEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dynamicLoadbalance"));
if (loadbalanceElement != null) {
DynamicLoadbalanceEndpoint loadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
// get the session for this endpoint
OMElement sessionElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
if (sessionElement != null) {
OMElement sessionTimeout = sessionElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sessionTimeout"));
if (sessionTimeout != null) {
try {
loadbalanceEndpoint.setSessionTimeout(Long.parseLong(sessionTimeout.getText().trim()));
} catch (NumberFormatException nfe) {
handleException("Invalid session timeout value : " + sessionTimeout.getText());
}
}
String type = sessionElement.getAttributeValue(new QName("type"));
if (type.equalsIgnoreCase("soap")) {
Dispatcher soapDispatcher = new SoapSessionDispatcher();
loadbalanceEndpoint.setDispatcher(soapDispatcher);
} else if (type.equalsIgnoreCase("http")) {
Dispatcher httpDispatcher = new HttpSessionDispatcher();
loadbalanceEndpoint.setDispatcher(httpDispatcher);
}
loadbalanceEndpoint.setSessionAffinity(true);
}
// set if failover is turned off
String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
if (failover != null && failover.equalsIgnoreCase("false")) {
loadbalanceEndpoint.setFailover(false);
} else {
loadbalanceEndpoint.setFailover(true);
}
OMElement eventHandler = loadbalanceElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "membershipHandler"));
if (eventHandler != null) {
String clazz = eventHandler.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "class")).trim();
try {
LoadBalanceMembershipHandler lbMembershipHandler = (LoadBalanceMembershipHandler) Class.forName(clazz).newInstance();
Properties lbProperties = new Properties();
for (Iterator props = eventHandler.getChildrenWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "property")); props.hasNext(); ) {
OMElement prop = (OMElement) props.next();
String propName = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")).trim();
String propValue = prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "value")).trim();
lbProperties.put(propName, propValue);
}
// Set load balance algorithm
LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, null);
lbMembershipHandler.init(lbProperties, algorithm);
loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
} catch (Exception e) {
String msg = "Could not instantiate " + "LoadBalanceMembershipHandler implementation " + clazz;
log.error(msg, e);
throw new SynapseException(msg, e);
}
}
processProperties(loadbalanceEndpoint, epConfig);
return loadbalanceEndpoint;
}
return null;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class POJOCommandMediatorFactory method handlePropertyAction.
private void handlePropertyAction(String name, OMElement propElem, POJOCommandMediator m) {
OMAttribute valueAttr = propElem.getAttribute(ATT_VALUE);
OMAttribute exprAttr = propElem.getAttribute(ATT_EXPRN);
OMAttribute ctxNameAttr = propElem.getAttribute(ATT_CTXNAME);
OMAttribute actionAttr = propElem.getAttribute(ATT_ACTION);
SynapseXPath xpath = null;
try {
if (exprAttr != null) {
xpath = SynapseXPathFactory.getSynapseXPath(propElem, ATT_EXPRN);
}
} catch (JaxenException e) {
handleException("Error in building the expression as an SynapseXPath" + e);
}
// if there is a value attribute there is no action (action is implied as read value)
if (valueAttr != null) {
String value = valueAttr.getAttributeValue();
// all other three attributes can not co-exists
if (exprAttr != null && ctxNameAttr != null) {
handleException("Command properties can not contain all three 'value', " + "'expression' and 'context-name' attributes. Only one or " + "combination of two can be there.");
} else {
m.addStaticSetterProperty(name, value);
if (exprAttr != null) {
// action ==> ReadValueAndUpdateMesssage
m.addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
// action ==> ReadValueAndUpdateContext
m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
}
// else the action ==> ReadValue
}
} else if (propElem.getFirstElement() != null) {
// all other two attributes can not co-exists
if (exprAttr != null && ctxNameAttr != null) {
handleException("Command properties can not contain all the " + "'expression' and 'context-name' attributes with a child. Only one " + "attribute of those can co-exists with a child");
} else {
m.addStaticSetterProperty(name, propElem.getFirstElement());
if (exprAttr != null) {
// action ==> ReadValueAndUpdateMesssage
m.addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
// action ==> ReadValueAndUpdateContext
m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
}
// else the action ==> ReadValue
}
} else {
// if both context-name and expression is there
if (exprAttr != null && ctxNameAttr != null) {
if (actionAttr != null && actionAttr.getAttributeValue() != null) {
String action = actionAttr.getAttributeValue();
if (RM_ACTION.equals(action) || UC_ACTION.equals(action)) {
// action ==> ReadMessageAndUpdateContext
m.addMessageSetterProperty(name, xpath);
m.addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
} else if (RC_ACTION.equals(action) || UM_ACTION.equals(action)) {
// action ==> ReadContextAndUpdateMessage
m.addContextSetterProperty(name, ctxNameAttr.getAttributeValue());
m.addMessageGetterProperty(name, xpath);
} else {
handleException("Invalid action for " + "the command property with the name " + name);
}
} else {
handleException("Action attribute " + "is required for the command property with name " + name);
}
} else {
// only one of expression or context-name is present
if (actionAttr != null && actionAttr.getAttributeValue() != null) {
String action = actionAttr.getAttributeValue();
if (exprAttr != null) {
if (RM_ACTION.equals(action)) {
// action ==> ReadMessage
m.addMessageSetterProperty(name, xpath);
} else if (UM_ACTION.equals(action)) {
// action ==> UpdateMessage
m.addMessageGetterProperty(name, xpath);
} else if (RAUM_ACTION.equals(action)) {
// action ==> ReadAndUpdateMessage
m.addMessageSetterProperty(name, xpath);
m.addMessageGetterProperty(name, xpath);
} else {
handleException("Invalid action for " + "the command property with the name " + name);
}
} else if (ctxNameAttr != null) {
String ctxName = ctxNameAttr.getAttributeValue();
if (RC_ACTION.equals(action)) {
// action ==> ReadContext
m.addContextSetterProperty(name, ctxName);
} else if (UC_ACTION.equals(action)) {
// action ==> UpdateContext
m.addContextGetterProperty(name, ctxName);
} else if (RAUC_ACTION.equals(action)) {
// action ==> ReadAndUpdateContext
m.addContextSetterProperty(name, ctxName);
m.addContextGetterProperty(name, ctxName);
} else {
handleException("Invalid action for " + "the command property with the name " + name);
}
} else {
handleException("Unrecognized command property with the name " + name);
}
} else {
// action ==> ReadAndUpdateMessage/Context
if (exprAttr != null) {
m.addMessageSetterProperty(name, xpath);
m.addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
String ctxName = ctxNameAttr.getAttributeValue();
m.addContextSetterProperty(name, ctxName);
m.addContextGetterProperty(name, ctxName);
} else {
handleException("Unrecognized command property with the name " + name);
}
}
}
}
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class ValidateMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
ValidateMediator validateMediator = new ValidateMediator();
// process schema element definitions and create DynamicProperties
List<Value> schemaKeys = new ArrayList<Value>();
Iterator schemas = elem.getChildrenWithName(SCHEMA_Q);
while (schemas.hasNext()) {
Object o = schemas.next();
if (o instanceof OMElement) {
OMElement omElem = (OMElement) o;
OMAttribute keyAtt = omElem.getAttribute(ATT_KEY);
if (keyAtt != 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, omElem);
schemaKeys.add(generatedKey);
} else {
handleException("A 'schema' definition must contain a local property 'key'");
}
} else {
handleException("Invalid 'schema' declaration for validate mediator");
}
}
if (schemaKeys.size() == 0) {
handleException("No schema specified for the validate mediator");
} else {
validateMediator.setSchemaKeys(schemaKeys);
}
// process source XPath attribute if present
OMAttribute attSource = elem.getAttribute(ATT_SOURCE);
if (attSource != null) {
try {
if (attSource.getAttributeValue() != null) {
validateMediator.setSource(SynapsePathFactory.getSynapsePath(elem, ATT_SOURCE));
}
} catch (JaxenException e) {
handleException("Invalid XPath expression specified for attribute 'source'", e);
}
}
// process schema cacheability.
OMAttribute attSchemaCache = elem.getAttribute(ATT_CACHE_SCHEMA);
if (attSchemaCache != null) {
final boolean cacheSchema = Boolean.parseBoolean(attSchemaCache.getAttributeValue());
if (log.isDebugEnabled()) {
log.debug("Schema cached: " + cacheSchema);
}
validateMediator.setCacheSchema(cacheSchema);
}
// process external schema resources
validateMediator.setResourceMap(ResourceMapFactory.createResourceMap(elem));
// process on-fail
OMElement onFail = null;
Iterator iterator = elem.getChildrenWithName(ON_FAIL_Q);
if (iterator.hasNext()) {
onFail = (OMElement) iterator.next();
}
if (onFail != null && onFail.getChildElements().hasNext()) {
addChildren(onFail, validateMediator, properties);
} else {
handleException("A non-empty <on-fail> child element is required for " + "the <validate> mediator");
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(validateMediator, 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;
}
try {
validateMediator.addFeature(entry.getKey(), isFeatureEnabled);
} catch (SAXException e) {
handleException("Error setting validation feature : " + entry.getKey() + " to : " + value, e);
}
}
addAllCommentChildrenToMediator(elem, validateMediator);
return validateMediator;
}
use of org.apache.axiom.om.OMAttribute 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.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class RegistryFactory method getProperties.
private static Properties getProperties(OMElement elem, Properties topLevelProps) {
Iterator params = elem.getChildrenWithName(PARAMETER_Q);
Properties props = new Properties(topLevelProps);
while (params.hasNext()) {
Object o = params.next();
if (o instanceof OMElement) {
OMElement prop = (OMElement) o;
OMAttribute pname = prop.getAttribute(NAME_Q);
String propertyValue = prop.getText();
if (pname != null) {
if (propertyValue != null) {
props.setProperty(pname.getAttributeValue(), propertyValue.trim());
}
} else {
handleException("Invalid registry property - property should have a name ");
}
} else {
handleException("Invalid registry property");
}
}
return props;
}
Aggregations