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;