This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2110
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 2e891274f9e5e9a6a8e3cba5b5273860a9f49004
Author: Stephen Mallette <[email protected]>
AuthorDate: Mon Dec 17 13:30:45 2018 -0500

    TINKERPOP-2110 Added option to change path for java driver
---
 CHANGELOG.asciidoc                                 |  1 +
 .../apache/tinkerpop/gremlin/driver/Cluster.java   | 24 +++++++++++++++++-----
 .../org/apache/tinkerpop/gremlin/driver/Host.java  |  6 +++---
 .../apache/tinkerpop/gremlin/driver/Settings.java  |  5 +++++
 .../apache/tinkerpop/gremlin/driver/HostTest.java  | 10 ++++++++-
 .../gremlin/server/AbstractChannelizer.java        |  1 -
 .../server/channel/WebSocketChannelizer.java       |  3 ++-
 7 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 5e6dcb2..f3bd2d0 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -30,6 +30,7 @@ This release also includes changes from <<release-3-2-11, 
3.2.11>>.
 * Fixed a bug in `CoalesceStep` which squared the bulk if the step followed a 
`Barrier` step.
 * Fixed a bug in `GroupStep` that assigned wrong reducing bi-operators
 * Added `:bytecode` command to help developers debugging `Bytecode`-based 
traversals.
+* Added option to set the path for the URI on the Java driver.
 * Fixed `PersistedOutputRDD` to eager persist RDD by adding `count()` action 
calls.
 * Deserialized `g:Set` to a Python `Set` in GraphSON in `gremlin-python`.
 * Deprecated `StarGraph.builder()` and `StarGraph.Builder.build()` in favor of 
