You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2018/08/23 12:51:45 UTC

[05/17] tinkerpop git commit: Submit can accept an existing requestId. Args supplied to _getRequest are run through the GraphSONWriter. Improved promise error handling on authenticator challenge. Tidying up of code formatting and documentation. Integrati

Submit can accept an existing requestId.
Args supplied to _getRequest are run through the GraphSONWriter.
Improved promise error handling on authenticator challenge.
Tidying up of code formatting and documentation.
Integration test updated to use secure gremlin server port.


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

Branch: refs/heads/master
Commit: f67fea49da3ca788f39c3824c3398f1a7aae65f0
Parents: 0e05499
Author: Matthew Allen <ma...@runbox.com>
Authored: Wed Jul 11 21:38:56 2018 +0100
Committer: Matthew Allen <ma...@runbox.com>
Committed: Thu Aug 23 06:37:55 2018 +0100

----------------------------------------------------------------------
 .../lib/driver/driver-remote-connection.js      | 50 +++++++++++++++-----
 .../lib/driver/remote-connection.js             |  5 +-
 .../gremlin-javascript/test/helper.js           |  8 ++++
 3 files changed, 49 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f67fea49/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
index facc0b8..bec599b 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
@@ -105,19 +105,25 @@ class DriverRemoteConnection extends RemoteConnection {
   }
 
   /** @override */
-  submit(bytecode, op, args) {
+  submit(bytecode, op, args, requestId) {
     return this.open().then(() => new Promise((resolve, reject) => {
-      const requestId = utils.getUuid();
-      this._responseHandlers[requestId] = {
-        callback: (err, result) => err ? reject(err) : resolve(result),
-        result: null
-      };
+      if (requestId === null || requestId === undefined) {
+        requestId = utils.getUuid();
+        this._responseHandlers[requestId] = {
+          callback: (err, result) => err ? reject(err) : resolve(result),
+          result: null
+        };
+      }
       const message = bufferFromString(this._header + JSON.stringify(this._getRequest(requestId, bytecode, op, args)));
       this._ws.send(message);
     }));
   }
 
   _getRequest(id, bytecode, op, args) {
+    if (args) {
+      args = this._adaptArgs(args);
+    }
+
     return ({
       'requestId': { '@type': 'g:UUID', '@value': id },
       'op': op || 'bytecode',
@@ -158,12 +164,10 @@ class DriverRemoteConnection extends RemoteConnection {
 
     if (response.status.code === responseStatusCode.authenticationChallenge && this._authenticator) {
       this._authenticator.evaluateChallenge(response).then(res => {
-        this.submit('', 'authentication', res);
-      }, err => {
-        return handler.callback(err);
-      });
-       
-       return;
+        return this.submit(null, 'authentication', res, response.requestId);
+      }).catch(handler.callback);
+
+      return;
     }
     else if (response.status.code >= 400) {
       // callback in error
@@ -200,6 +204,28 @@ class DriverRemoteConnection extends RemoteConnection {
   }
 
   /**
+   * Takes the given args map and ensures all arguments are passed through to _write.adaptObject
+   * @param {Object} args Map of arguments to process
+   * @returns {Object}
+   * @private
+   */
+  _adaptArgs(args) {
+    if (Array.isArray(args)) {
+      return args.map(val => this._adaptArgs(val));
+    }
+
+    if (args instanceof Object) {
+      let newObj = {};
+      Object.keys(args).forEach((key, val) => {
+        newObj[key] = this._adaptArgs(val);
+      });
+      return newObj;
+    }
+    
+    return this._writer.adaptObject(args);
+  }
+
+  /**
    * Closes the Connection.
    * @return {Promise}
    */

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f67fea49/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
index 46918df..be6f962 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/remote-connection.js
@@ -34,10 +34,11 @@ class RemoteConnection {
    * @abstract
    * @param {Bytecode} bytecode
    * @param {String} op Operation to perform, defaults to bytecode.
-   * @param {Object} args The arguments for the operation. Defaults to
+   * @param {Object} args The arguments for the operation. Defaults to an associative array containing values for "aliases" and "gremlin" keyss.
+   * @param {String} requestId A requestId for the current request. If none provided then a requestId is generated internally.
    * @returns {Promise}
    */
-  submit(bytecode, op, args) {
+  submit(bytecode, op, args, requestId) {
     throw new Error('submit() was not implemented');
   };
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f67fea49/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
index 546840e..99fea7f 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js
@@ -26,4 +26,12 @@ const DriverRemoteConnection = require('../lib/driver/driver-remote-connection')
 
 exports.getConnection = function getConnection(traversalSource) {
   return new DriverRemoteConnection('ws://localhost:45940/gremlin', { traversalSource: traversalSource });
+<<<<<<< HEAD
+=======
+};
+
+exports.getSecureConnectionWithAuthenticator = function getConnection(traversalSource) {
+  const authenticator = new SaslAuthenticator({ username: 'stephen', password: 'password' });
+  return new DriverRemoteConnection('wss://localhost:45941/gremlin', { traversalSource: traversalSource, authenticator: authenticator, rejectUnauthorized: false });
+>>>>>>> 65de11c3c8... Submit can accept an existing requestId.
 };
\ No newline at end of file