Package org.apache.synapse

Examples of org.apache.synapse.Mediator


        log.debug("Class mediator <" + clazz.getName() + ">:: mediate()");
        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
        if (shouldTrace) {
            trace.trace("Start : Class mediator");
        }
        Mediator m = null;
        try {
            try {
                m = (Mediator) clazz.newInstance();
            } catch (Exception e) {
                String msg = "Error while creating an instance of the specified mediator class : " + clazz.getName();
                if (shouldTrace)
                    trace.trace(msg);
                log.error(msg, e);
                throw new SynapseException(msg, e);
            }

            setProperties(m, synCtx, shouldTrace);
            if (shouldTrace) {
                trace.trace("Executing an instance of the specified class : " + clazz.getName());
            }
            return m.mediate(synCtx);
        } finally {
            if (shouldTrace) {
                trace.trace("End : Class mediator");
            }
        }
View Full Code Here


    private static final OMElement MY_MEDIATOR_FOO_FUNC = TestUtils.createOMElement(
       "<x><![CDATA[ function foo(mc) { return true;} ]]></x>");

    public void testInlineScriptMediatorFactory() throws XMLStreamException {
        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(INLINE_MEDIATOR_CONFIG);
        assertTrue(mediator.mediate(null));
    }
View Full Code Here

        Map props = new HashMap();
        props.put("MyMediator", prop);
        MessageContext mc = TestUtils.getTestContext("<foo/>", props);

        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(REG_PROP_MEDIATOR_CONFIG);
        assertTrue(mediator.mediate(mc));
    }
View Full Code Here

        Map props = new HashMap();
        props.put("MyFooMediator", prop);
        MessageContext mc = TestUtils.getTestContext("<foo/>", props);

        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(REG_PROP_FOO_FUNC_MEDIATOR_CONFIG);
        assertTrue(mediator.mediate(mc));
    }
View Full Code Here

    public void addChildren(OMElement el, ListMediator m)
    {
        Iterator it = el.getChildElements();
        while (it.hasNext()) {
            OMElement child = (OMElement) it.next();
            Mediator med = MediatorFactoryFinder.getInstance().getMediator(child);
            if (med != null) {
                m.addChild(med);
            } else {
                String msg = "Unknown mediator : " + child.getLocalName();
                log.error(msg);
View Full Code Here

            new QName(Constants.SYNAPSE_NAMESPACE, "onError"));
        if (error != null) {
            Iterator it = error.getChildElements();
            while (it.hasNext()) {
                OMElement child = (OMElement) it.next();
                Mediator med = MediatorFactoryFinder.getInstance().getMediator(child);
                if (med != null) {
                    tryMediator.getErrorHandlerMediators().add(med);
                } else {
                    handleException("Unknown mediator : " + child.getLocalName());
                }
            }
        } else {
            handleException("A 'onError' element is required for a 'try' mediator");
        }

        // process finally mediators - if any
        OMElement fin = elem.getFirstChildWithName(
            new QName(Constants.SYNAPSE_NAMESPACE, "finally"));
        if (fin != null) {
            Iterator it = fin.getChildElements();
            while (it.hasNext()) {
                OMElement child = (OMElement) it.next();
                Mediator med = MediatorFactoryFinder.getInstance().getMediator(child);
                if (med != null) {
                    tryMediator.getFinallyMediators().add(med);
                } else {
                    handleException("Unknown mediator : " + child.getLocalName());
                }
View Full Code Here

    public void serializeChildren(OMElement parent, List list)
    {
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Mediator child = (Mediator) iter.next();
            MediatorSerializer medSer = MediatorSerializerFinder.getInstance().getSerializer(child);
            if (medSer != null) {
                medSer.serializeMediator(parent, child);
            } else {
                handleException("Unable to find a serializer for mediator : " + child.getType());
            }
        }
    }
View Full Code Here

        });*/

        // if the outSequence property is present use that for the message mediation
        // if not use the main mediator to mediate the outgoing message
        if (synCtx.getProperty(Constants.OUT_SEQUENCE) != null) {
            Mediator mediator = synCtx.getConfiguration().getNamedSequence(
                    (String)synCtx.getProperty(Constants.OUT_SEQUENCE));
            // check weather the sequence specified with the property outSequence is availabel
            if(mediator != null) {
                log.debug("Using the outSequence " + synCtx.getProperty(Constants.OUT_SEQUENCE)
                        + " for the out message mediation");
                mediator.mediate(synCtx);
            } else {
                log.error("Sequence named " + synCtx.getProperty(Constants.OUT_SEQUENCE)
                        + " doesn't exists in synapse");
            }
        } else {
View Full Code Here

                synCtx.setProperty(org.apache.synapse.Constants.OUT_SEQUENCE, targetOutSequence);
            }

            // if a named inSequence is specified, use it for message mediation
            if (targetInSequence != null) {
                Mediator mediator = synCtx.getConfiguration().getNamedSequence(targetInSequence);
                if (mediator == null) {
                    // what else can/should we do instead of just logging the message as an error?
                    log.error("The mediator named '" + targetInSequence
                            + "' is not defined. Dropping current message");
                } else {
                    log.debug("Using sequence named : " + targetInSequence
                            + " for message mediation");
                    mediator.mediate(synCtx);
                }

            // else default to the Synapse main mediator
            } else {
                log.debug("Using default 'main' mediator for message mediation");
View Full Code Here

     * @return as per standard semantics
     */
    public boolean mediate(MessageContext synCtx) {

        log.debug("Class mediator <" + clazz.getName() + ">:: mediate()");
        Mediator m = null;
        try {
            m = (Mediator) clazz.newInstance();

        } catch (Exception e) {
            String msg = "Error while creating an instance of the specified mediator class : " + clazz.getName();
            log.error(msg, e);
            throw new SynapseException(msg, e);
        }

        setProperties(m, synCtx);

        return m.mediate(synCtx);
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.Mediator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.