Throttle defaultThrottle) throws AxisFault {
String currentServiceName;
if (axisDescription instanceof AxisService) {
Throttle throttle = null;
AxisService currentService = ((AxisService) axisDescription);
PolicySubject policySubject = currentService.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentService);
if (currentPolicy != null) {
throttle = ThrottleFactory.createServiceThrottle(currentPolicy);
if(throttle == null) {
//this is for the scenario when throttle policy is empty rather than
// null (eg: removing the throttle policy via policy editor)
throttle = defaultThrottle;
}
//todo - done by isuru, recheck
} else {
AxisConfiguration axisConfig = configctx.getAxisConfiguration();
AxisModule throttleModule = axisConfig.getModule(
ThrottleConstants.THROTTLE_MODULE_NAME);
policySubject = throttleModule.getPolicySubject();
if (policySubject != null) {
currentPolicy = ThrottleEnguageUtils.getThrottlePolicy(
policySubject.getAttachedPolicyComponents());
if (currentPolicy != null) {
throttle = ThrottleFactory.createModuleThrottle(currentPolicy);
}
}
//todo - done by isuru
}
} catch (ThrottleException e) {
log.error("Error was occurred when engaging throttle module for" +
" the service :" +
currentService.getName() + e.getMessage());
log.info("Throttling will occur using default module policy");
throttle = defaultThrottle;
}
if (throttle != null) {
Map throttles =
(Map) configctx.getPropertyNonReplicable(
ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(
ThrottleConstants.THROTTLES_MAP, throttles);
}
String serviceName = currentService.getName();
throttle.setId(serviceName);
throttles.put(serviceName, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX
+ serviceName + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
} else if (axisDescription instanceof AxisOperation) {
Throttle throttle = null;
AxisOperation currentOperation = ((AxisOperation) axisDescription);
AxisService axisService = (AxisService) currentOperation.getParent();
if (axisService != null) {
currentServiceName = axisService.getName();
PolicySubject policySubject = currentOperation.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies,
currentOperation);
if (currentPolicy != null) {
throttle = ThrottleFactory.createOperationThrottle(currentPolicy);
}