Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 6a44b82

Browse files
committed
Warn that bolt+routing:// isn't supported and fallback to bolt://
1 parent 3d8b7cc commit 6a44b82

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void setUp() throws Exception {
4444
commitCommand = new Commit(shell);
4545
beginCommand = new Begin(shell);
4646

47-
shell.connect(new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true));
47+
shell.connect(new ConnectionConfig(logger, "bolt://", "localhost", 7687, "neo4j", "neo", true));
4848
}
4949

5050
@After
@@ -84,7 +84,7 @@ public void connectTwiceThrows() throws CommandException {
8484
thrown.expect(CommandException.class);
8585
thrown.expectMessage("Already connected");
8686

87-
ConnectionConfig config = new ConnectionConfig("bolt://", "localhost", 7687, "neo4j", "neo", true);
87+
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "localhost", 7687, "neo4j", "neo", true);
8888
assertTrue("Shell should already be connected", shell.isConnected());
8989
shell.connect(config);
9090
}

cypher-shell/src/main/java/org/neo4j/shell/ConnectionConfig.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.neo4j.shell;
22

33
import org.neo4j.driver.v1.Config;
4+
import org.neo4j.shell.log.AnsiFormattedText;
5+
import org.neo4j.shell.log.Logger;
46

57
import javax.annotation.Nonnull;
68

