Package org.apache.synapse.mediators

Examples of org.apache.synapse.mediators.MediatorProperty


    public void addAllProperties(List list) {
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Object o = iter.next();
            if (o instanceof MediatorProperty) {
                MediatorProperty prop = (MediatorProperty) o;
                setProperty(prop.getName(), prop.getValue());
            } else {
                handleException("Attempt to set invalid property type. " +
                    "Expected MediatorProperty type got " + o.getClass().getName());
            }
        }
View Full Code Here


    public void serializeMediatorProperties(OMElement parent, Collection props) {

        Iterator iter = props.iterator();
        while (iter.hasNext()) {
            MediatorProperty mp = (MediatorProperty) iter.next();
            OMElement prop = fac.createOMElement("property", synNS, parent);
            if (mp.getName() != null) {
                prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
            } else {
                handleException("Mediator property name missing");
            }

            if (mp.getValue() != null) {
                prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));

            } else if (mp.getExpression() != null) {
                prop.addAttribute(fac.createOMAttribute("expression", nullNS,
                    mp.getExpression().toString()));
                serializeNamespaces(prop, mp.getExpression());

            } else {
                handleException("Mediator property must have a literal value or be an expression");
            }
        }
View Full Code Here

    private void setProperties(Mediator m, MessageContext synCtx, boolean shouldTrace) {

        Iterator iter = properties.iterator();
        while (iter.hasNext()) {

            MediatorProperty mProp = (MediatorProperty) iter.next();

            String mName = "set" + Character.toUpperCase(mProp.getName().charAt(0)) + mProp.getName().substring(1);
            String value = (mProp.getValue() != null ?
                mProp.getValue() :
                Axis2MessageContext.getStringValue(mProp.getExpression(), synCtx));

            try {
                Method method = m.getClass().getMethod(mName, new Class[] {String.class});
                log.debug("Setting property :: invoking method " + mName + "(" + value + ")");
                if (shouldTrace) {
                    trace.trace("Setting property :: invoking method " + mName + "(" + value + ")");
                }
                method.invoke(m, new Object[] { value });

            } catch (Exception e) {
                String msg = "Error setting property : " + mProp.getName() + " as a String property into class" +
                    " mediator : " + m.getClass() + " : " + e.getMessage();
                log.error(msg);
                if (shouldTrace) {
                    trace.trace(msg);
                }
View Full Code Here

    public void addAllProperties(List list) {
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Object o = iter.next();
            if (o instanceof MediatorProperty) {
                MediatorProperty prop = (MediatorProperty) o;
                setProperty(prop.getName(), prop.getValue());
            } else {
                handleException("Attempt to set invalid property type. " +
                    "Expected MediatorProperty type got " + o.getClass().getName());
            }
        }
View Full Code Here

                new AXIOMXPath("synapse:get-property('name')"), synCtx)));
    }

    public void testMediatorPropertiesLiteral() throws Exception {

        MediatorProperty medProp = new MediatorProperty();
        medProp.setName("name");
        medProp.setValue("value");
        assertTrue("value".equals(medProp.getValue()));
    }
View Full Code Here

        MessageContext synCtx = TestUtils.getTestContext("<empty/>");
        propMediator.mediate(synCtx);

        // read property through a mediator property
        MediatorProperty medProp = new MediatorProperty();
        medProp.setExpression(new AXIOMXPath("synapse:get-property('name')"));

        assertTrue(
            "value".equals(medProp.getEvaluatedExpression(synCtx)));
    }
View Full Code Here

    private void setCustomProperties(StringBuffer sb, MessageContext synCtx) {
        if (properties != null && !properties.isEmpty()) {
            Iterator iter = properties.iterator();
            while (iter.hasNext()) {
                MediatorProperty prop = (MediatorProperty) iter.next();
                sb.append(separator + prop.getName() + " = " +
                    (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synCtx)));
            }
        }
    }
View Full Code Here

    public void serializeMediatorProperties(OMElement parent, Collection props) {

        Iterator iter = props.iterator();
        while (iter.hasNext()) {
            MediatorProperty mp = (MediatorProperty) iter.next();
            OMElement prop = fac.createOMElement("property", synNS, parent);
            if (mp.getName() != null) {
                prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
            } else {
                handleException("Mediator property name missing");
            }

            if (mp.getValue() != null) {
                prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));

            } else if (mp.getExpression() != null) {
                prop.addAttribute(fac.createOMAttribute("expression", nullNS,
                    mp.getExpression().toString()));
                super.serializeNamespaces(prop, mp.getExpression());

            } else {
                handleException("Mediator property must have a literal value or be an expression");
            }
        }
View Full Code Here

    private void setProperties(Mediator m, MessageContext synCtx) {

        Iterator iter = properties.iterator();
        while (iter.hasNext()) {

            MediatorProperty mProp = (MediatorProperty) iter.next();

            String mName = "set" + Character.toUpperCase(mProp.getName().charAt(0)) + mProp.getName().substring(1);
            String value = (mProp.getValue() != null ?
                mProp.getValue() :
                Axis2MessageContext.getStringValue(mProp.getExpression(), synCtx));

            try {
                Method method = m.getClass().getMethod(mName, new Class[] {String.class});
                log.debug("Setting property :: invoking method " + mName + "(" + value + ")");
                method.invoke(m, new Object[] { value });

            } catch (Exception e) {
                String msg = "Error setting property : " + mProp.getName() + " as a String property into class" +
                    " mediator : " + m.getClass() + " : " + e.getMessage();
                log.error(msg);
                throw new SynapseException(msg, e);
            }
        }
View Full Code Here

            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);

            MediatorProperty prop = new MediatorProperty();

            if (attName == null || attName.getAttributeValue() == null ||
                attName.getAttributeValue().trim().length() == 0) {
                String msg = "Property 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 = "Property 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 = "Property attribute expression (if specified) is required for a mediator property";
                    log.error(msg);
                    throw new SynapseException(msg);

                } else {
                    try {
                        AXIOMXPath xp = new AXIOMXPath(attExpr.getAttributeValue());
                        OMElementUtils.addNameSpaces(xp, propEle, log);
                        prop.setExpression(xp);

                    } catch (JaxenException e) {
                        String msg = "Invalid XPapth expression : " + attExpr.getAttributeValue();
                        log.error(msg);
                        throw new SynapseException(msg, e);
View Full Code Here

TOP

Related Classes of org.apache.synapse.mediators.MediatorProperty

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.