Author: indika
Date: Mon Oct 29 08:46:50 2007
New Revision: 589693
URL: http://svn.apache.org/viewvc?rev=589693&view=rev
Log:
fixed an issue in throttle mediator
Modified:
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_602.xml
Modified:
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java?rev=589693&r1=589692&r2=589693&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
Mon Oct 29 08:46:50 2007
@@ -21,8 +21,8 @@
public class DBLookupMediatorSerializationTest extends AbstractTestCase {
- DBLookupMediatorFactory dbLookupFactory;
- DBLookupMediatorSerializer dbLookupSerializer;
+ private DBLookupMediatorFactory dbLookupFactory;
+ private DBLookupMediatorSerializer dbLookupSerializer;
public DBLookupMediatorSerializationTest() {
super(DBLookupMediatorSerializationTest.class.getName());
@@ -30,45 +30,12 @@
dbLookupSerializer = new DBLookupMediatorSerializer();
}
- public void testClassMediatorSerializationSenarioOne() throws Exception {
+ public void testDBLookupMediatorSerializationSenarioOne() throws Exception
{
+
String inputXml =
"<syn:dblookup
xmlns:syn=\"http://ws.apache.org/ns/synapse\"><syn:connection><syn:pool><syn:driver>com.some.driver.JDBCDriver</syn:driver><syn:url>jdbc:/some/url</syn:url><syn:user>user</syn:user><syn:password>pass</syn:password><syn:property
name=\"name1\"
value=\"value1\"/></syn:pool></syn:connection><syn:statement><syn:sql>insert
into table values (?, ?, ..)</syn:sql><syn:parameter value=\"ABC\"
type=\"VARCHAR\"/><syn:parameter expression=\"4\" type=\"INTEGER\"/><syn:result
name=\"2\" column=\"int\"/></syn:statement></syn:dblookup>";
-
-// "<dblookup xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
-// " <connection>\n" +
-// " <pool>\n" +
-// " <driver>com.some.driver.JDBCDriver</driver>\n" +
-// " <url>jdbc:/some/url</url>\n" +
-// " <user>user</user>\n" +
-// " <password>pass</password>\n" +
-// " <property name=\"name1\" value=\"value1\"/>\n" +
-// " <property name=\"name2\" value=\"value2\"/>\n" +
-// " </pool>\n" +
-// " </connection>\n" +
-// " <statement>\n" +
-// " <sql>insert into table values (?, ?, ..)</sql>\n" +
-// " <parameter value=\"ABC\" type=\"VARCHAR\"/>\n" +
-// " <parameter expression=\"4\" type=\"INTEGER\"/>\n" +
-// " <result name=\"res1\" column=\"String\"/>\n" +
-// " <result name=\"2\" column=\"int\"/>\n" +
-// " </statement>\n" +
-// "</dblookup>";
- assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
- assertTrue(serialization(inputXml, dbLookupSerializer));
- }
-/*
- public void testClassMediatorSerializationWithProperty() throws Exception {
- String inputXml = "<class xmlns=\"http://ws.apache.org/ns/synapse\"
name=\"org.apache.synapse.config.xml.TestMediator\"><property name=\"testProp\"
value=\"This is a test\"/></class> ";
assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
assertTrue(serialization(inputXml, dbLookupSerializer));
}
-
- public void testClassMediatorSerializationWithInlineProperty() throws
Exception {
- String inputXml = "<class xmlns=\"http://ws.apache.org/ns/synapse\"
name=\"org.apache.synapse.config.xml.TestMediator\"><property
name=\"testElemProp\"><test/></property></class> ";
- assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
- assertTrue(serialization(inputXml, dbLookupSerializer));
- }
-*/
-
}
Modified:
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java?rev=589693&r1=589692&r2=589693&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
(original)
+++
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
Mon Oct 29 08:46:50 2007
@@ -111,7 +111,7 @@
* Current Implementaion only support IP Based Throttling
*
* @param synContext Current Message Context
- * @param traceOn indicate whether trace is eanabled or not
+ * @param traceOn indicate whether trace is eanabled or not
* @return boolean which indicate whether this caller can or not access
*/
private boolean canAccess(MessageContext synContext, boolean
traceOrDebugOn, boolean traceOn) {
@@ -160,21 +160,23 @@
/**
* Doing concurrency throttlling
- * @param isResponse indicate whether message flow is OUT or IN
+ *
+ * @param isResponse indicate whether message flow is OUT or IN
* @param traceOrDebugOn is tracing or debbug on
- * @param traceOn indicate whether trace is ON or OFF
+ * @param traceOn indicate whether trace is ON or OFF
* @return True if message can continue ,otherwise false
*/
private boolean throttleByConcurrency(boolean isResponse, boolean
traceOrDebugOn, boolean traceOn) {
- int available = 0;
if (concurrentAccessController != null) {
+ int available = 0;
if (!isResponse) {
available = concurrentAccessController.getAndDecrement();
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Access " + (available > 0 ?
"allowed" : "denied") +
" :: " + available + " of available of " +
concurrentLimit + " connections");
}
+ return available > 0;
} else {
available = concurrentAccessController.incrementAndGet();
if (traceOrDebugOn) {
@@ -183,16 +185,18 @@
}
return true;
}
+ } else {
+ return true;
}
- return available > 0;
}
/**
* Processing throughh IP based throttle
- * @param synContext Current Message
+ *
+ * @param synContext Current Message
* @param traceOrDebugOn
- * @param traceOn Indicates whether trace is ON or OFF
- * @return True if message can continue ,otherwise false
+ * @param traceOn Indicates whether trace is ON or OFF
+ * @return True if message can continue ,otherwise false
*/
private boolean throttleByRate(MessageContext synContext, boolean
traceOrDebugOn, boolean traceOn) {
@@ -233,7 +237,7 @@
boolean canAccess = accessControler.canAccess(throttleContext,
remoteIP);
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Access " + (canAccess ? "allowed" :
"denied")
- +" for IP : " + remoteIP);
+ + " for IP : " + remoteIP);
}
return canAccess;
@@ -251,9 +255,9 @@
* If the policy is defined as a Inline XML ,then only one time policy
will process and any runtime
* changes to the policy will not reflect
*
- * @param synCtx Current Message
+ * @param synCtx Current Message
* @param traceOrDebugOn is tracing or debug on?
- * @param traceOn is tracing on?
+ * @param traceOn is tracing on?
*/
protected void initThrottle(MessageContext synCtx, boolean traceOrDebugOn,
boolean traceOn) {
@@ -263,7 +267,7 @@
if (traceOn && trace.isTraceEnabled()) {
trace.trace("Initializing using static throttling policy :
" + inLinePolicy);
}
- createThrottleMetaData(inLinePolicy, synCtx, traceOrDebugOn,
traceOn);
+ createThrottleMetaData(inLinePolicy, synCtx, traceOrDebugOn,
traceOn, false);
}
} else if (policyKey != null) {
@@ -274,28 +278,17 @@
handleException("Cannot find throttling policy using key : " +
policyKey, synCtx);
} else {
- Object entryValue = entry.getValue();
- if (entryValue == null) {
- handleException(
- "Null throttling policy returned by Entry : " +
policyKey, synCtx);
- } else {
- if (!(entryValue instanceof OMElement)) {
- handleException("Policy returned from key : " +
policyKey +
- " is not an OMElement", synCtx);
+ boolean reCreate = false;
- } else {
- // if entry is dynamic, need to check wheather expired
or not
- if ((!entry.isCached() || entry.isExpired())) {
- if (traceOn && trace.isTraceEnabled()) {
- trace.trace("Re/initializing using dynamic
throttling policy : " +
- entryValue);
- }
- createThrottleMetaData(
- (OMElement) entryValue, synCtx,
traceOrDebugOn, traceOn);
- }
+ // if the key refers to a dynamic resource
+ if (entry.isDynamic()) {
+ if (!entry.isCached() || entry.isExpired()) {
+ reCreate = true;
}
}
+ createThrottleMetaData(
+ null, synCtx, traceOrDebugOn, traceOn, reCreate);
}
}
}
@@ -304,26 +297,45 @@
* Create the throttling policy and the "Throttle" object applicable. If
this is a
* concurrent throttling instance, set the throttling access controller to
the shared
* map
- * @param policyOmElement throttling policy
- * @param synCtx incoming message
+ *
+ * @param policy throttling policy
+ * @param synCtx incoming message
* @param traceOrDebugOn is tracing or debug on?
- * @param traceOn is tracing on?
+ * @param traceOn is tracing on?
+ * @param reCreate is it need to reCreate the throttle
*/
- private synchronized void createThrottleMetaData(OMElement policyOmElement,
- MessageContext synCtx, boolean traceOrDebugOn, boolean traceOn) {
+ private synchronized void createThrottleMetaData(OMElement policy,
+ MessageContext synCtx,
boolean traceOrDebugOn, boolean traceOn, boolean reCreate) {
- if (inLinePolicy != null && throttle != null) {
+ if (!reCreate && throttle != null) {
// this uses a static policy, and one thread has already created
the "Throttle"
// object, just return...
return;
}
-
try {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Creating a new throttle configuration
by parsing the Policy");
}
- throttle = ThrottlePolicyProcessor.processPolicy(
- PolicyEngine.getPolicy(policyOmElement));
+ if (policy != null) {
+ throttle = ThrottlePolicyProcessor.processPolicy(
+ PolicyEngine.getPolicy(policy));
+ } else {
+ Object entryValue = synCtx.getEntry(policyKey);
+ if (entryValue == null) {
+ handleException(
+ "Null throttling policy returned by Entry : " +
policyKey, synCtx);
+
+ } else {
+ if (!(entryValue instanceof OMElement)) {
+ handleException("Policy returned from key : " +
policyKey +
+ " is not an OMElement", synCtx);
+
+ } else {
+ throttle = ThrottlePolicyProcessor.processPolicy(
+ PolicyEngine.getPolicy((OMElement) entryValue));
+ }
+ }
+ }
includesIPThrottling = (
throttle.getThrottleContext(ThrottleConstants.IP_BASED_THROTTLE_KEY) != null);
Modified:
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java?rev=589693&r1=589692&r2=589693&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
(original)
+++
webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
Mon Oct 29 08:46:50 2007
@@ -86,7 +86,7 @@
private final Object resourceLock = new Object();
/** Is it need to use DOMSource and DOMResult? */
- private boolean useDOMSource = true;
+ private boolean useDOMSource = false;
/** The DataSource which use to create a connection to XML database */
private XQDataSource cachedXQDataSource = null;
Modified:
webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_602.xml
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_602.xml?rev=589693&r1=589692&r2=589693&view=diff
==============================================================================
---
webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_602.xml
(original)
+++
webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_602.xml
Mon Oct 29 08:46:50 2007
@@ -20,7 +20,7 @@
<registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">
<!-- the root property of the simple URL registry helps resolve a
resource URL as root + key -->
- <parameter name="root">file:./../../repository/</parameter>
+ <parameter name="root">file:repository/</parameter>
<!-- all resources loaded from the URL registry would be cached for
this number of milli seconds -->
<parameter name="cachableDuration">15000</parameter>
</registry>
@@ -57,7 +57,7 @@
<target>
<inSequence>
<throttle onReject="onRejectSequence"
onAccept="onAcceptSequence" id="A">
- <policy key="thottlePolicy"/>
+ <policy
key="conf/sample/resources/policy/throttle_policy.xml"/>
</throttle>
</inSequence>
<outSequence>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]