@@ -12,14 +14,23 @@ public class ConnectionConfig {
1214
private String username;
1315
private String password;
1416

15-
public ConnectionConfig(@Nonnull String scheme, @Nonnull String host, int port, @Nonnull String username,
16-
@Nonnull String password, boolean encryption) {
17-
this.scheme = scheme;
17+
public ConnectionConfig(@Nonnull Logger logger, @Nonnull String scheme, @Nonnull String host, int port,
18+
@Nonnull String username, @Nonnull String password, boolean encryption) {
1819
this.host = host;
1920
this.port = port;
2021
this.username = fallbackToEnvVariable(username, "NEO4J_USERNAME");
2122
this.password = fallbackToEnvVariable(password, "NEO4J_PASSWORD");
2223
this.encryption = encryption ? Config.EncryptionLevel.REQUIRED : Config.EncryptionLevel.NONE;
24+
25+
if ("bolt+routing://".equalsIgnoreCase(scheme)) {
26+
logger.printError(
27+
AnsiFormattedText.s()
28+
.colorRed()
29+
.append("Routing is not supported by cypher-shell. Falling back to direct connection.")
30+
.formattedString());
31+
scheme = "bolt://";
32+
}
33+
this.scheme = scheme;
2334
}
2435

2536
/**

cypher-shell/src/main/java/org/neo4j/shell/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String[] args) {
4949
}
5050

5151
static String getWelcomeMessage(@Nonnull ConnectionConfig connectionConfig,
52-
@Nonnull String serverVersion) {
52+
@Nonnull String serverVersion) {
5353
String neo4j = "Neo4j";
5454
if (!serverVersion.isEmpty()) {
5555
neo4j += " " + serverVersion;
@@ -80,19 +80,19 @@ void startShell(@Nonnull CliArgs cliArgs) {
8080
out.println("Cypher-Shell " + Build.version());
8181
return;
8282
}
83+
Logger logger = new AnsiLogger(cliArgs.getDebugMode());
84+
logger.setFormat(cliArgs.getFormat());
8385

8486
ConnectionConfig connectionConfig = new ConnectionConfig(
87+
logger,
8588
cliArgs.getScheme(),
8689
cliArgs.getHost(),
8790
cliArgs.getPort(),
8891
cliArgs.getUsername(),
8992
cliArgs.getPassword(),
9093
cliArgs.getEncryption());
9194

92-
Logger logger = new AnsiLogger(cliArgs.getDebugMode());
9395
try {
94-
logger.setFormat(cliArgs.getFormat());
95-
9696
CypherShell shell = new CypherShell(logger);
9797
connectInteractively(shell, connectionConfig);
9898

cypher-shell/src/test/java/org/neo4j/shell/ConnectionConfigTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import org.junit.Test;
44
import org.neo4j.driver.v1.Config;
5+
import org.neo4j.shell.log.Logger;
56

67
import static org.junit.Assert.assertEquals;
8+
import static org.mockito.Mockito.mock;
9+
import static org.mockito.Mockito.verify;
710

811
public class ConnectionConfigTest {
9-
ConnectionConfig config = new ConnectionConfig("bolt://", "localhost", 1, "bob", "pass", false);
12+
private Logger logger = mock(Logger.class);
13+
private ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "localhost", 1, "bob",
14+
"pass", false);
1015

1116
@Test
1217
public void scheme() throws Exception {
@@ -39,17 +44,18 @@ public void driverUrlDefaultScheme() throws Exception {
3944
}
4045

4146
@Test
42-
public void driverUrlExplicitScheme() throws Exception {
43-
ConnectionConfig config = new ConnectionConfig("bolt+routing://", "localhost", 1, "bob",
47+
public void driverUrlRoutingScheme() throws Exception {
48+
ConnectionConfig config = new ConnectionConfig(logger, "bolt+routing://", "localhost", 1, "bob",
4449
"pass", false);
45-
assertEquals("bolt+routing://localhost:1", config.driverUrl());
50+
verify(logger).printError("@|RED Routing is not supported by cypher-shell. Falling back to direct connection.|@");
51+
assertEquals("bolt://localhost:1", config.driverUrl());
4652
}
4753

4854
@Test
4955
public void encryption() {
5056
assertEquals(Config.EncryptionLevel.REQUIRED,
51-
new ConnectionConfig("bolt://", "", -1, "", "", true).encryption());
57+
new ConnectionConfig(logger, "bolt://", "", -1, "", "", true).encryption());
5258
assertEquals(Config.EncryptionLevel.NONE,
53-
new ConnectionConfig("bolt://", "", -1, "", "", false).encryption());
59+
new ConnectionConfig(logger, "bolt://", "", -1, "", "", false).encryption());
5460
}
5561
}

cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setup() {
5858

5959
@Test
6060
public void verifyDelegationOfConnectionMethods() throws CommandException {
61-
ConnectionConfig cc = new ConnectionConfig("bolt://", "", 1, "", "", false);
61+
ConnectionConfig cc = new ConnectionConfig(logger, "bolt://", "", 1, "", "", false);
6262
CypherShell shell = new CypherShell(logger, mockedBoltStateHandler, mockedPrettyPrinter);
6363

6464
shell.connect(cc);

cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public String server() {
6464
}
6565
};
6666
BoltStateHandler handler = new BoltStateHandler(provider);
67-
ConnectionConfig config = new ConnectionConfig( "bolt://", "", -1, "", "", false);
67+
ConnectionConfig config = new ConnectionConfig( logger, "bolt://", "", -1, "", "", false);
6868
handler.connect(config);
6969

7070
assertEquals("", handler.getServerVersion());
@@ -90,7 +90,7 @@ public String server() {
9090
}
9191
};
9292
BoltStateHandler handler = new BoltStateHandler(provider);
93-
ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", false);
93+
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "", -1, "", "", false);
9494
handler.connect(config);
9595

9696
assertEquals("9.4.1-ALPHA", handler.getServerVersion());
@@ -270,7 +270,7 @@ public void silentDisconnectCleansUp() throws Exception {
270270
public void turnOffEncryptionIfRequested() throws CommandException {
271271
RecordingDriverProvider provider = new RecordingDriverProvider();
272272
BoltStateHandler handler = new BoltStateHandler(provider);
273-
ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", false);
273+
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "", -1, "", "", false);
274274
handler.connect(config);
275275
assertEquals(Config.EncryptionLevel.NONE, provider.config.encryptionLevel());
276276
}
@@ -279,7 +279,7 @@ public void turnOffEncryptionIfRequested() throws CommandException {
279279
public void turnOnEncryptionIfRequested() throws CommandException {
280280
RecordingDriverProvider provider = new RecordingDriverProvider();
281281
BoltStateHandler handler = new BoltStateHandler(provider);
282-
ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", true);
282+
ConnectionConfig config = new ConnectionConfig(logger, "bolt://", "", -1, "", "", true);
283283
handler.connect(config);
284284
assertEquals(Config.EncryptionLevel.REQUIRED, provider.config.encryptionLevel());
285285
}
@@ -297,7 +297,7 @@ public Transaction getCurrentTransaction() {
297297
}
298298

299299
public void connect() throws CommandException {
300-
connect(new ConnectionConfig("bolt://", "", 1, "", "", false));
300+
connect(new ConnectionConfig(mock(Logger.class), "bolt://", "", 1, "", "", false));
301301
}
302302
}
303303

0 commit comments

Comments
 (0)