Package org.apache.neethi.builders.xml

Examples of org.apache.neethi.builders.xml.XmlPrimtiveAssertion


                List controlList = ((Policy) obj).getPolicyComponents();
                for (Iterator controlIterator = controlList.iterator(); controlIterator.hasNext();)
                {
                    Object object = controlIterator.next();
                    if (object instanceof XmlPrimtiveAssertion) {
                        XmlPrimtiveAssertion primitiveAssertion =
                                (XmlPrimtiveAssertion) object;
                        OMElement element = primitiveAssertion.getValue();
                        // Name of the policy assertion
                        String name = element.getLocalName();
                        //Value of the policy assertion
                        String value = element.getText();
View Full Code Here


                if (cL != null) {
                    for (Iterator ci =
                            cL.iterator(); ci.hasNext();) {
                        Object ca = ci.next();
                        if (ca instanceof XmlPrimtiveAssertion) {
                            XmlPrimtiveAssertion id = (XmlPrimtiveAssertion) ca;
                            OMElement el = id.getValue();

                            String t = el.getAttributeValue(
                                    ThrottleConstants.THROTTLE_TYPE_ATTRIBUTE_QNAME);
                            if (t == null) {
                                handleException("Type of Throtle " +
                                        "in the policy cannot be null");
                            }
                            if (t.equals("IP")) {
                                // create a ip based throttle context and configuration
                                tc = th.getThrottleConfiguration
                                        (ThrottleConstants.IP_BASED_THROTTLE_KEY);
                                if (tc == null) {
                                    tc =
                                            ThrottleConfigurationFactory.
                                                    createThrottleConfiguration(
                                                            ThrottleConstants.IP_BASE);
                                    th.addThrottleContext(
                                            ThrottleConstants.IP_BASED_THROTTLE_KEY,
                                            ThrottleContextFactory.createThrottleContext(
                                                    ThrottleConstants.IP_BASE, tc));
                                    th.addThrottleConfiguration(
                                            ThrottleConstants.IP_BASED_THROTTLE_KEY, tc);
                                }
                                //create a callercontext for ip based throttle
                                cn = CallerConfigurationFactory.
                                        createCallerConfiguration(
                                                ThrottleConstants.IP_BASE);
                            } else if (t.equals("DOMAIN")) {
                                // create a domain based throttle context and configuration
                                tc = th.getThrottleConfiguration(
                                        ThrottleConstants.DOMAIN_BASED_THROTTLE_KEY);
                                if (tc == null) {
                                    tc =
                                            ThrottleConfigurationFactory.
                                                    createThrottleConfiguration(
                                                            ThrottleConstants.DOMAIN_BASE);
                                    th.addThrottleContext(
                                            ThrottleConstants.DOMAIN_BASED_THROTTLE_KEY,
                                            ThrottleContextFactory.createThrottleContext(
                                                    ThrottleConstants.DOMAIN_BASE, tc));
                                    th.addThrottleConfiguration(
                                            ThrottleConstants.DOMAIN_BASED_THROTTLE_KEY, tc);
                                }
                                //create a callercontext for domain based throttl
                                cn =
                                        CallerConfigurationFactory.
                                                createCallerConfiguration(
                                                        ThrottleConstants.DOMAIN_BASE);
                            } else {
                                handleException("Unsupported throttle type : " + t);
                            }
                            if (cn != null) {

                                // Name of the policy assertion
                                String n = el.getLocalName();
                                // Value of the policy assertion
                                String v = el.getText();

                                // If Value and Name  are null,
                                // then it is a invalid policy config
                                if (n == null || v == null) {
                                    handleException("Either Value or" +
                                            " Name of the policy cannot be null");
                                } else if (n.equals(ThrottleConstants.ID_PARAMETER_NAME)) {

                                    if (!v.equals("")) {

                                        isIPRangeFound = true;
                                        cn.setID(v);
                                    } else {
                                        handleException("Value of ID cannot find " +
                                                "- invalid configuration");
                                    }
                                } else {
                                    handleException("Undefined pocilcy property for" +
                                            " throttle - Expect ID  ");
                                }
                            }

                        } else if (ca instanceof ExactlyOne) {
                            cp = (ExactlyOne) ca;
                        }
                    }
                }
                if (cn != null) {
                    if (cp != null) {
                        List cal = cp.getPolicyComponents();
                        boolean haveSelectOneFromExactlyOne = false;
                        for (Iterator ci = cal.iterator(); ci.hasNext()
                                && !haveSelectOneFromExactlyOne;) {
                            Object co = ci.next();
                            if (co instanceof All) {
                                haveSelectOneFromExactlyOne = true;
                                boolean isFoundMaxCount = false;
                                boolean isFoundUnitTime = false;
                                All childAll = (All) co;
                                List cd = childAll.getPolicyComponents();
                                for (Iterator cdl = cd.iterator(); cdl.hasNext();) {
                                    Object d = cdl.next();
                                    if (d instanceof XmlPrimtiveAssertion) {
                                        XmlPrimtiveAssertion adx =
                                                (XmlPrimtiveAssertion) d;
                                        OMElement el = adx.getValue();
                                        // Name of the policy assertion
                                        String n = el.getLocalName();
                                        //Value of the policy assertion
                                        String v = el.getText();

                                        //if Value and Name  are null,then it is a
                                        // invalid policy config
                                        if (n == null || v == null) {
                                            handleException("Either Value or " +
                                                    "Name of the policy cannot be null");
                                        }
                                        if (!v.equals("")) {

                                            if (n.equals(
                                                    ThrottleConstants.
                                                            MAXIMUM_COUNT_PARAMETER_NAME)) {

                                                isFoundMaxCount = true;
                                                try {
                                                    cn.setMaximumRequestPerUnitTime(
                                                            Integer.parseInt(v.trim()));
                                                } catch (NumberFormatException ignored) {
                                                    log.error("Error occurred - " +
                                                            "Invalid number for maximum " +
                                                            "request number ", ignored);
                                                    if (log.isDebugEnabled()) {
                                                        log.debug("Access" +
                                                                " will be fully allowed");
                                                    }
                                                    cn.setAccessState(
                                                            ThrottleConstants.ACCESS_ALLOWED);
                                                }
                                            } else if (n.equals(
                                                    ThrottleConstants.
                                                            UNIT_TIME_PARAMETER_NAME)) {
                                                //TODO need to verify that value is in milisecond
                                                long timeInMiliSec = 0;
                                                try {
                                                    timeInMiliSec =
                                                            Long.parseLong(v.trim());
                                                } catch (NumberFormatException ignored) {
                                                    log.error("Error occurred " +
                                                            "- Invalid number for unit time",
                                                            ignored);
                                                }
                                                if (timeInMiliSec == 0) {
                                                    handleException("Unit Time cannot " +
                                                            "find - invalid throttle " +
                                                            "policy configuration");
                                                }
                                                isFoundUnitTime = true;
                                                cn.setUnitTime(timeInMiliSec);

                                            } else if (n.equals(
                                                    ThrottleConstants.
                                                            PROHIBIT_TIME_PERIOD_PARAMETER_NAME)) {
                                                try {
                                                    cn.setProhibitTimePeriod(
                                                            Long.parseLong(v.trim()));
                                                } catch (NumberFormatException ignored) {
                                                    log.error("Error occurred - Invalid" +
                                                            " number for prohibit time ",
                                                            ignored);
                                                }
                                            } else {
                                                handleException("Undefined Policy" +
                                                        " property for Throttle Policy");
                                            }
                                        } else {
                                            if (!n.equals(
                                                    ThrottleConstants.
                                                            PROHIBIT_TIME_PERIOD_PARAMETER_NAME)) {
                                                handleException("The policy which have " +
                                                        " defined as optional " +
                                                        "should have value ");
                                            }
                                        }
                                    }
                                }
                                if (isFoundUnitTime && isFoundMaxCount) {
                                    isExactlyOneFound = true;
                                } else {
                                    handleException("Maximum Count and UnitTime are " +
                                            "Mandatory in Throttle Policy ");

                                }
                            } else if (co instanceof XmlPrimtiveAssertion) {
                                haveSelectOneFromExactlyOne = true;
                                XmlPrimtiveAssertion alx = (XmlPrimtiveAssertion) co;
                                OMElement ele = alx.getValue();
                                // Name of the policy assertion
                                String n = ele.getLocalName();
                                //Value of the policy assertion
                                String v = ele.getText();

                                //if Value and Name are null,
                                // then it is a invalid policy config
                                if (n == null || v == null) {
                                    handleException("Either Value or" +
                                            " Name of the policy cannot be null");
                                } else if (n.equals(
                                        ThrottleConstants.ISALLOW_PARAMETER_NAME)) {
                                    if (v.equals(Boolean.toString(true))) {
                                        isExactlyOneFound = true;
                                        cn.setAccessState(
                                                ThrottleConstants.ACCESS_ALLOWED);
                                    } else if (v.equals(Boolean.toString(false))) {
                                        isExactlyOneFound = true;
                                        cn.setAccessState(
                                                ThrottleConstants.ACCESS_DENIED);
                                    } else {
                                        handleException("Value for isAllow " +
                                                " component is invalied");
                                    }
                                } else {
                                    handleException("Invalied Throttle" +
                                            " Policy configuration");
                                }
                            }
                        }
                    }

                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Couldn't find a cn for a throttle configuration" +
                                " for an one caller  ");
                    }
                }
                if (isIPRangeFound && isExactlyOneFound) {
                    // If the Throttle Configuration is valid
                    tc.addCallerConfiguration(cn);
                } else {
                    handleException("ID and one of Valid Control policy component are " +
                            "Mandatory in Throttle Policy");
                }
            } else if (tp instanceof XmlPrimtiveAssertion) {

                XmlPrimtiveAssertion mca = (XmlPrimtiveAssertion) tp;
                OMElement ele = mca.getValue();
                // Name of the policy assertion
                String n = ele.getLocalName();
                //Value of the policy assertion
                String v = ele.getText();
View Full Code Here

        } catch (RegistryException e) {
            log.error("Error occured in engaging throttlin at registry", e);
            throw new ThrottleComponentException("errorEngagingModuleAtRegistry");
        }

        XmlPrimtiveAssertion assertion = this.getThrottlePolicy(axisService
                .getPolicySubject().getAttachedPolicyComponents());

        //build builtPolicy according to received parameters
        OMElement policyElement = this.buildPolicy(policy,
                assertion, ThrottleComponentConstants.SERVICE_LEVEL);
