Search in sources :

Example 6 with Target

use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.

the class CloneMediatorSerializer method serializeSpecificMediator.

/**
 * This method will implement the serializeMediator method of the MediatorSerializer interface
 * and implements the serialization of CloneMediator to its configuration
 *
 * @param m Mediator of the type CloneMediator which is subjected to the serialization
 * @return OMElement serialized in to xml from the given parameters
 */
public OMElement serializeSpecificMediator(Mediator m) {
    OMElement cloneElem = fac.createOMElement("clone", synNS);
    saveTracingState(cloneElem, m);
    CloneMediator clone = (CloneMediator) m;
    if (clone.isContinueParent()) {
        cloneElem.addAttribute("continueParent", Boolean.toString(true), nullNS);
    }
    if (clone.getId() != null) {
        cloneElem.addAttribute("id", clone.getId(), nullNS);
    }
    if (clone.isSequential()) {
        cloneElem.addAttribute("sequential", "true", nullNS);
    }
    for (Object o : clone.getTargets()) {
        if (o instanceof Target) {
            cloneElem.addChild(TargetSerializer.serializeTarget((Target) o));
        }
    }
    return cloneElem;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) OMElement(org.apache.axiom.om.OMElement) CloneMediator(org.apache.synapse.mediators.eip.splitter.CloneMediator)

Example 7 with Target

use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.

the class ConditionalRouterMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    ConditionalRouterMediator conditionalRouterMediator = new ConditionalRouterMediator();
    processAuditStatus(conditionalRouterMediator, elem);
    if (elem.getAttribute(CONTINUE_AFTER_ATTR) != null) {
        if (JavaUtils.isTrueExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
            conditionalRouterMediator.setContinueAfter(true);
        } else if (JavaUtils.isFalseExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
            conditionalRouterMediator.setContinueAfter(false);
        } else {
            handleException("continueAfter attribute value of the conditionalRouter must " + "be either 'true' or 'false', the value found is : " + elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim());
        }
    }
    Iterator itr = elem.getChildrenWithName(ROUTE_Q);
    while (itr.hasNext()) {
        OMElement routeElem = (OMElement) itr.next();
        ConditionalRoute conditionalRoute = new ConditionalRoute();
        if (routeElem.getAttribute(BREAK_ROUTE_ATTR) != null) {
            if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
                conditionalRoute.setBreakRoute(true);
            } else if (JavaUtils.isFalseExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
                conditionalRoute.setBreakRoute(false);
            } else {
                handleException("breakRoute attribute value of the conditionalRoute element must " + "be either 'true' or 'false', the value found is : " + routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim());
            }
        }
        OMElement conditionElem = routeElem.getFirstChildWithName(CONDITION_Q);
        if (conditionElem == null) {
            handleException("Couldn't find the condition of the conditional router");
            return null;
        }
        try {
            Evaluator evaluator = EvaluatorFactoryFinder.getInstance().getEvaluator(conditionElem.getFirstElement());
            conditionalRoute.setEvaluator(evaluator);
        } catch (EvaluatorException ee) {
            handleException("Couldn't build the condition of the conditional router", ee);
        }
        OMElement targetElem = routeElem.getFirstChildWithName(TARGET_Q);
        Target target = TargetFactory.createTarget(targetElem, properties);
        if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(ASYNCHRONOUS_ATTR))) {
            target.setAsynchronous(true);
        } else {
            target.setAsynchronous(false);
        }
        conditionalRoute.setTarget(target);
        conditionalRouterMediator.addRoute(conditionalRoute);
    }
    return conditionalRouterMediator;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) ConditionalRoute(org.apache.synapse.mediators.filters.router.ConditionalRoute) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator) ConditionalRouterMediator(org.apache.synapse.mediators.filters.router.ConditionalRouterMediator)

Example 8 with Target

use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.

the class IterateMediatorFactory method createSpecificMediator.

