Search in sources :

Example 56 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class SequenceDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    CustomLogSetter.getInstance().setLogAppender(customLogContent);
    if (log.isDebugEnabled()) {
        log.debug("Sequence Deployment from file : " + fileName + " : Started");
    }
    try {
        MediatorFactoryFinder.getInstance().setSynapseLibraryMap(getSynapseConfiguration().getSynapseLibraries());
        Mediator m = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
        if (m instanceof SequenceMediator) {
            SequenceMediator seq = (SequenceMediator) m;
            seq.setArtifactContainerName(customLogContent);
            seq.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("Sequence named '" + seq.getName() + "' has been built from the file " + fileName);
            }
            seq.init(getSynapseEnvironment());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the sequence : " + seq.getName());
            }
            getSynapseConfiguration().addSequence(seq.getName(), seq);
            if (log.isDebugEnabled()) {
                log.debug("Sequence Deployment from file : " + fileName + " : Completed");
            }
            log.info("Sequence named '" + seq.getName() + "' has been deployed from file : " + fileName);
            return seq.getName();
        } else {
            handleSynapseArtifactDeploymentError("Sequence Deployment Failed. " + "The artifact described in the file " + fileName + " is not a Sequence");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Sequence Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 57 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class SynapseConfigUtils method setDefaultMainSequence.

/**
 * Return the main sequence if one is not defined. This implementation defaults to
 * a simple sequence with a <send/>
 *
 * @param config the configuration to be updated
 */
public static void setDefaultMainSequence(SynapseConfiguration config) {
    SequenceMediator main = new SequenceMediator();
    main.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
    main.addChild(new LogMediator());
    main.addChild(new DropMediator());
    config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, main);
    // set the aspect configuration
    AspectConfiguration configuration = new AspectConfiguration(main.getName());
    main.configure(configuration);
}
Also used : LogMediator(org.apache.synapse.mediators.builtin.LogMediator) DropMediator(org.apache.synapse.mediators.builtin.DropMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration)

Example 58 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class AggregateMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    AggregateMediator mediator = new AggregateMediator();
    processAuditStatus(mediator, elem);
    OMAttribute id = elem.getAttribute(ID_Q);
    if (id != null) {
        mediator.setId(id.getAttributeValue());
    }
    OMElement corelateOn = elem.getFirstChildWithName(CORELATE_ON_Q);
    if (corelateOn != null) {
        OMAttribute corelateExpr = corelateOn.getAttribute(EXPRESSION_Q);
        if (corelateExpr != null) {
            try {
                mediator.setCorrelateExpression(SynapseXPathFactory.getSynapseXPath(corelateOn, EXPRESSION_Q));
            } catch (JaxenException e) {
                handleException("Unable to load the corelate XPATH expression", e);
            }
        }
    }
    OMElement completeCond = elem.getFirstChildWithName(COMPLETE_CONDITION_Q);
    if (completeCond != null) {
        OMAttribute completeTimeout = completeCond.getAttribute(TIMEOUT_Q);
        if (completeTimeout != null) {
            mediator.setCompletionTimeoutMillis(Long.parseLong(completeTimeout.getAttributeValue()) * 1000);
        }
        OMElement messageCount = completeCond.getFirstChildWithName(MESSAGE_COUNT_Q);
        if (messageCount != null) {
            OMAttribute min = messageCount.getAttribute(MIN_Q);
            if (min != null) {
                mediator.setMinMessagesToComplete(new ValueFactory().createValue("min", messageCount));
            }
            OMAttribute max = messageCount.getAttribute(MAX_Q);
            if (max != null) {
                mediator.setMaxMessagesToComplete(new ValueFactory().createValue("max", messageCount));
            }
        }
    }
    OMElement onComplete = elem.getFirstChildWithName(ON_COMPLETE_Q);
    if (onComplete != null) {
        OMAttribute aggregateExpr = onComplete.getAttribute(EXPRESSION_Q);
        if (aggregateExpr != null) {
            try {
                mediator.setAggregationExpression(SynapseXPathFactory.getSynapseXPath(onComplete, EXPRESSION_Q));
            } catch (JaxenException e) {
                handleException("Unable to load the aggregating XPATH", e);
            }
        }
        OMAttribute enclosingElementPropertyName = onComplete.getAttribute(ENCLOSING_ELEMENT_PROPERTY);
        if (enclosingElementPropertyName != null) {
            mediator.setEnclosingElementPropertyName(enclosingElementPropertyName.getAttributeValue());
        }
        OMAttribute onCompleteSequence = onComplete.getAttribute(SEQUENCE_Q);
        if (onCompleteSequence != null) {
            mediator.setOnCompleteSequenceRef(onCompleteSequence.getAttributeValue());
        } else if (onComplete.getFirstElement() != null) {
            mediator.setOnCompleteSequence((new SequenceMediatorFactory()).createAnonymousSequence(onComplete, properties));
        } else {
            SequenceMediator sequence = new SequenceMediator();
            sequence.addChild(new DropMediator());
            mediator.setOnCompleteSequence(sequence);
        }
    }
    addAllCommentChildrenToList(elem, mediator.getCommentsList());
    return mediator;
}
Also used : AggregateMediator(org.apache.synapse.mediators.eip.aggregator.AggregateMediator) JaxenException(org.jaxen.JaxenException) DropMediator(org.apache.synapse.mediators.builtin.DropMediator) OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 59 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class Target method mediate.

