Examples of ThrottleComponentException


Examples of org.wso2.carbon.throttle.ThrottleComponentException

                registry.addAssociation(servicePath, getModuleResourcePath(module),
                        RegistryResources.Associations.ENGAGED_MODULES);
            }
        } 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);
        Policy builtPolicy = PolicyEngine.getPolicy(policyElement);

        //if we didn't find an already existing builtPolicy, attach a new one
        Policy policyToPersist = builtPolicy;
        if (assertion == null) {
            axisService.getPolicySubject().attachPolicy(builtPolicy);
        } else {
            axisService.getPolicySubject().updatePolicy(policyToUpdate);
            policyToPersist = policyToUpdate;
        }

        //persist the throttle builtPolicy into registry
        try {
            Resource policyResource = registry.newResource();
            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_TYPE,
                    "" + PolicyInclude.AXIS_SERVICE_POLICY);
            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_UUID,
                    policyToPersist.getId());
            this.persistPoliciesToRegistry(policyToPersist, servicePath, servicePath, policyResource);
        } catch (Exception e) {
            log.error("Error occured while saving the builtPolicy in registry", e);
            throw new ThrottleComponentException("errorSavingPolicy");
        }

        //engage the module only if it is not already engaged
        axisService.engageModule(module);
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

                globalResource.addProperty(GLOBALLY_ENGAGED_CUSTOM, Boolean.TRUE.toString());
                registry.put(globalPath, globalResource);
            }
        } 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);
        Policy builtPolicy = PolicyEngine.getPolicy(policyElement);

        //if we didn't find an already existing builtPolicy, attach a new one
        Policy policyToPersist = builtPolicy;
        if (assertion == null) {
            module.getPolicySubject().attachPolicy(builtPolicy);
        } else {
            module.getPolicySubject().updatePolicy(policyToUpdate);
            policyToPersist = policyToUpdate;
        }

        //persist the throttle builtPolicy into registry
        try {
            Resource policyResource = registry.newResource();
            policyResource.setProperty(RegistryResources.ModuleProperties.POLICY_TYPE,
                    "" + PolicyInclude.AXIS_MODULE_POLICY);
            policyResource.setProperty(RegistryResources.ModuleProperties.POLICY_UUID,
                    policyToPersist.getId());
            policyResource.setProperty(RegistryResources.ModuleProperties.VERSION,
                    module.getVersion().toString());
            this.persistPoliciesToRegistry(policyToPersist, resourcePath, null, policyResource);
        } catch (Exception e) {
            log.error("Error occured while saving the builtPolicy in registry", e);
            throw new ThrottleComponentException("errorSavingPolicy");
        }

        module.addParameter(new Parameter(GLOBALLY_ENGAGED_PARAM_NAME, Boolean.TRUE.toString()));

        //engage the module for every service which is not an admin service
        try {
            registry.beginTransaction();
            for (Iterator serviceIter = this.axisConfig.getServices().values().iterator();
                 serviceIter.hasNext();) {
                AxisService service = (AxisService) serviceIter.next();
                String adminParamValue =
                        (String) service.getParent().getParameterValue(ADMIN_SERICE_PARAM_NAME);

                //avoid admin services
                if (adminParamValue != null && adminParamValue.length() != 0 &&
                        Boolean.parseBoolean(adminParamValue.trim())) {
                    continue;
                }
                this.enableThrottling(service.getName(), policy);
            }
            registry.commitTransaction();
        } catch (Exception e) {
            log.error("Error occured in globally engaging throttlin at registry", e);
            try {
                registry.rollbackTransaction();
            } catch (RegistryException ex) {
                log.error("Unable to rollback transaction", ex);
            }
            throw new ThrottleComponentException("errorEngagingModuleAtRegistry");
        }
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

        AxisOperation operation = axisService.getOperation(new QName(operationName));
        if (operation == null) {
            log.error("No operation found from the name " + operationName
                    + ", in service : " + serviceName);
            throw new ThrottleComponentException("noSuchOperation", new String[]{serviceName});
        }

        String servicePath = RegistryResources.SERVICE_GROUPS
                + axisService.getAxisServiceGroup().getServiceGroupName()
                + RegistryResources.SERVICES + serviceName;

        String operationPath = servicePath + RegistryResources.OPERATIONS
                + operationName;

        // engage at registry
        try {
            // Check if an association exist between servicePath and moduleResourcePath.
            Association[] associations = registry.getAssociations(operationPath,
                    RegistryResources.Associations.ENGAGED_MODULES);
            boolean associationExist = false;
            for (Association association : associations) {
                if (association.getDestinationPath().equals(getModuleResourcePath(module))) {
                    associationExist = true;
                    break;
                }
            }

            //if throttling is not found, add a new association
            if (!associationExist) {
                registry.addAssociation(operationPath, getModuleResourcePath(module),
                        RegistryResources.Associations.ENGAGED_MODULES);
            }
        } catch (RegistryException e) {
            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);
        Policy builtPolicy = PolicyEngine.getPolicy(policyElement);

        //if we didn't find an already existing builtPolicy, attach a new one
        Policy policyToPersist = builtPolicy;
        if (assertion == null) {
            operation.getPolicySubject().attachPolicy(builtPolicy);
        } else {
            operation.getPolicySubject().updatePolicy(policyToUpdate);
            policyToPersist = policyToUpdate;
        }

        //persist the throttle builtPolicy into registry
        try {
            Resource policyResource = registry.newResource();
            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_TYPE,
                    "" + PolicyInclude.AXIS_OPERATION_POLICY);
            policyResource.setProperty(RegistryResources.ServiceProperties.POLICY_UUID,
                    policyToPersist.getId());
            this.persistPoliciesToRegistry(policyToPersist,
                    servicePath, operationPath, policyResource);
        } catch (Exception e) {
            log.error("Error occured while saving the builtPolicy in registry", e);
            throw new ThrottleComponentException("errorSavingPolicy");
        }

        //engage the module at operation
        operation.engageModule(module);
        return false;
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

            AxisOperation operation = axisService.getOperation(new QName(operationName));
            if (operation == null) {
                log.error("No operation found from the name " + operationName
                        + ", in service : " + serviceName);
                throw new ThrottleComponentException("noSuchOperation", new String[]{serviceName});
            }

            String operationPath = RegistryResources.SERVICE_GROUPS
                    + axisService.getAxisServiceGroup().getServiceGroupName()
                    + RegistryResources.SERVICES + serviceName + RegistryResources.OPERATIONS
                    + operationName;

            //disengage the throttling module
            try {
                // disengage at registry
                registry.removeAssociation(operationPath, getModuleResourcePath(module),
                        RegistryResources.Associations.ENGAGED_MODULES);

                // disengage at Axis
                operation.disengageModule(module);

            } catch (RegistryException e) {
                log.error("Error occured while removing assertion from registry", e);
                throw new ThrottleComponentException("errorDisablingAtRegistry");
            }

        } catch (AxisFault e) {
            log.error("Error occured while disengaging module from AxisService", e);
            throw new ThrottleComponentException("errorDisablingThrottling", e);
        }
        return false;
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

                // disengage at Axis
                axisService.disengageModule(module);

            } catch (RegistryException e) {
                log.error("Error occured while removing assertion from registry", e);
                throw new ThrottleComponentException("errorDisablingAtRegistry");
            }

        } catch (AxisFault e) {
            log.error("Error occured while disengaging module from AxisService", e);
            throw new ThrottleComponentException("errorDisablingThrottling", e);
        }
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

                this.disableThrottling(service.getName());
            }

        } catch (RegistryException e) {
            log.error("Error occured while removing global throttle from registry", e);
            throw new ThrottleComponentException("errorDisablingAtRegistry");
        } catch (AxisFault axisFault) {
            log.error("Error occured while disengaging module from AxisService", axisFault);
            throw new ThrottleComponentException("errorDisablingThrottling", axisFault);
        }
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

        AxisOperation operation = service.getOperation(new QName(operationName));
        if (operation == null) {
            log.error("No operation found from the name " + operationName
                    + ", in service : " + serviceName);
            throw new ThrottleComponentException("noSuchOperation", new String[]{serviceName});
        }

        //object to be returned
        ThrottlePolicy currentConfig = new ThrottlePolicy();
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

            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

Examples of org.wso2.carbon.throttle.ThrottleComponentException

            //Get the input stream of the template policy from registry
            Resource resource;
            if (registry.resourceExists(resourceUri)) {
                resource = registry.get(resourceUri);
            } else {
                throw new ThrottleComponentException("templateNotFound");
            }
            InputStream in = resource.getContentStream();

            //Get the template policy element by parsing the input stream
            parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
        } catch (Exception e) {
            log.error("Error occoured while loading template from registry", e);
            throw new ThrottleComponentException("errorLoadingTemplate");
        }
        StAXOMBuilder builder = new StAXOMBuilder(parser);
        return builder.getDocumentElement();
    }
View Full Code Here

Examples of org.wso2.carbon.throttle.ThrottleComponentException

    private AxisService getAxisService(String serviceName) throws ThrottleComponentException {
        AxisService axisService = axisConfig.getServiceForActivation(serviceName);
        if (axisService == null) {
            log.error("No service found from the name " + serviceName);
            throw new ThrottleComponentException("noSuchService", new String[]{serviceName});
        }
        return axisService;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.