Package org.apache.synapse.mediators.builtin

Examples of org.apache.synapse.mediators.builtin.PropertyMediator


        if (!(m instanceof PropertyMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }

        PropertyMediator mediator = (PropertyMediator) m;
        OMElement property = fac.createOMElement("property", synNS);
        saveTracingState(property, mediator);

        if (mediator.getName() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "name", nullNS, mediator.getName()));
        } else {
            handleException("Invalid property mediator. Name is required");
        }

        if (mediator.getValue() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "value", nullNS, mediator.getValue().toString()));
        } else if (mediator.getValueElement() != null) {
            property.addChild(mediator.getValueElement());
        } else if (mediator.getExpression() != null) {
            SynapseXPathSerializer.serializeXPath(mediator.getExpression(),
                    property, "expression");
        } else if (mediator.getAction() == PropertyMediator.ACTION_SET) {
            handleException("Invalid property mediator. Value or expression is required if " +
                    "action is SET");
        }

        if (mediator.getScope() != null) {
            // if we have already built a mediator with scope, scope should be valid, now save it
            property.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.getAction() == PropertyMediator.ACTION_REMOVE) {
            property.addAttribute(fac.createOMAttribute(
                    "action", nullNS, "remove"));
        } else if (mediator.getType() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "type" , nullNS, mediator.getType()));
        }

        if (mediator.getPattern() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "pattern", nullNS, mediator.getPattern().toString()));
            if (mediator.getGroup() >= 0) {
                property.addAttribute(fac.createOMAttribute(
                        "group", nullNS, Integer.toString(mediator.getGroup())));
            }
        }

        return property;
    }
