Author: sanka Date: Fri May 30 02:11:17 2008 New Revision: 17652 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17652
Log: Committing a fix for WSAS-756 Modified: branches/wsas/java/2.3/commons/throttle/modules/core/pom.xml branches/wsas/java/2.3/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottlePolicyProcessor.java branches/wsas/java/2.3/commons/throttle/modules/mar/pom.xml branches/wsas/java/2.3/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java branches/wsas/java/2.3/commons/throttle/pom.xml Modified: branches/wsas/java/2.3/commons/throttle/modules/core/pom.xml URL: http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/commons/throttle/modules/core/pom.xml?rev=17652&r1=17651&r2=17652&view=diff ============================================================================== --- branches/wsas/java/2.3/commons/throttle/modules/core/pom.xml (original) +++ branches/wsas/java/2.3/commons/throttle/modules/core/pom.xml Fri May 30 02:11:17 2008 @@ -6,13 +6,13 @@ <parent> <groupId>org.wso2.throttle</groupId> <artifactId>wso2throttle-parent</artifactId> - <version>2.2</version> + <version>2.3-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>wso2throttle-core</artifactId> <packaging>jar</packaging> - <version>2.2</version> + <version>2.3-SNAPSHOT</version> <name>WSO2 Throttling module - core</name> <build> <plugins> Modified: branches/wsas/java/2.3/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottlePolicyProcessor.java URL: http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottlePolicyProcessor.java?rev=17652&r1=17651&r2=17652&view=diff ============================================================================== --- branches/wsas/java/2.3/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottlePolicyProcessor.java (original) +++ branches/wsas/java/2.3/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottlePolicyProcessor.java Fri May 30 02:11:17 2008 @@ -54,331 +54,373 @@ public static Throttle processPolicy(Policy policy) throws ThrottleException { - Throttle th = null; // throttle instance - ThrottleConfiguration tc = null; // configuration data - if (policy == null) { - //if policy is not available ,then return null for ThrottleConfiguration - return null; // no pilicy is available in the module description - } - List tl = policy.getPolicyComponents(); - for (Iterator it = tl.iterator(); - it.hasNext();) { - Object o = it.next(); - if (o instanceof XmlPrimtiveAssertion) { - XmlPrimtiveAssertion tlXpa = (XmlPrimtiveAssertion) - o; - QName q = tlXpa.getName(); // top policy must contains ThrottleAssertion - if (q.equals(ThrottleConstants.THROTTLE_ASSERTION_QNAME)) { - th = new Throttle(); - Policy throtlePolicy = PolicyEngine. - getPolicy(tlXpa.getValue()); - List al = throtlePolicy.getPolicyComponents(); - - if (al == null || (al != null && al.isEmpty())) { - handleException("Empty the policy components" + - " as ThrottleAssertion's children"); - } - for (Iterator i = al.iterator(); i.hasNext();) { - Object tp = i.next(); - if (tp instanceof All) { - - // boolean isOtherConfiguration = false; - // // To track default cn for all ips - CallerConfiguration cn = null; // To create a - //configurationbean object - boolean isIPRangeFound = false; - boolean isExactlyOneFound = false; - ExactlyOne cp = null; - List cL = ((All) tp).getAssertions(); - 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(); - - //if Value and Name are null,then - // it is a invalid policy configuration - if (n == null || v == null) { - handleException("Either Value or Name of the policy cannot be null"); - } else if (n.equals( - ThrottleConstants.MAXIMUM_CONCURRENT_ACCESS_PARAMETER_NAME)) { - int intvalue = 0; - try { - intvalue = Integer.parseInt(v.trim()); - } catch (NumberFormatException ignored) { - log.error("Error occurred - Invalid number for maximum " + - "concurrent access ", ignored); - } - if (intvalue > 0) { - th.setConcurrentAccessController( - new ConcurrentAccessController(intvalue)); - } - } else { - handleException("Invalied Throttle Policy configuration"); - } - } - } - } - } - } - return th; + Throttle th = null; // throttle instance + ThrottleConfiguration tc = null; // configuration data + if (policy == null) { + // if policy is not available ,then return null for + // ThrottleConfiguration + return null; // no pilicy is available in the module description + } + boolean found = false; + Object xmlPrim = null; + Iterator alternatives = policy.getAlternatives(); + outer: while (alternatives.hasNext()) { + List assertionsList = (List) alternatives.next(); + for (Iterator i = assertionsList.iterator(); i.hasNext();) { + xmlPrim = i.next(); + if (xmlPrim instanceof XmlPrimtiveAssertion) { + if (ThrottleConstants.THROTTLE_ASSERTION_QNAME + .equals(((XmlPrimtiveAssertion) xmlPrim).getName())) { + found = true; + break outer; + } + } + } + } + if (found) { + XmlPrimtiveAssertion tlXpa = (XmlPrimtiveAssertion) xmlPrim; + QName q = tlXpa.getName(); // top policy must contains + // ThrottleAssertion + if (q.equals(ThrottleConstants.THROTTLE_ASSERTION_QNAME)) { + th = new Throttle(); + Policy throtlePolicy = PolicyEngine.getPolicy(tlXpa.getValue()); + List al = throtlePolicy.getPolicyComponents(); + + if (al == null || (al != null && al.isEmpty())) { + handleException("Empty the policy components" + + " as ThrottleAssertion's children"); + } + for (Iterator i = al.iterator(); i.hasNext();) { + Object tp = i.next(); + if (tp instanceof All) { + + // boolean isOtherConfiguration = false; + // // To track default cn for all ips + CallerConfiguration cn = null; // To create a + // configurationbean object + boolean isIPRangeFound = false; + boolean isExactlyOneFound = false; + ExactlyOne cp = null; + List cL = ((All) tp).getAssertions(); + 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(); + + // if Value and Name are null,then + // it is a invalid policy configuration + if (n == null || v == null) { + handleException("Either Value or Name of the policy cannot be null"); + } else if (n + .equals(ThrottleConstants.MAXIMUM_CONCURRENT_ACCESS_PARAMETER_NAME)) { + int intvalue = 0; + try { + intvalue = Integer.parseInt(v.trim()); + } catch (NumberFormatException ignored) { + log + .error( + "Error occurred - Invalid number for maximum " + + "concurrent access ", + ignored); + } + if (intvalue > 0) { + th + .setConcurrentAccessController(new ConcurrentAccessController( + intvalue)); + } + } else { + handleException("Invalied Throttle Policy configuration"); + } + } + } + } + } + return th; } /** - * Helper method to handle exception - * - * @param messeage Debug message - * @throws ThrottleException - */ + * Helper method to handle exception + * + * @param messeage + * Debug message + * @throws ThrottleException + */ private static void handleException(String messeage) throws ThrottleException { String msg = "Error was ocuured during throttle policy processing " + messeage; log.error(msg); Modified: branches/wsas/java/2.3/commons/throttle/modules/mar/pom.xml URL: http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/commons/throttle/modules/mar/pom.xml?rev=17652&r1=17651&r2=17652&view=diff ============================================================================== --- branches/wsas/java/2.3/commons/throttle/modules/mar/pom.xml (original) +++ branches/wsas/java/2.3/commons/throttle/modules/mar/pom.xml Fri May 30 02:11:17 2008 @@ -6,13 +6,13 @@ <parent> <groupId>org.wso2.throttle</groupId> <artifactId>wso2throttle-parent</artifactId> - <version>2.2</version> + <version>2.3-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>wso2throttle</artifactId> <packaging>jar</packaging> - <version>2.2</version> + <version>2.3-SNAPSHOT</version> <name>WSO2 Throttling module - Mar</name> <build> Modified: branches/wsas/java/2.3/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java URL: http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java?rev=17652&r1=17651&r2=17652&view=diff ============================================================================== --- branches/wsas/java/2.3/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java (original) +++ branches/wsas/java/2.3/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java Fri May 30 02:11:17 2008 @@ -18,21 +18,33 @@ package org.wso2.throttle.module; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + import org.apache.axis2.AxisFault; import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.description.*; +import org.apache.axis2.description.AxisDescription; +import org.apache.axis2.description.AxisModule; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.PolicySubject; import org.apache.axis2.modules.Module; +import org.apache.axis2.util.PolicyUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.neethi.Assertion; import org.apache.neethi.Policy; import org.apache.neethi.PolicyEngine; -import org.wso2.throttle.*; - -import javax.xml.namespace.QName; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; +import org.wso2.throttle.ConcurrentAccessController; +import org.wso2.throttle.Throttle; +import org.wso2.throttle.ThrottleConstants; +import org.wso2.throttle.ThrottleException; +import org.wso2.throttle.ThrottlePolicyProcessor; public class ThrottleModule implements Module { @@ -50,10 +62,12 @@ initDefaultPolicy(); initDefaultThrottle(); Throttle throttle; - PolicyInclude policyInclude = module.getPolicyInclude(); - if (policyInclude != null) { - Policy policy = policyInclude.getEffectivePolicy(); - if (policy != null) { + PolicySubject policySubject = module.getPolicySubject(); + if (policySubject != null) { + List list = new ArrayList(policySubject + .getAttachedPolicyComponents()); + Policy policy = PolicyUtil.getMergedPolicy(list, null); + if (policy != null) { try { throttle = ThrottlePolicyProcessor.processPolicy(policy); } @@ -63,9 +77,9 @@ log.info("Throttling will occur using default module policy"); String id = policy.getId(); - policyInclude.removePolicyElement(id); + policySubject.detachPolicyComponent(id); defaultPolicy.setId(id); - policyInclude.addPolicyElement(PolicyInclude.AXIS_MODULE_POLICY, defaultPolicy); + policySubject.attachPolicy(defaultPolicy); throttle = defaultThrottle; } if (throttle != null) { @@ -99,13 +113,11 @@ if (axisDescription instanceof AxisService) { Throttle throttle = null; AxisService currentService = ((AxisService) axisDescription); - PolicyInclude policyInclude = currentService.getPolicyInclude(); - if (policyInclude != null) { + PolicySubject policySubject = currentService.getPolicySubject(); + if (policySubject != null) { try { - Policy currentPolicy = policyInclude.getPolicy(); - if (currentPolicy == null) { - currentPolicy = policyInclude.getEffectivePolicy(); - } + List policies = new ArrayList(policySubject.getAttachedPolicyComponents()); + Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentService); if (currentPolicy != null) { throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy); } @@ -146,13 +158,11 @@ AxisService axisService = (AxisService) currentOperation.getParent(); if (axisService != null) { currentServiceName = axisService.getName(); - PolicyInclude policyInclude = currentOperation.getPolicyInclude(); - if (policyInclude != null) { + PolicySubject policySubject = currentOperation.getPolicySubject(); + if (policySubject != null) { try { - Policy currentPolicy = policyInclude.getPolicy(); - if (currentPolicy == null) { - currentPolicy = policyInclude.getEffectivePolicy(); - } + List policies = new ArrayList(policySubject.getAttachedPolicyComponents()); + Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentOperation); if (currentPolicy != null) { throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy); } @@ -236,4 +246,4 @@ throw new AxisFault(msg); } } -} \ No newline at end of file +} Modified: branches/wsas/java/2.3/commons/throttle/pom.xml URL: http://wso2.org/svn/browse/wso2/branches/wsas/java/2.3/commons/throttle/pom.xml?rev=17652&r1=17651&r2=17652&view=diff ============================================================================== --- branches/wsas/java/2.3/commons/throttle/pom.xml (original) +++ branches/wsas/java/2.3/commons/throttle/pom.xml Fri May 30 02:11:17 2008 @@ -6,7 +6,7 @@ <groupId>org.wso2.throttle</groupId> <artifactId>wso2throttle-parent</artifactId> <packaging>pom</packaging> - <version>2.2</version> + <version>2.3-SNAPSHOT</version> <name>WSO2 throttle module</name> <url>http://www.wso2.org</url> @@ -194,15 +194,15 @@ </modules> <properties> - <axis2.version>1.35</axis2.version> + <axis2.version>1.4.01</axis2.version> <wso2throttle.version>${pom.version}</wso2throttle.version> - <axiom.version>1.2.6</axiom.version> - <neethi.version>2.0.2</neethi.version> - <commons.logging.version>1.1</commons.logging.version> - <junit.version>3.8.2</junit.version> + <axiom.version>1.2.7</axiom.version> + <neethi.version>2.0.4</neethi.version> + <commons.logging.version>1.1.1</commons.logging.version> + <junit.version>4.4</junit.version> <log4j.version>1.2.13</log4j.version> <ant.version>1.7.0</ant.version> <servlet-api.version>2.3</servlet-api.version> - <backport.util.concurrent.version>2.2</backport.util.concurrent.version> + <backport.util.concurrent.version>3.1</backport.util.concurrent.version> </properties> </project> _______________________________________________ Wsas-java-dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev
