use of org.apache.axiom.om.OMAttribute 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.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class ListenerContextBuilder method createParser.
private Parser createParser(final OMElement definitions) throws AxisFault {
OMElement conditionsElem = definitions.getFirstChildWithName(new QName(EvaluatorConstants.CONDITIONS));
if (conditionsElem == null) {
handleException("Conditions configuration is mandatory for priority based routing");
}
assert conditionsElem != null;
OMAttribute defPriorityAttr = conditionsElem.getAttribute(new QName(EvaluatorConstants.DEFAULT_PRIORITY));
Parser parser;
if (defPriorityAttr != null) {
parser = new Parser(Integer.parseInt(defPriorityAttr.getAttributeValue()));
} else {
parser = new Parser();
}
try {
parser.init(conditionsElem);
} catch (EvaluatorException e) {
handleException("Invalid " + EvaluatorConstants.CONDITIONS + " configuration for priority based mediation", e);
}
return parser;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class EventPublisherMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
EventPublisherMediator eventPublisherMediator = new EventPublisherMediator();
processAuditStatus(eventPublisherMediator, elem);
OMAttribute attEventSource = elem.getAttribute(PROP_NAME);
if (attEventSource != null) {
eventPublisherMediator.setEventSourceName(attEventSource.getAttributeValue());
} else {
handleException("The 'eventSourceName' attribute is required for the EventPublisher mediator");
}
return eventPublisherMediator;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class EventSourceFactory method createEventSource.
@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
SynapseEventSource eventSource = null;
OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name == null) {
handleException("The 'name' attribute is required for a event source de");
} else {
eventSource = new SynapseEventSource(name.getAttributeValue());
}
OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
if (eventSource != null && subscriptionManagerElem != null) {
OMAttribute clazz = subscriptionManagerElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
if (clazz != null) {
String className = clazz.getAttributeValue();
try {
Class subscriptionManagerClass = Class.forName(className);
SubscriptionManager manager = (SubscriptionManager) subscriptionManagerClass.newInstance();
Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
while (itr.hasNext()) {
OMElement propElem = (OMElement) itr.next();
String propName = propElem.getAttribute(new QName("name")).getAttributeValue();
String propValue = propElem.getAttribute(new QName("value")).getAttributeValue();
if (propName != null && !"".equals(propName.trim()) && propValue != null && !"".equals(propValue.trim())) {
propName = propName.trim();
propValue = propValue.trim();
PasswordManager passwordManager = PasswordManager.getInstance();
String key = eventSource.getName() + "." + propName;
if (passwordManager.isInitialized() && passwordManager.isTokenProtected(key)) {
eventSource.putConfigurationProperty(propName, propValue);
propValue = passwordManager.resolve(propValue);
}
manager.addProperty(propName, propValue);
}
}
eventSource.setSubscriptionManager(manager);
eventSource.getSubscriptionManager().init();
} catch (ClassNotFoundException e) {
handleException("SubscriptionManager class not found", e);
} catch (IllegalAccessException e) {
handleException("Unable to access the SubscriptionManager object", e);
} catch (InstantiationException e) {
handleException("Unable to instantiate the SubscriptionManager object", e);
}
} else {
handleException("SynapseSubscription manager class is a required attribute");
}
} else {
handleException("SynapseSubscription Manager has not been specified for the event source");
}
try {
createStaticSubscriptions(elem, eventSource);
} catch (EventException e) {
handleException("Static subscription creation failure", e);
}
return eventSource;
}
use of org.apache.axiom.om.OMAttribute 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;
}
Aggregations