View Full Code Here

        } catch (RegistryException e) {
            log.error("Error occured in globally engaging throttlin at registry", e);
            throw new ThrottleComponentException("errorEngagingModuleAtRegistry");
        }

        XmlPrimtiveAssertion assertion = this.getThrottlePolicy(module
                .getPolicySubject().getAttachedPolicyComponents());

        //build builtPolicy according to received parameters
        OMElement policyElement = this.buildPolicy(policy,
                assertion, ThrottleComponentConstants.GLOBAL_LEVEL);
View Full Code Here

            log.error("Error occured in engaging throttling for operation : "
                    + operationName + " at registry", e);
            throw new ThrottleComponentException("errorEngagingModuleAtRegistry");
        }

        XmlPrimtiveAssertion assertion = this.getThrottlePolicy(operation
                .getPolicySubject().getAttachedPolicyComponents());

        //build builtPolicy according to received parameters
        OMElement policyElement = this.buildPolicy(policy,
                assertion, ThrottleComponentConstants.OPERATION_LEVEL);
View Full Code Here

        //Set whether module is currently engaged or not
        AxisModule module = service.getAxisConfiguration()
                .getModule(ThrottleComponentConstants.THROTTLE_MODULE);
        currentConfig.setEngaged(service.isEngaged(module));

        XmlPrimtiveAssertion assertion = this.getThrottlePolicy(service
                .getPolicySubject().getAttachedPolicyComponents());

        return preparePolicyConfigs(assertion, currentConfig);
    }
