ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/3] incubator-ignite git commit: # gg-10561: tests and fix session
Date Wed, 22 Jul 2015 16:12:03 GMT
# gg-10561: tests and fix session


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/482cfbb8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/482cfbb8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/482cfbb8

Branch: refs/heads/ignite-gg-10561
Commit: 482cfbb8c733305e4d80f1495dd79865682ee4c6
Parents: f30b111
Author: ashutak <ashutak@gridgain.com>
Authored: Wed Jul 22 19:12:15 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Wed Jul 22 19:12:15 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestProcessor.java      | 24 ++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/482cfbb8/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index bf6c0fb..60c7ef4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -278,8 +278,6 @@ public class GridRestProcessor extends GridProcessorAdapter {
             clientId2Session.put(ses.clientId, ses);
             sesTokId2Session.put(ses.sesTokId, ses);
 
-            // TODO add checks.
-
             return ses;
         }
 
@@ -291,12 +289,12 @@ public class GridRestProcessor extends GridProcessorAdapter {
                 ses.clientId = clientId;
                 ses.sesTokId = UUID.randomUUID();
 
-                clientId2Session.put(ses.clientId, ses);
-                sesTokId2Session.put(ses.sesTokId, ses);
+                Session oldSes = clientId2Session.putIfAbsent(ses.clientId, ses);
 
-                // TODO add checks.
+                if (oldSes == null)
+                    sesTokId2Session.put(ses.sesTokId, ses);
 
-                return ses;
+                return oldSes == null ? ses : oldSes;
             }
 
             return ses;
@@ -308,14 +306,22 @@ public class GridRestProcessor extends GridProcessorAdapter {
             Session ses = sesTokId2Session.get(sesTokId);
 
             if (ses == null)
-                throw new IgniteCheckedException("Failed to handle request. Unknown session
token " +
+                throw new IgniteCheckedException("Faile to handle request. Unknown session
token " +
                     "(maybe expired session). [sessionToken=" + U.byteArray2HexString(sesTok)
+ "]");
 
             return ses;
         }
 
-        if (!F.isEmpty(sesTok) && clientId != null)
-            throw new IgniteCheckedException("Failed to handle request. Unsupported case.");
+        if (!F.isEmpty(sesTok) && clientId != null) {
+            Session ses1 = sesTokId2Session.get(U.bytesToUuid(sesTok, 0));
+            Session ses2 = clientId2Session.get(clientId);
+
+            if (ses1 == null || ses2 == null || !ses1.equals(ses2))
+                throw new IgniteCheckedException("Failed to handle request. " +
+                    "Unsupported case (use one: clientId or session token)");
+
+            return ses1;
+        }
 
         throw new IgniteCheckedException("Failed to handle request (Unreachable state).");
     }


Mime
View raw message