TINKERPOP-1913 ResponseException will have status attributes present

Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6adbe199
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6adbe199
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6adbe199

Branch: refs/heads/TINKERPOP-1913
Commit: 6adbe19983beeef3bae772ab49fd07ea5a7405a5
Parents: f22c98c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 16 10:38:48 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Sep 18 12:34:37 2018 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/Handler.java       | 12 +++++++-
 .../driver/exception/ResponseException.java     | 31 +++++++++++++++-----
 2 files changed, 35 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6adbe199/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
index 4a82f24..d79bed5 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Handler.java
@@ -256,7 +256,7 @@ final class Handler {
                         final List<String> exceptions = 
attributes.containsKey(Tokens.STATUS_ATTRIBUTE_EXCEPTIONS) ?
                                 (List<String>) 
attributes.get(Tokens.STATUS_ATTRIBUTE_EXCEPTIONS) : null;
                         queue.markError(new 
ResponseException(response.getStatus().getCode(), 
response.getStatus().getMessage(),
-                                exceptions, stackTrace));
+                                exceptions, stackTrace, 
cleanStatusAttributes(attributes)));
                     }
                 }
 
@@ -270,6 +270,7 @@ final class Handler {
 
                 // as this is a non-PARTIAL_CONTENT code - the stream is done.
                 if (statusCode != ResponseStatusCode.PARTIAL_CONTENT) {
+                    queue.statusAttributes = 
response.getStatus().getAttributes();
                     pending.remove(response.getRequestId()).markComplete();
                 }
             } finally {
@@ -294,6 +295,15 @@ final class Handler {
             if 
(!IteratorUtils.anyMatch(ExceptionUtils.getThrowableList(cause).iterator(), t 
-> t instanceof SerializationException))
                 if (ctx.channel().isActive()) ctx.close();
         }
+
+        private Map<String,Object> cleanStatusAttributes(final 
Map<String,Object> statusAttributes) {
+            final Map<String,Object> m = new HashMap<>();
+            statusAttributes.forEach((k,v) -> {
+                if (!k.equals(Tokens.STATUS_ATTRIBUTE_EXCEPTIONS) && 
!k.equals(Tokens.STATUS_ATTRIBUTE_STACK_TRACE))
+                    m.put(k,v);
+            });
+            return m;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6adbe199/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/ResponseException.java
----------------------------------------------------------------------
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/ResponseException.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/ResponseException.java
index 51e748a..a960d44 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/ResponseException.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/exception/ResponseException.java
@@ -20,27 +20,37 @@ package org.apache.tinkerpop.gremlin.driver.exception;
 
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
 
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class ResponseException extends Exception {
-    private ResponseStatusCode responseStatusCode;
-    private String remoteStackTrace = null;
-    private List<String> remoteExceptionHierarchy = null;
+    private final ResponseStatusCode responseStatusCode;
+    private final String remoteStackTrace;
+    private final List<String> remoteExceptionHierarchy;
+    private final Map<String,Object> attributes;
 
     public ResponseException(final ResponseStatusCode responseStatusCode, 
final String serverMessage) {
-        super(serverMessage);
-        this.responseStatusCode = responseStatusCode;
+        this(responseStatusCode, serverMessage, null, null);
     }
 
     public ResponseException(final ResponseStatusCode responseStatusCode, 
final String serverMessage,
                              final List<String> remoteExceptionHierarchy, 
final String remoteStackTrace) {
-        this(responseStatusCode, serverMessage);
-        this.remoteExceptionHierarchy = remoteExceptionHierarchy;
+        this(responseStatusCode, serverMessage, remoteExceptionHierarchy, 
remoteStackTrace, null);
+    }
+
+    public ResponseException(final ResponseStatusCode responseStatusCode, 
final String serverMessage,
+                             final List<String> remoteExceptionHierarchy, 
final String remoteStackTrace,
+                             final Map<String,Object> statusAttributes) {
+        super(serverMessage);
+        this.responseStatusCode = responseStatusCode;
+        this.remoteExceptionHierarchy = remoteExceptionHierarchy != null ? 
Collections.unmodifiableList(remoteExceptionHierarchy) : null;
         this.remoteStackTrace = remoteStackTrace;
+        this.attributes = statusAttributes != null ? 
Collections.unmodifiableMap(statusAttributes) : null;
     }
 
     public ResponseStatusCode getResponseStatusCode() {
@@ -61,4 +71,11 @@ public class ResponseException extends Exception {
     public Optional<List<String>> getRemoteExceptionHierarchy() {
         return Optional.ofNullable(remoteExceptionHierarchy);
     }
+
+    /**
+     * Gets any status attributes from the response.
+     */
+    public Optional<Map<String, Object>> getStatusAttributes() {
+        return Optional.ofNullable(attributes);
+    }
 }
\ No newline at end of file

Reply via email to