use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ConfigurationFactoryAndSerializerFinder method serializeConfiguration.
/**
* This method will serialize the config using the supplied QName
* (looking up the right class to do it)
*
* @param synCfg
* @param qName
* @throws XMLStreamException
*/
public static OMElement serializeConfiguration(SynapseConfiguration synCfg, QName qName) {
Class cls = (Class) serializerMap.get(qName);
if (cls == null) {
String msg = "Unknown Configuration type " + "referenced by configuration element : " + qName;
log.error(msg);
throw new SynapseException(msg);
}
try {
ConfigurationSerializer cs = (ConfigurationSerializer) cls.newInstance();
return cs.serializeConfiguration(synCfg);
} 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);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class InvokeMediatorFactory method createSpecificMediator.
@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
invoker = new InvokeMediator();
processAuditStatus(invoker, elem);
OMAttribute targetTemplateAttr = elem.getAttribute(ATT_TARGET);
if (targetTemplateAttr != null) {
invoker.setTargetTemplate(targetTemplateAttr.getAttributeValue());
buildParameters(elem);
} else {
String msg = "EIP Invoke mediator should have a target template specified.";
log.error(msg);
throw new SynapseException(msg);
}
return invoker;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MediatorFactoryFinder method getMediator.
/**
* 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 XML representation of a mediator
* @param properties bag of properties to pass in any information to the factory
* @return Processor
*/
public Mediator getMediator(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("getMediator(" + qName + ")");
}
Class cls = factoryMap.get(qName);
if (cls == null && localName.indexOf('.') > -1) {
String newLocalName = localName.substring(0, localName.indexOf('.'));
qName = new QName(element.getNamespace().getNamespaceURI(), newLocalName);
if (log.isDebugEnabled()) {
log.debug("getMediator.2(" + qName + ")");
}
cls = factoryMap.get(qName);
}
if (cls == null) {
if (synapseLibraryMap != null && !synapseLibraryMap.isEmpty()) {
for (Map.Entry<String, Library> entry : synapseLibraryMap.entrySet()) {
if (entry.getValue().getLibArtifactDetails().containsKey(localName)) {
return getDynamicInvokeMediator(element, entry.getValue().getPackage());
}
}
}
if (!synapseImportMap.isEmpty()) {
for (Map.Entry<String, SynapseImport> entry : synapseImportMap.entrySet()) {
if (localName.startsWith(entry.getValue().getLibName())) {
return getDynamicInvokeMediator(element, entry.getValue().getLibPackage());
}
}
}
String msg = "Unknown mediator referenced by configuration element : " + qName;
log.error(msg);
throw new SynapseException(msg);
}
try {
MediatorFactory mf = (MediatorFactory) cls.newInstance();
return mf.createMediator(element, properties);
} catch (InstantiationException e) {
String msg = "Error initializing mediator factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
} catch (IllegalAccessException e) {
String msg = "Error initializing mediator factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class MediatorPropertyFactory method getMediatorProperties.
public static List<MediatorProperty> getMediatorProperties(OMElement elem) {
List<MediatorProperty> propertyList = new ArrayList<MediatorProperty>();
Iterator iter = elem.getChildrenWithName(MediatorProperty.PROPERTY_Q);
while (iter.hasNext()) {
OMElement propEle = (OMElement) iter.next();
OMAttribute attName = propEle.getAttribute(MediatorProperty.ATT_NAME_Q);
OMAttribute attValue = propEle.getAttribute(MediatorProperty.ATT_VALUE_Q);
OMAttribute attExpr = propEle.getAttribute(MediatorProperty.ATT_EXPR_Q);
OMAttribute attScope = propEle.getAttribute(MediatorProperty.ATT_SCOPE_Q);
MediatorProperty prop = new MediatorProperty();
if (attName == null || attName.getAttributeValue() == null || attName.getAttributeValue().trim().length() == 0) {
String msg = "Entry name is a required attribute for a Log property";
log.error(msg);
throw new SynapseException(msg);
} else {
prop.setName(attName.getAttributeValue());
}
// if a value is specified, use it, else look for an expression
if (attValue != null) {
if (attValue.getAttributeValue() == null || attValue.getAttributeValue().trim().length() == 0) {
String msg = "Entry attribute value (if specified) " + "is required for a Log property";
log.error(msg);
throw new SynapseException(msg);
} else {
prop.setValue(attValue.getAttributeValue());
}
} else if (attExpr != null) {
if (attExpr.getAttributeValue() == null || attExpr.getAttributeValue().trim().length() == 0) {
String msg = "Entry attribute expression (if specified) " + "is required for a mediator property";
log.error(msg);
throw new SynapseException(msg);
} else {
try {
prop.setExpression(SynapsePathFactory.getSynapsePath(propEle, MediatorProperty.ATT_EXPR_Q));
} catch (JaxenException e) {
String msg = "Invalid XPath expression : " + attExpr.getAttributeValue();
log.error(msg);
throw new SynapseException(msg, e);
}
}
} else {
String msg = "Entry attribute value OR expression must " + "be specified for a mediator property";
log.error(msg);
throw new SynapseException(msg);
}
if (attScope != null) {
String valueStr = attScope.getAttributeValue();
if (!XMLConfigConstants.SCOPE_AXIS2.equals(valueStr) && !XMLConfigConstants.SCOPE_TRANSPORT.equals(valueStr) && !XMLConfigConstants.SCOPE_DEFAULT.equals(valueStr) && !XMLConfigConstants.SCOPE_CLIENT.equals(valueStr)) {
String msg = "Only '" + XMLConfigConstants.SCOPE_AXIS2 + "' or '" + XMLConfigConstants.SCOPE_TRANSPORT + "' or '" + XMLConfigConstants.SCOPE_CLIENT + "' values are allowed for attribute scope for a property" + ", Unsupported scope " + valueStr;
log.error(msg);
throw new SynapseException(msg);
}
prop.setScope(valueStr);
}
propertyList.add(prop);
}
return propertyList;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class IterateMediator method mediate.
/**
* Splits the message by iterating over the results of the given XPath expression
*
* @param synCtx - MessageContext to be mediated
* @return boolean false if need to stop processing of the parent message
*/
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Iterate mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
try {
// get a copy of the message for the processing, if the continueParent is set to true
// this original message can go in further mediations and hence we should not change
// the original message context
SOAPEnvelope envelope = MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());
synCtx.setProperty(id != null ? EIPConstants.EIP_SHARED_DATA_HOLDER + "." + id : EIPConstants.EIP_SHARED_DATA_HOLDER, new SharedDataHolder());
// get the iteration elements and iterate through the list,
// this call will also detach all the iteration elements
List splitElements = EIPUtils.getDetachedMatchingElements(envelope, synCtx, expression);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " + splitElements.size() + " elements");
}
// if not preservePayload remove all the child elements
if (!preservePayload && envelope.getBody() != null) {
for (Iterator itr = envelope.getBody().getChildren(); itr.hasNext(); ) {
((OMNode) itr.next()).detach();
}
}
int msgCount = splitElements.size();
int msgNumber = 0;
// iterate through the list
for (Object o : splitElements) {
// for the moment iterator will look for an OMNode as the iteration element
if (!(o instanceof OMNode)) {
handleException("Error splitting message with XPath : " + expression + " - result not an OMNode", synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Submitting " + (msgNumber + 1) + " of " + msgCount + (target.isAsynchronous() ? " messages for processing in parallel" : " messages for processing in sequentially"));
}
MessageContext iteratedMsgCtx = getIteratedMessage(synCtx, msgNumber++, msgCount, envelope, (OMNode) o);
ContinuationStackManager.addReliantContinuationState(iteratedMsgCtx, 0, getMediatorPosition());
if (target.isAsynchronous()) {
target.mediate(iteratedMsgCtx);
} else {
try {
/*
* if Iteration is sequential we won't be able to execute correct fault
* handler as data are lost with clone message ending execution. So here we
* copy fault stack of clone message context to original message context
*/
target.mediate(iteratedMsgCtx);
} catch (SynapseException synEx) {
copyFaultyIteratedMessage(synCtx, iteratedMsgCtx);
throw synEx;
} catch (Exception e) {
copyFaultyIteratedMessage(synCtx, iteratedMsgCtx);
handleException("Exception occurred while executing sequential iteration " + "in the Iterator Mediator", e, synCtx);
}
}
}
} catch (JaxenException e) {
handleException("Error evaluating split XPath expression : " + expression, e, synCtx);
} catch (AxisFault af) {
handleException("Error creating an iterated copy of the message", af, synCtx);
} catch (SynapseException synEx) {
throw synEx;
} catch (Exception e) {
handleException("Exception occurred while executing the Iterate Mediator", e, synCtx);
}
// if the continuation of the parent message is stopped from here set the RESPONSE_WRITTEN
// property to SKIP to skip the blank http response
OperationContext opCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext();
if (!continueParent && opCtx != null) {
opCtx.setProperty(Constants.RESPONSE_WRITTEN, "SKIP");
}
synLog.traceOrDebug("End : Iterate mediator");
// whether to continue mediation on the original message
return continueParent;
}
Aggregations