You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/08/16 15:40:37 UTC
[49/50] tinkerpop git commit: TINKERPOP-1913 ResponseException will
have status attributes present
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/9c22174c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9c22174c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9c22174c
Branch: refs/heads/TINKERPOP-1913
Commit: 9c22174c38a0a07357c155c393952f661bcd9fd8
Parents: b934d2f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 16 10:38:48 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 16 10:38:48 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/9c22174c/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 4677bee..dcfc4b9 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
@@ -255,7 +255,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)));
}
}
@@ -269,6 +269,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 {
@@ -293,6 +294,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/9c22174c/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