/**
 * process the message through this target (may be to mediate
 * using the target sequence, send message to the target endpoint or both)
 *
 * @param synCtx - MessageContext to be mediated
 * @return <code>false</code> if the target is mediated as synchronous and the sequence
 * mediation returns <code>false</code>, <code>true</code> otherwise
 */
public boolean mediate(MessageContext synCtx) {
    boolean returnValue = true;
    if (log.isDebugEnabled()) {
        log.debug("Target mediation : START");
    }
    if (soapAction != null) {
        if (log.isDebugEnabled()) {
            log.debug("Setting the SOAPAction as : " + soapAction);
        }
        synCtx.setSoapAction(soapAction);
    }
    if (toAddress != null) {
        if (log.isDebugEnabled()) {
            log.debug("Setting the To header as : " + toAddress);
        }
        if (synCtx.getTo() != null) {
            synCtx.getTo().setAddress(toAddress);
        } else {
            synCtx.setTo(new EndpointReference(toAddress));
        }
    }
    // through a sequence and then again with an endpoint
    if (sequence != null) {
        if (asynchronous) {
            if (log.isDebugEnabled()) {
                log.debug("Asynchronously mediating using the in-lined anonymous sequence");
            }
            synCtx.getEnvironment().injectAsync(synCtx, sequence);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Synchronously mediating using the in-lined anonymous sequence");
            }
            returnValue = sequence.mediate(synCtx);
        }
    } else if (sequenceRef != null) {
        SequenceMediator refSequence = (SequenceMediator) synCtx.getSequence(sequenceRef);
        // if target directs the message to a defined sequence, ReliantContState added by
        // Clone/Iterate mediator is no longer needed as defined sequence can be directly
        // referred from a SeqContinuationState
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        if (refSequence != null) {
            if (asynchronous) {
                if (log.isDebugEnabled()) {
                    log.debug("Asynchronously mediating using the sequence " + "named : " + sequenceRef);
                }
                synCtx.getEnvironment().injectAsync(synCtx, refSequence);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Synchronously mediating using the sequence " + "named : " + sequenceRef);
                }
                try {
                    returnValue = refSequence.mediate(synCtx);
                } catch (SynapseException syne) {
                    if (!synCtx.getFaultStack().isEmpty()) {
                        log.warn("Executing fault handler due to exception encountered");
                        ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
                    } else {
                        log.warn("Exception encountered but no fault handler found - message dropped");
                    }
                } catch (Exception e) {
                    String msg = "Unexpected error occurred executing the Target";
                    log.error(msg, e);
                    if (synCtx.getServiceLog() != null) {
                        synCtx.getServiceLog().error(msg, e);
                    }
                    if (!synCtx.getFaultStack().isEmpty()) {
                        log.warn("Executing fault handler due to exception encountered");
                        ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, e);
                    } else {
                        log.warn("Exception encountered but no fault handler found - message dropped");
                    }
                }
            }
        } else {
            handleException("Couldn't find the sequence named : " + sequenceRef);
        }
    } else if (endpoint != null) {
        if (log.isDebugEnabled()) {
            log.debug("Sending using the in-lined anonymous endpoint");
        }
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        endpoint.send(synCtx);
    } else if (endpointRef != null) {
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
        if (epr != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending using the endpoint named : " + endpointRef);
            }
            if (!epr.isInitialized()) {
                // initializing registry
                epr.init(synCtx.getEnvironment());
            // base endpoint configuration
            }
            epr.send(synCtx);
        // epr.destroy();
        } else {
            handleException("Couldn't find the endpoint named : " + endpointRef);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Target mediation : END");
    }
    return returnValue;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) FaultHandler(org.apache.synapse.FaultHandler) SynapseException(org.apache.synapse.SynapseException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 60 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class ProxyServiceTest method testStart.

/**
 * Tests starting a proxy service with correct axis configuration provided.
 *
 * @throws Exception if an exception occurs while configuring the axis configuration
 */
public void testStart() throws Exception {
    String proxyServiceName = "TestStartProxy";
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
    axisCfg.addParameter(SynapseConstants.SYNAPSE_ENV, synEnv);
    synCfg.setAxisConfiguration(axisCfg);
    ProxyService proxyService = new ProxyService(proxyServiceName);
    AxisService axisServiceForActivation = new AxisService();
    axisServiceForActivation.setName(proxyServiceName);
    axisCfg.addToAllServicesMap(axisServiceForActivation);
    proxyService.setTargetInLineInSequence(new SequenceMediator());
    proxyService.setTargetInLineOutSequence(new SequenceMediator());
    proxyService.setTargetInLineFaultSequence(new SequenceMediator());
    proxyService.start(synCfg);
    Assert.assertTrue("Underlying Axis service is not activated", axisServiceForActivation.isActive());
    Assert.assertTrue("Proxy service is not running", proxyService.isRunning());
    proxyService.stop(synCfg);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) AxisService(org.apache.axis2.description.AxisService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)70 TestMediator (org.apache.synapse.mediators.TestMediator)18 OMElement (org.apache.axiom.om.OMElement)12 ProxyService (org.apache.synapse.core.axis2.ProxyService)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 Mediator (org.apache.synapse.Mediator)11 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)11 MessageContext (org.apache.synapse.MessageContext)9 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)7 OMAttribute (org.apache.axiom.om.OMAttribute)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)6 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)6 File (java.io.File)4 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)4 SynapseException (org.apache.synapse.SynapseException)4 SynapseLog (org.apache.synapse.SynapseLog)4 QName (javax.xml.namespace.QName)3 OMNode (org.apache.axiom.om.OMNode)3