/**
 * This method will create the IterateMediator by parsing the given xml configuration
 *
 * @param elem OMElement describing the configuration of the IterateMediaotr
 * @param properties properties passed
 * @return IterateMediator created from the given configuration
 */
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    IterateMediator mediator = new IterateMediator();
    processAuditStatus(mediator, elem);
    OMAttribute id = elem.getAttribute(ID_Q);
    if (id != null) {
        mediator.setId(id.getAttributeValue());
    }
    OMAttribute continueParent = elem.getAttribute(ATT_CONTPAR);
    if (continueParent != null) {
        mediator.setContinueParent(Boolean.valueOf(continueParent.getAttributeValue()));
    }
    OMAttribute preservePayload = elem.getAttribute(ATT_PREPLD);
    if (preservePayload != null) {
        mediator.setPreservePayload(Boolean.valueOf(preservePayload.getAttributeValue()));
    }
    OMAttribute expression = elem.getAttribute(ATT_EXPRN);
    if (expression != null) {
        try {
            mediator.setExpression(SynapseXPathFactory.getSynapseXPath(elem, ATT_EXPRN));
        } catch (JaxenException e) {
            handleException("Unable to build the IterateMediator. " + "Invalid XPATH " + expression.getAttributeValue(), e);
        }
    } else {
        handleException("XPATH expression is required " + "for an IterateMediator under the \"expression\" attribute");
    }
    OMAttribute attachPath = elem.getAttribute(ATT_ATTACHPATH);
    String attachPathValue = ".";
    if (attachPath != null && !mediator.isPreservePayload()) {
        handleException("Wrong configuration for the iterate mediator :: if the iterator " + "should not preserve payload, then attachPath can not be present");
    } else if (attachPath != null) {
        attachPathValue = attachPath.getAttributeValue();
    }
    try {
        SynapseXPath xp = new SynapseXPath(attachPathValue);
        OMElementUtils.addNameSpaces(xp, elem, log);
        mediator.setAttachPath(xp);
    } catch (JaxenException e) {
        handleException("Unable to build the IterateMediator. Invalid XPATH " + attachPathValue, e);
    }
    boolean asynchronous = true;
    OMAttribute asynchronousAttr = elem.getAttribute(ATT_SEQUENCIAL);
    if (asynchronousAttr != null && asynchronousAttr.getAttributeValue().equals("true")) {
        asynchronous = false;
    }
    OMElement targetElement = elem.getFirstChildWithName(TARGET_Q);
    if (targetElement != null) {
        Target target = TargetFactory.createTarget(targetElement, properties);
        if (target != null) {
            target.setAsynchronous(asynchronous);
            mediator.setTarget(target);
        }
    } else {
        handleException("Target for an iterate mediator is required :: missing target");
    }
    addAllCommentChildrenToList(elem, mediator.getCommentsList());
    return mediator;
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Target(org.apache.synapse.mediators.eip.Target) JaxenException(org.jaxen.JaxenException) OMElement(org.apache.axiom.om.OMElement) IterateMediator(org.apache.synapse.mediators.eip.splitter.IterateMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 9 with Target

use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.

the class CloneMediator method destroy.

public void destroy() {
    for (Target target : targets) {
        ManagedLifecycle seq = target.getSequence();
        if (seq != null) {
            seq.destroy();
        } else if (target.getSequenceRef() != null) {
            SequenceMediator targetSequence = (SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence(target.getSequenceRef());
            if (targetSequence == null || targetSequence.isDynamic()) {
                synapseEnv.removeUnavailableArtifactRef(target.getSequenceRef());
            }
        }
        Endpoint endpoint = target.getEndpoint();
        if (endpoint != null) {
            endpoint.destroy();
        }
    }
}
Also used : Target(org.apache.synapse.mediators.eip.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 10 with Target

use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.

the class CloneMediator method mediate.

/**
 * This will implement the mediate method of the Mediator interface and will provide the
 * functionality of cloning message into the specified targets and mediation
 *
 * @param synCtx - MessageContext which is subjected to the cloning
 * @return boolean true if this needs to be further mediated (continueParent=true)
 */
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 : Clone mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    synCtx.setProperty(id != null ? EIPConstants.EIP_SHARED_DATA_HOLDER + "." + id : EIPConstants.EIP_SHARED_DATA_HOLDER, new SharedDataHolder());
    // get the targets list, clone the message for the number of targets and then
    // mediate the cloned messages using the targets
    Iterator<Target> iter = targets.iterator();
    int i = 0;
    while (iter.hasNext()) {
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Submitting " + (i + 1) + " of " + targets.size() + " messages for " + (isSequential() ? "sequential processing" : "parallel processing"));
        }
        MessageContext clonedMsgCtx = getClonedMessageContext(synCtx, i++, targets.size());
        ContinuationStackManager.addReliantContinuationState(clonedMsgCtx, i - 1, getMediatorPosition());
        iter.next().mediate(clonedMsgCtx);
    }
    // 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");
    }
    // finalize tracing and debugging
    synLog.traceOrDebug("End : Clone mediator");
    // mediation of the message which is subjected for clonning (parent message)
    return continueParent;
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) Target(org.apache.synapse.mediators.eip.Target) SynapseLog(org.apache.synapse.SynapseLog) SharedDataHolder(org.apache.synapse.mediators.eip.SharedDataHolder) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Endpoint(org.apache.synapse.endpoints.Endpoint)

Aggregations

Target (org.apache.synapse.mediators.eip.Target)10 OMElement (org.apache.axiom.om.OMElement)5 OMAttribute (org.apache.axiom.om.OMAttribute)4 Endpoint (org.apache.synapse.endpoints.Endpoint)3 Iterator (java.util.Iterator)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)2 CloneMediator (org.apache.synapse.mediators.eip.splitter.CloneMediator)2 QName (javax.xml.namespace.QName)1 OperationContext (org.apache.axis2.context.OperationContext)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseLog (org.apache.synapse.SynapseLog)1 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)1 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)1 EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 SharedDataHolder (org.apache.synapse.mediators.eip.SharedDataHolder)1 MessageQueue (org.apache.synapse.mediators.eip.sample.MessageQueue)1 SamplingThrottleMediator (org.apache.synapse.mediators.eip.sample.SamplingThrottleMediator)1 IterateMediator (org.apache.synapse.mediators.eip.splitter.IterateMediator)1