Package org.wso2.carbon.mediator.service

Examples of org.wso2.carbon.mediator.service.MediatorException


    public void build(OMElement elem) {
        OMAttribute name = elem.getAttribute(ATT_NAME);
        if (name == null) {
            String msg = "The name of the actual mediator class is a required attribute";
            throw new MediatorException(msg);
        }
        this.mediator = name.getAttributeValue();
       
        for (Iterator it = elem.getChildrenWithName(PROP_Q); it.hasNext();) {
            OMElement child = (OMElement) it.next();

            String propName = child.getAttribute(ATT_NAME).getAttributeValue();
            if (propName == null) {
                throw new MediatorException(
                    "A Class mediator property must specify the name attribute");
            } else {
                if (child.getAttribute(ATT_VALUE) != null) {
                    String value = child.getAttribute(ATT_VALUE).getAttributeValue();
                    properties.put(propName, value);
                } else {
                    OMNode omElt = child.getFirstElement();
                    if (omElt != null) {
                        properties.put(propName, omElt);
                    } else {
                        throw new MediatorException("A Class mediator property must specify " +
                            "name and value attributes, or a name and a child XML fragment");
                    }
                }
            }
        }
View Full Code Here


    public OMElement serialize(OMElement parent) {
        OMElement sequence = fac.createOMElement("RMSequence", synNS);
        saveTracingState(sequence, this);

        if(single && correlation != null) {
            throw new MediatorException("Invalid RMSequence mediator. A RMSequence can't have both a "
                    + "single attribute value of true and a correlation attribute specified.");
        }
        if(single && lastMessage != null) {
            throw new MediatorException("Invalid RMSequence mediator. A RMSequence can't have both a "
                    + "single attribute value of true and a last-message attribute specified.");
        }

        if (single) {
            sequence.addAttribute(fac.createOMAttribute("single", nullNS, String.valueOf(single)));
        } else if (correlation != null) {
            SynapseXPathSerializer.serializeXPath(
                correlation, sequence, "correlation");
        } else {
            throw new MediatorException("Invalid RMSequence mediator. Specify a single message sequence "
                    + "or a correlation attribute.");
        }

        if (lastMessage != null) {
            SynapseXPathSerializer.serializeXPath(
View Full Code Here

        OMAttribute version = elem.getAttribute(ATT_VERSION);

        if (single == null && correlation == null) {
            String msg = "The 'single' attribute value of true or a 'correlation' attribute is " +
                "required for the configuration of a RMSequence mediator";
            throw new MediatorException(msg);
        }

        if (correlation != null) {
            if (correlation.getAttributeValue() != null &&
                correlation.getAttributeValue().trim().length() == 0) {
                String msg = "Invalid attribute value specified for correlation";
                throw new MediatorException(msg);

            } else {
                try {
                    this.correlation =
                        SynapseXPathFactory.getSynapseXPath(elem, ATT_CORR);
        this.single = false;
                } catch (JaxenException e) {
                    String msg = "Invalid XPath expression for attribute correlation : "
                        + correlation.getAttributeValue();
                    throw new MediatorException(msg);
                }
            }
        }

        if (single != null) {
            this.single = Boolean.valueOf(single.getAttributeValue());
        }

        if (this.single && this.correlation != null) {
            String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
                + "single attribute value of true and a correlation attribute specified.";
            throw new MediatorException(msg);

        } else if (!this.single && correlation == null) {
            String msg = "Invalid RMSequence mediator. A RMSequence must have a "
                + "single attribute value of true or a correlation attribute specified.";
            throw new SynapseException(msg);
        }

        if (lastMessage != null) {
            if (lastMessage.getAttributeValue() != null &&
                lastMessage.getAttributeValue().trim().length() == 0) {
                String msg = "Invalid attribute value specified for last-message";
                throw new MediatorException(msg);

            } else {
                try {
                    this.lastMessage =
                        SynapseXPathFactory.getSynapseXPath(elem, ATT_LASTMSG);
                } catch (JaxenException e) {
                    String msg = "Invalid XPath expression for attribute last-message : "
                        + lastMessage.getAttributeValue();
                    throw new MediatorException(msg);
                }
            }
        }

        if (this.single && this.lastMessage != null) {
            String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
                + "single attribute value of true and a last-message attribute specified.";
            throw new SynapseException(msg);
        }

        if (version != null) {
            if (!XMLConfigConstants.SEQUENCE_VERSION_1_0.equals(version.getAttributeValue()) &&
                !XMLConfigConstants.SEQUENCE_VERSION_1_1.equals(version.getAttributeValue())) {
                String msg = "Only '" + XMLConfigConstants.SEQUENCE_VERSION_1_0 + "' or '" +
                    XMLConfigConstants.SEQUENCE_VERSION_1_1
                    + "' values are allowed for attribute version for a RMSequence mediator"
                    + ", Unsupported version " + version.getAttributeValue();
                throw new MediatorException(msg);
            }
            this.version = version.getAttributeValue();
        }

        // after successfully creating the mediator
View Full Code Here

                                faultCodeValue.getLocalPart())) ) {

            this.faultCodeValue = faultCodeValue;

        } else {
            throw new MediatorException("Invalid Fault code value for a SOAP 1.2 fault : " + faultCodeValue);
        }
    }
