Package org.apache.synapse.mediators

Examples of org.apache.synapse.mediators.MediatorProperty


            Endpoint endpoint = endpoints.get(i);
            if (!(endpoint instanceof PropertyInclude)) {
                EndpointState state = new EndpointState(i, DEFAULT_WEIGHT);
                endpointStates[i] = state;
            } else {
                MediatorProperty property =
                        ((PropertyInclude) endpoint).getProperty(LOADBALANCE_WEIGHT);
                EndpointState state;
                if (property != null) {
                    int weight = Integer.parseInt(property.getValue());

                    if (weight <= 0) {
                        String msg = "Weight must be greater than zero";
                        log.error(msg);
                        throw new SynapseException(msg);
                    }

                    state = new EndpointState(i, weight);
                } else {
                    state = new EndpointState(i, DEFAULT_WEIGHT);
                }

                endpointStates[i] = state;
            }
        }

        if (loadBalanceEndpoint instanceof PropertyInclude) {
            MediatorProperty threadLocalProperty = ((PropertyInclude) loadBalanceEndpoint).
                    getProperty(LOADBALANCE_ThEADLOCAL);

            if (threadLocalProperty != null && threadLocalProperty.getValue().equals("true")) {
                isThreadLocal = true;
            }
        }

        view = new WeightedRoundRobinView(this);
View Full Code Here


            OMAttribute attName  = propEle.getAttribute(MediatorProperty.ATT_NAME_Q);
            OMAttribute attValue = propEle.getAttribute(MediatorProperty.ATT_VALUE_Q);
            OMAttribute attExpr  = propEle.getAttribute(MediatorProperty.ATT_EXPR_Q);
            OMAttribute attScope = propEle.getAttribute(MediatorProperty.ATT_SCOPE_Q);

            MediatorProperty prop = new MediatorProperty();

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

                } else {
                    try {
                        prop.setExpression(SynapseXPathFactory.getSynapseXPath(
                            propEle, MediatorProperty.ATT_EXPR_Q));

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

            } else {
                String msg = "Entry attribute value OR expression must " +
                    "be specified for a mediator property";
                log.error(msg);
                throw new SynapseException(msg);
            }

            if (attScope != null) {
                String valueStr = attScope.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" +
                            ", Unsupported scope " + valueStr;
                    log.error(msg);
                    throw new SynapseException(msg);
                }
                prop.setScope(valueStr);
            }

            propertyList.add(prop);
        }
View Full Code Here

     *
     * @see TransformerFactory#setFeature(String, boolean)
     * @see XSLTMediator
     */
    public void addFeature(String featureName, boolean isFeatureEnable) {
        MediatorProperty mp = new MediatorProperty();
        mp.setName(featureName);
        if (isFeatureEnable) {
            mp.setValue("true");
        } else {
            mp.setValue("false");
        }
        transformerFactoryFeatures.add(mp);
        if (USE_DOM_SOURCE_AND_RESULTS.equals(featureName)) {
            if (isFeatureEnable) {
                sourceBuilderFactory = new DOOMSourceBuilderFactory();
View Full Code Here

     *
     * @see TransformerFactory#setAttribute(String, Object)
     * @see XSLTMediator
     */
    public void addAttribute(String name, String value) {
        MediatorProperty mp = new MediatorProperty();
        mp.setName(name);
        mp.setValue(value);
        transformerFactoryAttributes.add(mp);
        if (SOURCE_BUILDER_FACTORY.equals(name) || RESULT_BUILDER_FACTORY.equals(name)) {
            Object instance;
            try {
                instance = Class.forName(value).newInstance();
View Full Code Here

     * @param isFeatureEnable should this feature enable?(true|false)
     * @see #getFeature(String)
     * @throws SAXException on an unknown feature
     */
   public void addFeature(String featureName, boolean isFeatureEnable) throws SAXException {
        MediatorProperty mp = new MediatorProperty();
        mp.setName(featureName);
        if (isFeatureEnable) {
            mp.setValue("true");
        } else {
            mp.setValue("false");
        }
        explicityFeatures.add(mp);
        factory.setFeature(featureName, isFeatureEnable);
    }
View Full Code Here

        assertTrue(ClassMediatorTestMediator.invoked);
    }

    public void testCreationWithLiteralProperties() throws Exception {
        ClassMediator cm = new ClassMediator();
        MediatorProperty mp = new MediatorProperty();
        mp.setName("testProp");
        mp.setValue("testValue");
        cm.addProperty(mp);
        cm.setClazz(ClassMediatorTestMediator.class);
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
    }
View Full Code Here

        assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
    }

    public void testCreationWithXPathProperties() throws Exception {
        ClassMediator cm = new ClassMediator();
        MediatorProperty mp = new MediatorProperty();
        mp.setName("testProp");
        mp.setExpression(new AXIOMXPath("concat('XPath ','is ','FUN!')"));
        cm.addProperty(mp);
        cm.setClazz(ClassMediatorTestMediator.class);
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.testProp.equals("XPath is FUN!"));
    }
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 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() :
                Util.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

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.