the more common "builder" patterns of `build()` and `create()` respectively.
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
index c6891c2..113f081 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
@@ -31,10 +31,6 @@ import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import org.apache.commons.lang3.concurrent.BasicThreadFactory;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
-import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -182,6 +178,7 @@ public final class Cluster {
 
         final Builder builder = new Builder(settings.hosts.get(0))
                 .port(settings.port)
+                .path(settings.path)
                 .enableSsl(settings.connectionPool.enableSsl)
                 
.trustCertificateChainFile(settings.connectionPool.trustCertChainFile)
                 .keepAliveInterval(settings.connectionPool.keepAliveInterval)
@@ -297,6 +294,13 @@ public final class Cluster {
     }
 
     /**
+     * Gets the path to the Gremlin service.
+     */
+    public String getPath() {
+        return manager.path;
+    }
+
+    /**
      * Size of the pool for handling request/response operations.
      */
     public int getNioPoolSize() {
@@ -550,6 +554,7 @@ public final class Cluster {
     public final static class Builder {
         private List<InetAddress> addresses = new ArrayList<>();
         private int port = 8182;
+        private String path = "/gremlin";
         private MessageSerializer serializer = 
Serializers.GRYO_V3D0.simpleInstance();
         private int nioPoolSize = Runtime.getRuntime().availableProcessors();
         private int workerPoolSize = 
Runtime.getRuntime().availableProcessors() * 2;
@@ -610,6 +615,14 @@ public final class Cluster {
         }
 
         /**
+         * The path to the Gremlin service on the host which is "/gremlin" by 
default.
+         */
+        public Builder path(final String path) {
+            this.path = path;
+            return this;
+        }
+
+        /**
          * Set the {@link MessageSerializer} to use given the exact name of a 
{@link Serializers} enum.  Note that
          * setting this value this way will not allow specific configuration 
of the serializer itself.  If specific
          * configuration is required * please use {@link 
#serializer(MessageSerializer)}.
@@ -1029,6 +1042,7 @@ public final class Cluster {
         private final int nioPoolSize;
         private final int workerPoolSize;
         private final int port;
+        private final String path;
 
         private final AtomicReference<CompletableFuture<Void>> closeFuture = 
new AtomicReference<>();
 
@@ -1075,6 +1089,7 @@ public final class Cluster {
             nioPoolSize = builder.nioPoolSize;
             workerPoolSize = builder.workerPoolSize;
             port = builder.port;
+            path = builder.path;
 
             this.factory = new Factory(builder.nioPoolSize);
             this.serializer = builder.serializer;
@@ -1134,7 +1149,6 @@ public final class Cluster {
 
             if (builder.workerPoolSize < 1)
                 throw new IllegalArgumentException("workerPoolSize must be 
greater than zero");
-
         }
 
         synchronized void init() {
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
index 52f4d78..1dab315 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Host.java
@@ -48,7 +48,7 @@ public final class Host {
     Host(final InetSocketAddress address, final Cluster cluster) {
         this.cluster = cluster;
         this.address = address;
-        this.hostUri = makeUriFromAddress(address, 
cluster.connectionPoolSettings().enableSsl);
+        this.hostUri = makeUriFromAddress(address, cluster.getPath(), 
cluster.connectionPoolSettings().enableSsl);
         hostLabel = String.format("Host{address=%s, hostUri=%s}", address, 
hostUri);
     }
 
@@ -90,10 +90,10 @@ public final class Host {
         makeAvailable();
     }
 
-    private static URI makeUriFromAddress(final InetSocketAddress addy, final 
boolean ssl) {
+    private static URI makeUriFromAddress(final InetSocketAddress addy, final 
String path, final boolean ssl) {
         try {
             final String scheme = ssl ? "wss" : "ws";
-            return new URI(scheme, null, addy.getHostName(), addy.getPort(), 
"/gremlin", null, null);
+            return new URI(scheme, null, addy.getHostName(), addy.getPort(), 
path, null, null);
         } catch (URISyntaxException use) {
             throw new RuntimeException(String.format("URI for host could not 
be constructed from: %s", addy), use);
         }
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
index 61edd86..4b339de 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
@@ -48,6 +48,11 @@ final class Settings {
     public int port = 8182;
 
     /**
+     * The path to the Gremlin service which is defaulted to "/gremlin".
+     */
+    public String path = "/gremlin";
+
+    /**
      * The list of hosts that the driver will connect to.
      */
     public List<String> hosts = new ArrayList<>();
diff --git 
a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
index cef9a82..2c20261 100644
--- 
a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
+++ 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/HostTest.java
@@ -31,11 +31,19 @@ import static org.junit.Assert.assertEquals;
 public class HostTest {
 
     @Test
-    public void shouldConstructHost() {
+    public void shouldConstructHostWithDefaultPath() {
         final InetSocketAddress addy = new InetSocketAddress("localhost", 
8182);
         final Host host = new Host(addy, Cluster.open());
         final URI webSocketUri = host.getHostUri();
         assertEquals("ws://localhost:8182/gremlin", webSocketUri.toString());
     }
 
+    @Test
+    public void shouldConstructHostWithCustomPath() {
+        final InetSocketAddress addy = new InetSocketAddress("localhost", 
8183);
+        final Host host = new Host(addy, 
Cluster.build().port(8183).path("/argh").create());
+        final URI webSocketUri = host.getHostUri();
+        assertEquals("ws://localhost:8183/argh", webSocketUri.toString());
+    }
+
 }
diff --git 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
index 5f4f228..60298a2 100644
--- 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
+++ 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.server;
 
-import io.netty.channel.EventLoopGroup;
 import io.netty.handler.ssl.ClientAuth;
 import io.netty.handler.ssl.SslContext;
 import io.netty.handler.ssl.SslContextBuilder;
diff --git 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
index 157263b..8706208 100644
--- 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
+++ 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/channel/WebSocketChannelizer.java
@@ -95,7 +95,8 @@ public class WebSocketChannelizer extends AbstractChannelizer 
{
 
         pipeline.addLast(PIPELINE_HTTP_RESPONSE_ENCODER, new 
HttpResponseEncoder());
 
-        pipeline.addLast(PIPELINE_REQUEST_HANDLER, new 
WebSocketServerProtocolHandler(GREMLIN_ENDPOINT, null, false, 
settings.maxContentLength));
+        pipeline.addLast(PIPELINE_REQUEST_HANDLER, new 
WebSocketServerProtocolHandler(GREMLIN_ENDPOINT,
+                null, false, settings.maxContentLength));
 
         if (logger.isDebugEnabled())
             pipeline.addLast(new LoggingHandler("log-aggregator-encoder", 
LogLevel.DEBUG));

Reply via email to