Search in sources :

Example 81 with SynapseException

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);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException)

Example 82 with SynapseException

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;
}
Also used : SynapseException(org.apache.synapse.SynapseException) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 83 with SynapseException

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);
    }
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) EventPublisherMediatorFactory(org.apache.synapse.config.xml.eventing.EventPublisherMediatorFactory) Library(org.apache.synapse.libraries.model.Library) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with SynapseException

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;
}
Also used : MediatorProperty(org.apache.synapse.mediators.MediatorProperty) SynapseException(org.apache.synapse.SynapseException) JaxenException(org.jaxen.JaxenException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 85 with SynapseException

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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OperationContext(org.apache.axis2.context.OperationContext) SynapseException(org.apache.synapse.SynapseException) SharedDataHolder(org.apache.synapse.mediators.eip.SharedDataHolder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Endpoint(org.apache.synapse.endpoints.Endpoint) JaxenException(org.jaxen.JaxenException) SynapseException(org.apache.synapse.SynapseException) OMNode(org.apache.axiom.om.OMNode) SynapseLog(org.apache.synapse.SynapseLog) JaxenException(org.jaxen.JaxenException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7