use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class POJOCommandMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
POJOCommandMediator pojoMediator = new POJOCommandMediator();
processAuditStatus(pojoMediator, elem);
// Class name of the Command object should be present
OMAttribute name = elem.getAttribute(ATT_NAME);
if (name == null) {
String msg = "The name of the actual POJO command implementation class" + " is a required attribute";
log.error(msg);
throw new SynapseException(msg);
}
// load the class for the command object
try {
pojoMediator.setCommand(getClass().getClassLoader().loadClass(name.getAttributeValue()));
} catch (ClassNotFoundException e) {
handleException("Unable to load the class specified as the command " + name.getAttributeValue(), e);
}
// at the mediation time
for (Iterator it = elem.getChildElements(); it.hasNext(); ) {
OMElement child = (OMElement) it.next();
if ("property".equals(child.getLocalName())) {
OMAttribute nameAttr = child.getAttribute(ATT_NAME);
if (nameAttr != null && nameAttr.getAttributeValue() != null && !"".equals(nameAttr.getAttributeValue())) {
handlePropertyAction(nameAttr.getAttributeValue(), child, pojoMediator);
} else {
handleException("A POJO command mediator " + "property must specify the name attribute");
}
}
}
return pojoMediator;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class PropertyMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
PropertyMediator propMediator = new PropertyMediator();
OMAttribute name = elem.getAttribute(ATT_NAME);
OMAttribute value = elem.getAttribute(ATT_VALUE);
OMAttribute expression = elem.getAttribute(ATT_EXPRN);
OMAttribute scope = elem.getAttribute(ATT_SCOPE);
OMAttribute action = elem.getAttribute(ATT_ACTION);
OMAttribute type = elem.getAttribute(ATT_TYPE);
OMAttribute pattern = elem.getAttribute(ATT_PATTERN);
OMAttribute group = elem.getAttribute(ATT_GROUP);
OMElement valueElement = elem.getFirstElement();
if (name == null) {
String msg = "The 'name' attribute is required for the configuration of a property mediator";
log.error(msg);
throw new SynapseException(msg);
} else if ((value == null && valueElement == null && expression == null) && !(action != null && "remove".equals(action.getAttributeValue()))) {
String msg = "Either a child element or one of 'value', 'expression' attributes is " + "required for a property mediator when action is SET";
log.error(msg);
throw new SynapseException(msg);
}
propMediator.setName(name.getAttributeValue());
String dataType = null;
if (type != null) {
dataType = type.getAttributeValue();
}
if (value != null) {
propMediator.setValue(value.getAttributeValue(), dataType);
} else if (valueElement != null) {
// Need to clone to prevent same reference getting modified at the message flow
propMediator.setValueElement(valueElement.cloneOMElement());
} else if (expression != null) {
try {
propMediator.setExpression(SynapsePathFactory.getSynapsePath(elem, ATT_EXPRN), dataType);
} catch (JaxenException e) {
String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
log.error(msg);
throw new SynapseException(msg);
}
}
if (pattern != null) {
propMediator.setPattern(Pattern.compile(pattern.getAttributeValue()));
if (group != null) {
int groupValue = Integer.parseInt(group.getAttributeValue());
if (groupValue >= 0) {
propMediator.setGroup(groupValue);
} else {
String msg = "group can have a positive value only";
log.error(msg);
throw new SynapseException(msg);
}
}
} else if (group != null) {
String msg = "group is only allowed when a pattern is specified";
log.error(msg);
throw new SynapseException(msg);
}
// property mediator will act as a property remove mediator
if (action != null && "remove".equals(action.getAttributeValue())) {
propMediator.setAction(PropertyMediator.ACTION_REMOVE);
}
if (scope != null) {
String valueStr = scope.getAttributeValue();
if (!XMLConfigConstants.SCOPE_AXIS2.equals(valueStr) && !XMLConfigConstants.SCOPE_TRANSPORT.equals(valueStr) && !XMLConfigConstants.SCOPE_OPERATION.equals(valueStr) && !XMLConfigConstants.SCOPE_DEFAULT.equals(valueStr) && !XMLConfigConstants.SCOPE_CLIENT.equals(valueStr) && !XMLConfigConstants.SCOPE_REGISTRY.equals(valueStr)) {
String msg = "Only '" + XMLConfigConstants.SCOPE_AXIS2 + "' or '" + XMLConfigConstants.SCOPE_TRANSPORT + "' or '" + XMLConfigConstants.SCOPE_CLIENT + "' or '" + XMLConfigConstants.SCOPE_DEFAULT + "' or '" + XMLConfigConstants.SCOPE_OPERATION + "' or '" + XMLConfigConstants.SCOPE_REGISTRY + "' values are allowed for attribute scope for a property mediator" + ", Unsupported scope " + valueStr;
log.error(msg);
throw new SynapseException(msg);
}
propMediator.setScope(valueStr);
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(propMediator, elem);
return propMediator;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class EnrichMediatorFactory method validateTypeCombination.
/**
* Check the combination of the source and target types are valid or not and throw proper exception.
* Here the integers 0-4 refer as below
* 0-custom, 1-envelope, 2-body, 3-property, 4-inline
*
* @param sourceElement
* @param targetElement
*/
private void validateTypeCombination(OMElement sourceElement, OMElement targetElement) {
int sourceType = -1;
int targetType = -1;
// source type attribute
OMAttribute sourceTypeAttr = sourceElement.getAttribute(ATT_TYPE);
if (sourceTypeAttr != null && sourceTypeAttr.getAttributeValue() != null) {
sourceType = convertTypeToInt(sourceTypeAttr.getAttributeValue());
// check if source type is different form the existing
if (sourceType < 0) {
throw new SynapseException("Unexpected source type");
}
}
// target type attribute
OMAttribute targetTypeAttr = targetElement.getAttribute(ATT_TYPE);
if (targetTypeAttr != null && targetTypeAttr.getAttributeValue() != null) {
targetType = convertTypeToInt(targetTypeAttr.getAttributeValue());
// check if target type is different form the existing
if (targetType < 0) {
throw new SynapseException("Unexpected target type");
}
// check if target type is 4-inline
if (targetType == 4) {
throw new SynapseException("Inline not support for target attribute");
}
}
/*
check the wrong combination such as
sourceType = 1-envelope and targetType = 0-custom
sourceType = 1-envelope and targetType = 2-body
sourceType = 2-body and targetType = 2-body
sourceType = 0-custom and targetType = 1-envelope
sourceType = 1-envelope and targetType = 1-envelope
sourceType = 2-body and targetType = 1-envelope
*/
if (sourceType == 1) {
if (targetType == 0 || targetType == 1 || targetType == 2) {
throw new SynapseException("Wrong combination of source and target type");
}
} else if (sourceType == 2) {
if (targetType == 1 || targetType == 2) {
throw new SynapseException("Wrong combination of source and target type");
}
} else if (sourceType == 0 && targetType == 1) {
throw new SynapseException("Wrong combination of source and target type");
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ConfigurationFactoryAndSerializerFinder method loadConfigurationFatoriesAndSerializers.
private static void loadConfigurationFatoriesAndSerializers() {
for (Class c : configurationFactories) {
if (c != null) {
try {
ConfigurationFactory fac = (ConfigurationFactory) c.newInstance();
factoryMap.put(fac.getTagQName(), c);
serializerMap.put(fac.getTagQName(), fac.getSerializerClass());
} catch (Exception e) {
throw new SynapseException("Error instantiating " + c.getName(), e);
}
}
}
// now iterate through the available plugable mediator factories
registerExtensions();
initialized = true;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ConfigurationFactoryAndSerializerFinder method getConfiguration.
/**
* This method returns a Processor given an OMElement. This will be used
* recursively by the elements which contain processor elements themselves
* (e.g. rules)
*
* @param element
* @return Processor
*/
public SynapseConfiguration getConfiguration(OMElement element, Properties properties) {
String localName = element.getLocalName();
QName qName;
if (element.getNamespace() != null) {
qName = new QName(element.getNamespace().getNamespaceURI(), localName);
} else {
qName = new QName(localName);
}
if (log.isDebugEnabled()) {
log.debug("getConfiguration(" + qName + ")");
}
Class cls = factoryMap.get(qName);
if (cls == null) {
String msg = "Unknown Configuration type " + "referenced by configuration element : " + qName;
log.error(msg);
throw new SynapseException(msg);
}
try {
ConfigurationFactory cf = (ConfigurationFactory) cls.newInstance();
return cf.getConfiguration(element, properties);
} catch (InstantiationException e) {
String msg = "Error initializing configuration factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
} catch (IllegalAccessException e) {
String msg = "Error initializing configuration factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
}
}
Aggregations