You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/01 12:13:59 UTC

[23/39] incubator-ignite git commit: #ignite-964: wip

#ignite-964: wip


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

Branch: refs/heads/ignite-964
Commit: 80bd452c985d685169f7ca8bc4bd264e0f4d33ca
Parents: ea50ebb
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 30 18:53:10 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 30 18:53:10 2015 +0300

----------------------------------------------------------------------
 .../processors/scripting/JSONCacheObject.java   |  78 -------------
 .../http/jetty/GridJettyRestHandler.java        |  53 ++++++---
 .../protocols/http/jetty/JSONCacheObject.java   | 111 +++++++++++++++++++
 3 files changed, 149 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/80bd452c/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
deleted file mode 100644
index 46067d7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.scripting;
-
-import java.util.*;
-
-/**
- * Json cache object.
- */
-public class JSONCacheObject {
-    /** Fields map. */
-    private Map<String, Object> fields = new HashMap<>();
-
-    /**
-     * @param key Field name.
-     * @param val Field value.
-     */
-    public void addField(String key, Object val) {
-        fields.put(key, val);
-    }
-
-    /**
-     * @param key Field name.
-     * @return Field value.
-     */
-    public Object getField(String key) {
-        return fields.get(key);
-    }
-
-    /**
-     * @return Fields key set.
-     */
-    public Set<String> keys() {
-        return fields.keySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        //TODO:
-        return fields.hashCode();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (obj == null || !(obj instanceof JSONCacheObject))
-            return false;
-
-        JSONCacheObject obj0 = (JSONCacheObject) obj;
-
-        if (fields.size() != obj0.fields.size())
-            return false;
-
-        for (String key : obj0.keys()) {
-            if (!fields.containsKey(key))
-                return false;
-
-            if (!obj0.getField(key).equals(getField(key)))
-                return false;
-        }
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/80bd452c/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 6327c88..f7b1db8 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -358,28 +358,28 @@ public class GridJettyRestHandler extends AbstractHandler {
 
                 if (req.getHeader("JSONObject") != null) {
                     if (cmd == CACHE_PUT_ALL) {
-                        StringBuilder builder = new StringBuilder();
+                        JSONObject o =parseRequest(req);
 
-                        Scanner reader = null;
+                        int i = 1;
 
-                        try {
-                            reader = new Scanner(req.getReader());
-                        }
-                        catch (IOException e) {
-                            throw new IgniteCheckedException(e);
-                        }
+                        Map<Object, Object> map = U.newHashMap(o.keySet().size());
 
-                        while (reader.hasNext())
-                            builder.append(reader.next() + "\n");
+                        while (o.get("k" + i) != null) {
+                            Object key = o.get("k" + i);
 
-                        JSONObject o = JSONObject.fromObject(builder.toString());
+                            Object val = o.get("val" + i);
 
-                        restReq0.cacheName(F.isEmpty(cacheName) ? null : cacheName);
+                            if (key instanceof JSONObject)
+                                key = new JSONCacheObject((JSONObject)key);
 
-                        Map<Object, Object> map = U.newHashMap(o.keySet().size());
+                            if (val instanceof JSONObject)
+                                val = new JSONCacheObject((JSONObject)val);
 
-                        for (Object k : o.keySet())
-                            map.put(k, o.get(k));
+                            map.put(key, val);
+                            i++;
+                        }
+
+                        restReq0.cacheName(F.isEmpty(cacheName) ? null : cacheName);
 
                         restReq0.values(map);
                     }
@@ -732,4 +732,27 @@ public class GridJettyRestHandler extends AbstractHandler {
 
         return null;
     }
+
+    /**
+     * @param req Request.
+     * @return JSON object.
+     * @throws IgniteCheckedException If failed.
+     */
+    private JSONObject parseRequest(HttpServletRequest req) throws IgniteCheckedException{
+        StringBuilder builder = new StringBuilder();
+
+        Scanner reader = null;
+
+        try {
+            reader = new Scanner(req.getReader());
+        }
+        catch (IOException e) {
+            throw new IgniteCheckedException(e);
+        }
+
+        while (reader.hasNext())
+            builder.append(reader.next() + "\n");
+
+        return JSONObject.fromObject(builder.toString());
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/80bd452c/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/JSONCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/JSONCacheObject.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/JSONCacheObject.java
new file mode 100644
index 0000000..9bcd419
--- /dev/null
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/JSONCacheObject.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.rest.protocols.http.jetty;
+
+import net.sf.json.*;
+
+import java.util.*;
+
+/**
+ * Json cache object.
+ */
+public class JSONCacheObject {
+    /** Fields map. */
+    private Map<Object, Object> fields = new HashMap<>();
+
+    public JSONCacheObject() {
+
+    }
+
+    public JSONCacheObject(JSONObject o) {
+        for (Object key : o.keySet())
+            addField(toSimpleObject(key), toSimpleObject(o.get(key)));
+    }
+
+    private Object toSimpleObject(Object o) {
+        if (o instanceof JSONObject) {
+            JSONObject o1 = (JSONObject)o;
+            JSONCacheObject res = new JSONCacheObject();
+
+            for (Object key : o1.keySet())
+                res.addField(toSimpleObject(key), toSimpleObject(o1.get(key)));
+
+            return res;
+        }
+        else if (o instanceof JSONArray) {
+            JSONArray o1 = (JSONArray) o;
+            List<Object> val = new ArrayList<>();
+            for (Object v : o1)
+                val.add(toSimpleObject(v));
+
+            return val;
+        }
+
+        return o;
+    }
+
+    /**
+     * @param key Field name.
+     * @param val Field value.
+     */
+    public void addField(Object key, Object val) {
+        fields.put(key, val);
+    }
+
+    /**
+     * @param key Field name.
+     * @return Field value.
+     */
+    public Object getField(Object key) {
+        return fields.get(key);
+    }
+
+    /**
+     * @return Fields key set.
+     */
+    public Set<Object> keys() {
+        return fields.keySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        //TODO:
+        return fields.hashCode();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (obj == null || !(obj instanceof JSONCacheObject))
+            return false;
+
+        JSONCacheObject obj0 = (JSONCacheObject) obj;
+
+        if (fields.size() != obj0.fields.size())
+            return false;
+
+        for (Object key : obj0.keys()) {
+            if (!fields.containsKey(key))
+                return false;
+
+            if (!obj0.getField(key).equals(getField(key)))
+                return false;
+        }
+
+        return true;
+    }
+}