You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2016/06/14 17:15:22 UTC
[43/44] usergrid git commit: Additional enhancements to cursor
validation and error messages.
Additional enhancements to cursor validation and error messages.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3df07791
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3df07791
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3df07791
Branch: refs/heads/usergrid-1268-akka-211
Commit: 3df07791c394de2e7ec7e1f9559e1490f63af630
Parents: 72c9df1
Author: Michael Russo <mr...@apigee.com>
Authored: Tue Jun 7 09:32:15 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Tue Jun 7 09:32:15 2016 -0700
----------------------------------------------------------------------
.../pipeline/cursor/CursorSerializerUtil.java | 9 ---------
.../pipeline/cursor/RequestCursor.java | 21 ++++++++++++++++----
2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3df07791/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
index 7acdd00..5728433 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
@@ -40,12 +40,6 @@ public class CursorSerializerUtil {
private static final ObjectMapper MAPPER = new ObjectMapper( SMILE_FACTORY );
- /**
- * Aritrary number, just meant to keep us from having a DOS issue
- */
- private static final int MAX_SIZE = 1024;
-
-
public static ObjectMapper getMapper() {
return MAPPER;
}
@@ -75,9 +69,6 @@ public class CursorSerializerUtil {
*/
public static JsonNode fromString( final String base64EncodedJson ) {
- Preconditions.checkArgument( base64EncodedJson.length() <= MAX_SIZE,
- "Your cursor must be less than " + MAX_SIZE + " chars in length" );
-
final byte[] data = Base64.getUrlDecoder().decode( base64EncodedJson );
JsonNode jsonNode;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3df07791/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
index acd6e25..0209794 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
@@ -35,6 +35,10 @@ import java.util.Map;
*/
public class RequestCursor {
+ /**
+ * Arbitrary number, just meant to keep us from having a DOS issue
+ */
+ private static final int MAX_SIZE = 1024;
private static final int MAX_CURSOR_COUNT = 100;
@@ -74,9 +78,15 @@ public class RequestCursor {
* Deserialize from the cursor as json nodes
*/
private Map<Integer, JsonNode> fromCursor( final String cursor ) throws CursorParseException {
- if(cursor.isEmpty()){
- throw new IllegalArgumentException("cursor cannot be empty");
- }
+
+
+ Preconditions.checkArgument( cursor != null, "Cursor cannot be null");
+
+ Preconditions.checkArgument( cursor.length() <= MAX_SIZE,
+ "Your cursor must be less than " + MAX_SIZE + " chars in length" );
+
+ Preconditions.checkArgument( !cursor.isEmpty(), "Cursor cannot have an empty value");
+
try {
JsonNode jsonNode = CursorSerializerUtil.fromString( cursor );
@@ -95,8 +105,11 @@ public class RequestCursor {
return cursors;
}
+ catch ( IllegalArgumentException ie ){
+ throw new IllegalArgumentException("Provided cursor has an invalid format and cannot be parsed.");
+ }
catch ( Exception e ) {
- throw new CursorParseException( "Unable to serialize cursor", e );
+ throw new CursorParseException( "Unable to deserialize cursor", e );
}
}
}