activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1044412 - in /activemq/trunk/activemq-web-demo/src/main/webapp: js/amq.js test/amq_test.html
Date Fri, 10 Dec 2010 15:56:55 GMT
Author: dejanb
Date: Fri Dec 10 15:56:55 2010
New Revision: 1044412

URL: http://svn.apache.org/viewvc?rev=1044412&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3015 - js client does not establish session properly

Modified:
    activemq/trunk/activemq-web-demo/src/main/webapp/js/amq.js
    activemq/trunk/activemq-web-demo/src/main/webapp/test/amq_test.html

Modified: activemq/trunk/activemq-web-demo/src/main/webapp/js/amq.js
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web-demo/src/main/webapp/js/amq.js?rev=1044412&r1=1044411&r2=1044412&view=diff
==============================================================================
--- activemq/trunk/activemq-web-demo/src/main/webapp/js/amq.js (original)
+++ activemq/trunk/activemq-web-demo/src/main/webapp/js/amq.js Fri Dec 10 15:56:55 2010
@@ -45,6 +45,14 @@ org.activemq.Amq = function() {
 	// Best to keep this to a value less than one minute.
 	var timeout;
 
+	// A session should not be considered initialized until the JSESSIONID is returned
+	// from the initial GET request.  Otherwise subscription POSTS may register the
+	// subscription with the wrong session.
+	var sessionInitialized = false;
+
+	// This callback will be called after the first GET request returns.
+	var sessionInitializedCallback;	
+
 	// Poll delay. if set to positive integer, this is the time to wait in ms
 	// before sending the next poll after the last completes.
 	var pollDelay;
@@ -136,16 +144,27 @@ org.activemq.Amq = function() {
 		}
 	};
 
+	var initHandler = function(data) {
+		sessionInitialized = true;
+		if(sessionInitializedCallback) {
+			sessionInitializedCallback();
+		}
+		sendPoll();
+	}
+
 	var sendPoll = function() {
 		// Workaround IE6 bug where it caches the response
 		// Generate a unique query string with date and random
 		var now = new Date();
-		var data = 'timeout=' + timeout * 1000
+		var timeoutArg = sessionInitialized ? timeout : 0.001;
+		var data = 'timeout=' + timeoutArg * 1000
 				 + '&d=' + now.getTime()
 				 + '&r=' + Math.random();
+		var successCallback = sessionInitialized ? pollHandler : initHandler;
+
 		var options = { method: 'get',
 			data: addClientId( data ),
-			success: pollHandler,
+			success: successCallback,
 			error: pollErrorHandler};
 		adapter.ajax(uri, options);
 	};
@@ -206,6 +225,7 @@ org.activemq.Amq = function() {
 			pollDelay = typeof options.pollDelay == 'number' ? options.pollDelay : 0;
 			timeout = typeof options.timeout == 'number' ? options.timeout : 25;
 			logging = options.logging;
+			sessionInitializedCallback = options.sessionInitializedCallback
 			clientId = options.clientId;
 			adapter.init(options);
 			sendPoll();

Modified: activemq/trunk/activemq-web-demo/src/main/webapp/test/amq_test.html
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web-demo/src/main/webapp/test/amq_test.html?rev=1044412&r1=1044411&r2=1044412&view=diff
==============================================================================
--- activemq/trunk/activemq-web-demo/src/main/webapp/test/amq_test.html (original)
+++ activemq/trunk/activemq-web-demo/src/main/webapp/test/amq_test.html Fri Dec 10 15:56:55
2010
@@ -107,7 +107,7 @@
       var requests = org.activemq.AmqAdapter.getRequests();
       
       assertEqual( 'get', requests[ 0 ].options.method );
-      assert( requests[ 0 ].options.data.match( /timeout=30000&d=\d+&r=[\d.]+/ )
);
+      assert( requests[ 0 ].options.data.match( /timeout=1&d=\d+&r=[\d.]+/ ) );
     }},
     
     testPostIsSentIfNoBatchIsInProgress: function() { with( this ) {



Mime
View raw message