View Full Code Here

        return faultNode;
    }

    public void setFaultNode(URI faultNode) {
        if (soapVersion == SOAP11) {
            throw new MediatorException("A fault node does not apply to a SOAP 1.1 fault");
        }
        this.faultNode = faultNode;
    }
View Full Code Here

        } else if (faultCodeExpr != null) {
            SynapseXPathSerializer.serializeXPath(faultCodeExpr, code, "expression");

        } else if (soapVersion != POX) {
            throw new MediatorException("Fault code is required for a fault " +
                    "mediator unless it is a pox fault");
        }

        OMElement reason = fac.createOMElement("reason", synNS, fault);
        if (faultReasonValue != null) {
            reason.addAttribute(fac.createOMAttribute(
                "value", nullNS, faultReasonValue));

        } else if (faultReasonExpr != null) {

            SynapseXPathSerializer.serializeXPath(
                faultReasonExpr, reason, "expression");

        } else if (soapVersion != POX) {
            throw new MediatorException("Fault reason is required for a fault " +
                    "mediator unless it is a pox fault");
        }


        if (faultNode != null) {
View Full Code Here

            } else if (SOAP12_STRING.equals(version.getAttributeValue())) {
                soapVersion = SOAP12;
            } else if (POX_STRING.equals(version.getAttributeValue())) {
                soapVersion = POX;
            } else {
                throw new MediatorException("Invalid SOAP version");
            }
        }

        OMAttribute response = elem.getAttribute(ATT_RESPONSE_Q);
        if (response != null) {
            if ("true".equals(response.getAttributeValue())) {
                markAsResponse = true;
            } else if ("false".equals(response.getAttributeValue())) {
                markAsResponse = false;
            } else {
                throw new MediatorException("Invalid value '" + response.getAttributeValue()
                        + "' passed as response. Expected 'true' or 'false'");
            }
            serializeResponse = true;
        }

        OMElement code = elem.getFirstChildWithName(CODE_Q);
        if (code != null) {
            OMAttribute value = code.getAttribute(ATT_VALUE);
            OMAttribute expression = code.getAttribute(ATT_EXPRN);

            if (value != null) {
                String strValue = value.getAttributeValue();
                String prefix = null;
                String name = null;
                if (strValue.indexOf(":") != -1) {
                    prefix = strValue.substring(0, strValue.indexOf(":"));
                    name = strValue.substring(strValue.indexOf(":")+1);
                } else {
                    throw new MediatorException("A QName is expected for fault code as prefix:name");
                }
                String namespaceURI = OMElementUtils.getNameSpaceWithPrefix(prefix, code);
                if (namespaceURI == null) {
                    throw new MediatorException("Invalid namespace prefix '" + prefix + "' in code attribute");
                }
                faultCodeValue = new QName(namespaceURI, name, prefix);
            } else if (expression != null) {
                try {
                    faultCodeExpr = SynapseXPathFactory.getSynapseXPath(code, ATT_EXPRN);
                } catch (JaxenException je) {
                    throw new MediatorException("Invalid fault code expression : " + je.getMessage());
                }
            } else {
                throw new MediatorException("A 'value' or 'expression' attribute must specify the fault code");
            }

        } else if (soapVersion != POX) {
            throw new MediatorException("The fault code is a required attribute for the " +
                    "makefault mediator unless it is a pox fault");
        }

        OMElement reason = elem.getFirstChildWithName(REASON_Q);
        if (reason != null) {
            OMAttribute value = reason.getAttribute(ATT_VALUE);
            OMAttribute expression = reason.getAttribute(ATT_EXPRN);

            if (value != null) {
                faultReasonValue = value.getAttributeValue();
            } else if (expression != null) {
                try {
                    faultReasonExpr = SynapseXPathFactory.getSynapseXPath(reason, ATT_EXPRN);
                } catch (JaxenException je) {
                    throw new MediatorException("Invalid fault reason expression : " + je.getMessage());
                }
            } else {
                throw new MediatorException("A 'value' or 'expression' attribute must specify the fault code");
            }

        } else if (soapVersion != POX) {
            throw new MediatorException("The fault reason is a required attribute for the " +
                    "makefault mediator unless it is a pox fault");
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(this, elem);

        OMElement node = elem.getFirstChildWithName(NODE_Q);
        if (node != null && node.getText() != null) {
            try {
                faultNode = new URI(node.getText());
            } catch (URISyntaxException e) {
                throw new MediatorException("Invalid URI specified for fault node : " + node.getText());
            }
        }

        OMElement role = elem.getFirstChildWithName(ROLE_Q);
        if (role != null && role.getText() != null) {
            try {
                faultRole = new URI(role.getText());
            } catch (URISyntaxException e) {
                throw new MediatorException("Invalid URI specified for fault role : " + role.getText());
            }
        }

        OMElement detail = elem.getFirstChildWithName(DETAIL_Q);
        if (detail != null) {
            OMAttribute detailExpr = detail.getAttribute(ATT_EXPRN);
            if (detailExpr != null && detailExpr.getAttributeValue() != null) {
                try {
                    faultDetailExpr = SynapseXPathFactory.getSynapseXPath(detail, ATT_EXPRN);
                } catch (JaxenException e) {
                    throw new MediatorException("Unable to build the XPath for fault detail " +
                            "from the expression : " + detailExpr.getAttributeValue());
                }
            } else if (detail.getFirstOMChild() != null) {
                OMNode detailNode = detail.getFirstOMChild();
                if (detailNode instanceof OMText) {
View Full Code Here

        if (name != null) {
            property.addAttribute(fac.createOMAttribute(
                    "name", nullNS, name));
        } else {
            throw new MediatorException("Property name not specified");
        }

        if (action == ACTION_SET) {
            if (value != null) {
                property.addAttribute(fac.createOMAttribute(
                        "value", nullNS, value));
            } else if (expression != null) {
                SynapseXPathSerializer.serializeXPath(expression, property, "expression");
            } else if (valueElement != null) {
                property.addChild(valueElement);
            } else {
                throw new MediatorException("Property value, expression or inline " +
                        "element must be set");
            }

            if (pattern != null) {
                property.addAttribute(fac.createOMAttribute("pattern", nullNS, pattern));
View Full Code Here

        OMAttribute patternAttr = elem.getAttribute(ATT_PATTERN);
        OMAttribute groupAttr = elem.getAttribute(ATT_GROUP);

        if (nameAttr == null) {
            String msg = "The 'name' attribute is required for the configuration of a property mediator";
            throw new MediatorException(msg);
        } else if ((valueAttr == null && expressionAttr == null) && !(actionAttr != null && "remove".equals(actionAttr.getAttributeValue()))) {
            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator when action is SET";
            throw new MediatorException(msg);
        }

        this.name = nameAttr.getAttributeValue();

        // The action attribute is optional, if provided and equals to 'remove' the
        // property mediator will act as a property remove mediator
        if (actionAttr != null && "remove".equals(actionAttr.getAttributeValue())) {
            this.action = ACTION_REMOVE;
        }

        if (valueAttr != null) {
            this.value = valueAttr.getAttributeValue();
        } else if (expressionAttr != null) {
            try {
                this.expression = SynapseXPathFactory.getSynapseXPath(elem, ATT_EXPRN);
            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'expression' : " + expressionAttr.getAttributeValue();
                throw new MediatorException(msg);
            }
        } else if (elem.getFirstElement() != null) {
            valueElement = elem.getFirstElement();
        }

        if (scopeAttr != null) {
            String valueStr = scopeAttr.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;
                throw new MediatorException(msg);
            }
            this.scope = valueStr;
        }

        if (typeAttr != null) {
View Full Code Here

        if (command != null) {
            pojoCommand.addAttribute(fac.createOMAttribute(
                "name", nullNS, command));
        } else {
            throw new MediatorException("Invalid POJO Command mediator. The command class name is required");
        }

        for (String propName : getStaticSetterProperties().keySet()) {
            Object value = getStaticSetterProperties().get(propName);
            OMElement prop = fac.createOMElement(PROP_Q.getLocalPart(), synNS);
            prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));

            if (value instanceof String) {
                prop.addAttribute(fac.createOMAttribute("value", nullNS, (String) value));
            } else if (value instanceof OMElement) {
                prop.addChild((OMElement) value);
            } else {
                throw new MediatorException("Unable to serialize the command " +
                    "mediator property with the naem " + propName + " : Unknown type");
            }

            if (getContextGetterProperties().containsKey(propName)) {
                prop.addAttribute(fac.createOMAttribute("context-name", nullNS,
View Full Code Here

TOP

Related Classes of org.wso2.carbon.mediator.service.MediatorException

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.