View Full Code Here


    private static final QName ATT_PATTERN = new QName("pattern");
    private static final QName ATT_GROUP = new QName("group");

    protected Mediator createSpecificMediator(OMElement elem, Properties properties) {

        PropertyMediator propMediator = new PropertyMediator();
        OMAttribute name = elem.getAttribute(ATT_NAME);
        OMAttribute value = elem.getAttribute(ATT_VALUE);
        OMAttribute expression = elem.getAttribute(ATT_EXPRN);
        OMAttribute scope = elem.getAttribute(ATT_SCOPE);
        OMAttribute action = elem.getAttribute(ATT_ACTION);
        OMAttribute type = elem.getAttribute(ATT_TYPE);
        OMAttribute pattern = elem.getAttribute(ATT_PATTERN);
        OMAttribute group = elem.getAttribute(ATT_GROUP);

        OMElement valueElement = elem.getFirstElement();

        if (name == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else if ((value == null && valueElement == null && expression == null) &&
                !(action != null && "remove".equals(action.getAttributeValue()))) {
            String msg = "Either a child element or one of 'value', 'expression' attributes is " +
                    "required for a property mediator when action is SET";
            log.error(msg);
            throw new SynapseException(msg);
        }
       
        propMediator.setName(name.getAttributeValue());
        String dataType = null;
        if (type != null) {
            dataType = type.getAttributeValue();
        }

        if (value != null) {
            propMediator.setValue(value.getAttributeValue(), dataType);
        } else if (valueElement != null) {
            propMediator.setValueElement(valueElement);
        } else if (expression != null) {
            try {
                propMediator.setExpression(SynapseXPathFactory.getSynapseXPath(elem, ATT_EXPRN),
                        dataType);
            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " +
                        expression.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
            }
        }

        if (pattern != null) {
            propMediator.setPattern(Pattern.compile(pattern.getAttributeValue()));
            if (group != null) {
                int groupValue = Integer.parseInt(group.getAttributeValue());
                if (groupValue >= 0) {
                    propMediator.setGroup(groupValue);
                } else {                   
                    String msg = "group can have a positive value only";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        } else if (group != null) {
            String msg = "group is only allowed when a pattern is specified";
            log.error(msg);
            throw new SynapseException(msg);
        }

        // The action attribute is optional, if provided and equals to 'remove' the
        // property mediator will act as a property remove mediator
        if (action != null && "remove".equals(action.getAttributeValue())) {
            propMediator.setAction(PropertyMediator.ACTION_REMOVE);
        }
       
        if (scope != null) {
            String valueStr = scope.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 mediator"
                        + ", Unsupported scope " + valueStr;
                log.error(msg);
                throw new SynapseException(msg);
            }
            propMediator.setScope(valueStr);
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(propMediator, elem);
View Full Code Here

        if (!(m instanceof PropertyMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }

        PropertyMediator mediator = (PropertyMediator) m;
        OMElement property = fac.createOMElement("set-property", synNS);
        finalizeSerialization(property,mediator);

        if (mediator.getName() != null) {
            property.addAttribute(fac.createOMAttribute(
                "name", nullNS, mediator.getName()));
        } else {
            handleException("Invalid property mediator. Name is required");
        }

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

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

        } else {
            handleException("Invalid property mediator. Value or expression is required");
        }
       
        if (mediator.getScope() != null) {
            // if we have already built a mediator with scope, scope should be valid, now save it
            property.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (parent != null) {
            parent.addChild(property);
        }
View Full Code Here

    private static final QName PROP_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");

    public Mediator createMediator(OMElement elem) {

        PropertyMediator propMediator = new PropertyMediator();
        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
        OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
        OMAttribute scope = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "scope"));

        if (name == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else if (value == null && expression == null) {
            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        }

        propMediator.setName(name.getAttributeValue());
        if (value != null) {
            propMediator.setValue(value.getAttributeValue());
        } else {
            try {
                AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
                OMElementUtils.addNameSpaces(xp, elem, log);
                propMediator.setExpression(xp);

            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
            }
        }

        if (scope != null) {
          if (!Constants.SCOPE_CORRELATE.equals(scope.getAttributeValue()) &&
                    !Constants.SCOPE_AXIS2.equals(scope.getAttributeValue())) {
            String msg = "Only '" + Constants.SCOPE_CORRELATE + "' or '" + Constants.SCOPE_AXIS2
                    + "' values are allowed for attribute scope for a property mediator"
                        + ", Unsupported scope " + scope.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
          }
            propMediator.setScope(scope.getAttributeValue());
        }
        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        initMediator(propMediator,elem);
View Full Code Here

        if (!(m instanceof PropertyMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }

        PropertyMediator mediator = (PropertyMediator) m;
        OMElement property = fac.createOMElement("set-property", synNS);
        if (mediator.getName() != null) {
            property.addAttribute(fac.createOMAttribute(
                "name", nullNS, mediator.getName()));
        } else {
            handleException("Invalid property mediator. Name is required");
        }

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

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

        } else {
            handleException("Invalid property mediator. Value or expression is required");
        }
View Full Code Here

    private static final QName PROP_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");

    public Mediator createMediator(OMElement elem) {

        PropertyMediator propMediator = new PropertyMediator();
        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
        OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));

        if (name == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else if (value == null && expression == null) {
            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        }

        propMediator.setName(name.getAttributeValue());
        if (value != null) {
            propMediator.setValue(value.getAttributeValue());
        } else {
            try {
                AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
                OMElementUtils.addNameSpaces(xp, elem, log);
                propMediator.setExpression(xp);

            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
View Full Code Here

    private static final QName ATT_PATTERN = new QName("pattern");
    private static final QName ATT_GROUP = new QName("group");

    public Mediator createSpecificMediator(OMElement elem, Properties properties) {

        PropertyMediator propMediator = new PropertyMediator();
        OMAttribute name = elem.getAttribute(ATT_NAME);
        OMAttribute value = elem.getAttribute(ATT_VALUE);
        OMAttribute expression = elem.getAttribute(ATT_EXPRN);
        OMAttribute scope = elem.getAttribute(ATT_SCOPE);
        OMAttribute action = elem.getAttribute(ATT_ACTION);
        OMAttribute type = elem.getAttribute(ATT_TYPE);
        OMAttribute pattern = elem.getAttribute(ATT_PATTERN);
        OMAttribute group = elem.getAttribute(ATT_GROUP);

        OMElement valueElement = elem.getFirstElement();

        if (name == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else if ((value == null && valueElement == null && expression == null) &&
                !(action != null && "remove".equals(action.getAttributeValue()))) {
            String msg = "Either a child element or one of 'value', 'expression' attributes is " +
                    "required for a property mediator when action is SET";
            log.error(msg);
            throw new SynapseException(msg);
        }
       
        propMediator.setName(name.getAttributeValue());
        String dataType = null;
        if (type != null) {
            dataType = type.getAttributeValue();
        }

        if (value != null) {
            propMediator.setValue(value.getAttributeValue(), dataType);
        } else if (valueElement != null) {
            propMediator.setValueElement(valueElement);
        } else if (expression != null) {
            try {
                propMediator.setExpression(SynapseXPathFactory.getSynapseXPath(elem, ATT_EXPRN),
                        dataType);
            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " +
                        expression.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
            }
        }

        if (pattern != null) {
            propMediator.setPattern(Pattern.compile(pattern.getAttributeValue()));
            if (group != null) {
                int groupValue = Integer.parseInt(group.getAttributeValue());
                if (groupValue >= 0) {
                    propMediator.setGroup(groupValue);
                } else {                   
                    String msg = "group can have a positive value only";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        } else if (group != null) {
            String msg = "group is only allowed when a pattern is specified";
            log.error(msg);
            throw new SynapseException(msg);
        }

        // The action attribute is optional, if provided and equals to 'remove' the
        // property mediator will act as a property remove mediator
        if (action != null && "remove".equals(action.getAttributeValue())) {
            propMediator.setAction(PropertyMediator.ACTION_REMOVE);
        }
       
        if (scope != null) {
            String valueStr = scope.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 mediator"
                        + ", Unsupported scope " + valueStr;
                log.error(msg);
                throw new SynapseException(msg);
            }
            propMediator.setScope(valueStr);
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(propMediator, elem);
View Full Code Here

        }
    }

    protected SequenceMediator getTestSequence(String name, String value) {
        SequenceMediator seq = new SequenceMediator();
        PropertyMediator prop = new PropertyMediator();
        prop.setName(name);
        prop.setValue(value);
        seq.addChild(prop);
        return seq;
    }
View Full Code Here

        if (!(m instanceof PropertyMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }

        PropertyMediator mediator = (PropertyMediator) m;
        OMElement property = fac.createOMElement("property", synNS);
        saveTracingState(property, mediator);

        if (mediator.getName() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "name", nullNS, mediator.getName()));
        } else {
            handleException("Invalid property mediator. Name is required");
        }

        if (mediator.getValue() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "value", nullNS, mediator.getValue().toString()));
        } else if (mediator.getValueElement() != null) {
            property.addChild(mediator.getValueElement());
        } else if (mediator.getExpression() != null) {
            SynapseXPathSerializer.serializeXPath(mediator.getExpression(),
                    property, "expression");
        } else if (mediator.getAction() == PropertyMediator.ACTION_SET) {
            handleException("Invalid property mediator. Value or expression is required if " +
                    "action is SET");
        }

        if (mediator.getScope() != null) {
            // if we have already built a mediator with scope, scope should be valid, now save it
            property.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.getAction() == PropertyMediator.ACTION_REMOVE) {
            property.addAttribute(fac.createOMAttribute(
                    "action", nullNS, "remove"));
        } else if (mediator.getType() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "type" , nullNS, mediator.getType()));
        }

        if (mediator.getPattern() != null) {
            property.addAttribute(fac.createOMAttribute(
                    "pattern", nullNS, mediator.getPattern().toString()));
            if (mediator.getGroup() >= 0) {
                property.addAttribute(fac.createOMAttribute(
                        "group", nullNS, Integer.toString(mediator.getGroup())));
            }
        }

        return property;
    }
View Full Code Here

    private static final QName PROP_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");

    public Mediator createMediator(OMElement elem) {

        PropertyMediator propMediator = new PropertyMediator();
        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
        OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));

        if (name == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else if (value == null && expression == null) {
            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator";
            log.error(msg);
            throw new SynapseException(msg);
        }

        propMediator.setName(name.getAttributeValue());
        if (value != null) {
            propMediator.setValue(value.getAttributeValue());
        } else {
            try {
                AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
                Util.addNameSpaces(xp, elem, log);
                propMediator.setExpression(xp);

            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
View Full Code Here

TOP

Related Classes of org.apache.synapse.mediators.builtin.PropertyMediator

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.