use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ScriptMediatorFactory method getIncludeKeysMap.
private Map<Value, Object> getIncludeKeysMap(OMElement elem) {
// get <include /> scripts
// map key = registry entry key, value = script source
// at this time map values are null, later loaded
// from void ScriptMediator.prepareExternalScript(MessageContext synCtx)
// TreeMap used to keep given scripts order if needed
Map<Value, Object> includeKeysMap = new LinkedHashMap<Value, Object>();
Iterator itr = elem.getChildrenWithName(INCLUDE_Q);
while (itr.hasNext()) {
OMElement includeElem = (OMElement) itr.next();
OMAttribute key = includeElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
// 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, includeElem);
if (key == null) {
throw new SynapseException("Cannot use 'include' element without 'key'" + " attribute for a script mediator");
}
includeKeysMap.put(generatedKey, null);
}
return includeKeysMap;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class SynapseXMLConfigurationFactory method getConfiguration.
public SynapseConfiguration getConfiguration(OMElement definitions, Properties properties) {
if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
throw new SynapseException("Wrong QName for this configuration factory " + definitions.getQName());
}
SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
config.setDefaultQName(definitions.getQName());
Iterator itr = definitions.getChildren();
while (itr.hasNext()) {
Object o = itr.next();
if (o instanceof OMElement) {
OMElement elt = (OMElement) o;
if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
String key = elt.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
// this could be a sequence def or a referred sequence
if (key != null) {
handleException("Referred sequences are not allowed at the top level");
} else {
defineSequence(config, elt, properties);
}
} else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
defineTemplate(config, elt, properties);
} else if (XMLConfigConstants.IMPORT_ELT.equals(elt.getQName())) {
defineImport(config, elt, properties);
} else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
defineEndpoint(config, elt, properties);
} else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
defineEntry(config, elt, properties);
} else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
defineProxy(config, elt, properties);
} else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
defineRegistry(config, elt, properties);
} else if (XMLConfigConstants.EVENT_SOURCE_ELT.equals(elt.getQName())) {
defineEventSource(config, elt, properties);
} else if (XMLConfigConstants.EXECUTOR_ELT.equals(elt.getQName())) {
defineExecutor(config, elt, properties);
} else if (XMLConfigConstants.MESSAGE_STORE_ELT.equals(elt.getQName())) {
defineMessageStore(config, elt, properties);
} else if (XMLConfigConstants.TASK_MANAGER_ELT.equals(elt.getQName())) {
defineTaskManager(config, elt, properties);
} else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())) {
defineMessageProcessor(config, elt, properties);
} else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
defineStartup(config, elt, properties);
} else if (XMLConfigConstants.API_ELT.equals(elt.getQName())) {
defineAPI(config, elt, properties);
} else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
config.setDescription(elt.getText());
} else if (XMLConfigConstants.INBOUND_ENDPOINT_ELT.equals(elt.getQName())) {
defineInboundEndpoint(config, elt, properties);
} else {
handleException("Invalid configuration element at the top level, one of \'sequence\', " + "\'endpoint\', \'proxy\', \'eventSource\', \'localEntry\', \'priorityExecutor\'" + ", \'registry\' or \'inboundEndpoint\' is expected");
}
} else if (o instanceof OMComment) {
OMComment commentNode = (OMComment) o;
defineComments(config, commentNode);
}
}
return config;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MediatorFactoryFinder method loadMediatorFactories.
private static void loadMediatorFactories() {
for (Class c : mediatorFactories) {
try {
MediatorFactory fac = (MediatorFactory) c.newInstance();
factoryMap.put(fac.getTagQName(), c);
} catch (Exception e) {
throw new SynapseException("Error instantiating " + c.getName(), e);
}
}
// now iterate through the available pluggable mediator factories
registerExtensions();
initialized = true;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MediatorPropertySerializer method serializeMediatorProperty.
/**
* Serialize the property to the given paren element. There will be a element created with
* given name inside the parent element.
*
* @param parent element to which property elements should be added
* @param mp a property to be serialized
* @param childElementName <code>QName</code> of the element to be created
*/
public static void serializeMediatorProperty(OMElement parent, MediatorProperty mp, QName childElementName) {
OMElement prop = fac.createOMElement(childElementName, parent);
if (mp.getName() != null) {
prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
} else {
String msg = "Mediator property name missing";
log.error(msg);
throw new SynapseException(msg);
}
if (mp.getValue() != null) {
prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));
} else if (mp.getExpression() != null) {
SynapsePathSerializer.serializePath(mp.getExpression(), prop, "expression");
} else {
String msg = "Mediator property must have a literal value or be an expression";
log.error(msg);
throw new SynapseException(msg);
}
if (mp.getScope() != null && !XMLConfigConstants.SCOPE_DEFAULT.equals(mp.getScope())) {
prop.addAttribute(fac.createOMAttribute("scope", nullNS, mp.getScope()));
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class TemplateMediatorFactory method createSpecificMediator.
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
TemplateMediator templateTemplateMediator = new TemplateMediator();
OMAttribute nameAttr = elem.getAttribute(ATT_NAME);
if (nameAttr != null) {
templateTemplateMediator.setName(nameAttr.getAttributeValue());
processAuditStatus(templateTemplateMediator, elem);
initParameters(elem, templateTemplateMediator);
OMElement templateBodyElem = elem.getFirstChildWithName(TEMPLATE_BODY_Q);
addChildren(templateBodyElem, templateTemplateMediator, properties);
} else {
String msg = "A EIP template should be a named mediator .";
log.error(msg);
throw new SynapseException(msg);
}
return templateTemplateMediator;
}
Aggregations