View Full Code Here

            if (globallyEngaged != null && globallyEngaged.length() != 0) {
                currentConfig.setEngaged(Boolean.parseBoolean(globallyEngaged.trim()));
            }
        }

        XmlPrimtiveAssertion assertion = this.getThrottlePolicy(module
                .getPolicySubject().getAttachedPolicyComponents());

        return preparePolicyConfigs(assertion, currentConfig);
    }
View Full Code Here

        //Set whether module is currently engaged or not
        AxisModule module = service.getAxisConfiguration()
                .getModule(ThrottleComponentConstants.THROTTLE_MODULE);
        currentConfig.setEngaged((operation.isEngaged(module) || service.isEngaged(module)));

        XmlPrimtiveAssertion assertion = null;
        if (service.isEngaged(module)) {
            assertion = this.getThrottlePolicy(service
                    .getPolicySubject().getAttachedPolicyComponents());
        }
        if (assertion == null) {
View Full Code Here

        try {
            OMElement policyOM = createOMElement(policyXML);
            Policy policy = PolicyEngine.getPolicy(policyOM);
            List<Policy> list = new ArrayList<Policy>();
            list.add(policy);
            XmlPrimtiveAssertion assertion = this.getThrottlePolicy(list);

            return preparePolicyConfigs(assertion, new ThrottlePolicy());
        } catch (Exception e) {
            throw new ThrottleComponentException("Invalid policy XML ", e);
        }
View Full Code Here

                    Object object = iterator.next();
                    if (object instanceof List) {
                        List list = (List) object;
                        for (Object assertObj : list) {
                            if (assertObj instanceof XmlPrimtiveAssertion) {
                                XmlPrimtiveAssertion primitiveAssertion = (XmlPrimtiveAssertion)
                                        assertObj;
                                assertionName = primitiveAssertion.getName();
                                if (assertionName.equals(
                                        ThrottleConstants.SERVICE_THROTTLE_ASSERTION_QNAME)
                                        || assertionName.equals(
                                        ThrottleConstants.MODULE_THROTTLE_ASSERTION_QNAME) ||
                                        assertionName.equals(ThrottleConstants
View Full Code Here

TOP

Related Classes of org.apache.neethi.builders.xml.XmlPrimtiveAssertion

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.