Skip to content

Commit 7856cf8

Browse files
committed
Deprecated and replaced ServerInfo.version()
1 parent 0d8b671 commit 7856cf8

25 files changed

+341
-46
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
<differences>
2-
<!--4.0 drivers is not API compatible with 1.0 drivers, as a result we reset API differences from 4.0.0-->
2+
<!--4.0 drivers is not API compatible with 1.0 drivers, as a result we reset API differences from 4.0.0-->
3+
4+
<difference>
5+
<className>org/neo4j/driver/summary/ServerInfo</className>
6+
<differenceType>7007</differenceType>
7+
<method>java.lang.String version()</method>
8+
</difference>
9+
10+
<difference>
11+
<className>org/neo4j/driver/summary/ServerInfo</className>
12+
<differenceType>7012</differenceType>
13+
<method>java.lang.String protocolVersion()</method>
14+
</difference>
15+
16+
<difference>
17+
<className>org/neo4j/driver/summary/ServerInfo</className>
18+
<differenceType>7012</differenceType>
19+
<method>java.lang.String agent()</method>
20+
</difference>
21+
322
</differences>

driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class NetworkConnection implements Connection
5454
{
5555
private final Channel channel;
5656
private final InboundMessageDispatcher messageDispatcher;
57+
private final String serverAgent;
5758
private final BoltServerAddress serverAddress;
5859
private final ServerVersion serverVersion;
5960
private final BoltProtocol protocol;
@@ -69,6 +70,7 @@ public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Cloc
6970
{
7071
this.channel = channel;
7172
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
73+
this.serverAgent = ChannelAttributes.serverAgent( channel );
7274
this.serverAddress = ChannelAttributes.serverAddress( channel );
7375
this.serverVersion = ChannelAttributes.serverVersion( channel );
7476
this.protocol = BoltProtocol.forChannel( channel );
@@ -185,6 +187,12 @@ public void terminateAndRelease( String reason )
185187
}
186188
}
187189

190+
@Override
191+
public String serverAgent()
192+
{
193+
return serverAgent;
194+
}
195+
188196
@Override
189197
public BoltServerAddress serverAddress()
190198
{

driver/src/main/java/org/neo4j/driver/internal/async/connection/ChannelAttributes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class ChannelAttributes
3333
private static final AttributeKey<String> CONNECTION_ID = newInstance( "connectionId" );
3434
private static final AttributeKey<String> POOL_ID = newInstance( "poolId" );
3535
private static final AttributeKey<BoltProtocolVersion> PROTOCOL_VERSION = newInstance( "protocolVersion" );
36+
private static final AttributeKey<String> SERVER_AGENT = newInstance( "serverAgent" );
3637
private static final AttributeKey<BoltServerAddress> ADDRESS = newInstance( "serverAddress" );
3738
private static final AttributeKey<ServerVersion> SERVER_VERSION = newInstance( "serverVersion" );
3839
private static final AttributeKey<Long> CREATION_TIMESTAMP = newInstance( "creationTimestamp" );
@@ -74,6 +75,16 @@ public static void setProtocolVersion( Channel channel, BoltProtocolVersion vers
7475
setOnce( channel, PROTOCOL_VERSION, version );
7576
}
7677

78+
public static void setServerAgent( Channel channel, String serverAgent )
79+
{
80+
setOnce( channel, SERVER_AGENT, serverAgent );
81+
}
82+
83+
public static String serverAgent( Channel channel )
84+
{
85+
return get( channel, SERVER_AGENT );
86+
}
87+
7788
public static BoltServerAddress serverAddress( Channel channel )
7889
{
7990
return get( channel, ADDRESS );

driver/src/main/java/org/neo4j/driver/internal/async/connection/DirectConnection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.concurrent.CompletionStage;
2222

23+
import org.neo4j.driver.AccessMode;
2324
import org.neo4j.driver.internal.BoltServerAddress;
2425
import org.neo4j.driver.internal.DatabaseName;
2526
import org.neo4j.driver.internal.DirectConnectionProvider;
@@ -28,7 +29,6 @@
2829
import org.neo4j.driver.internal.spi.Connection;
2930
import org.neo4j.driver.internal.spi.ResponseHandler;
3031
import org.neo4j.driver.internal.util.ServerVersion;
31-
import org.neo4j.driver.AccessMode;
3232

3333
/**
3434
* This is a connection used by {@link DirectConnectionProvider} to connect to a remote database.
@@ -111,6 +111,12 @@ public void terminateAndRelease( String reason )
111111
delegate.terminateAndRelease( reason );
112112
}
113113

114+
@Override
115+
public String serverAgent()
116+
{
117+
return delegate.serverAgent();
118+
}
119+
114120
@Override
115121
public BoltServerAddress serverAddress()
116122
{

driver/src/main/java/org/neo4j/driver/internal/async/connection/RoutingConnection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.concurrent.CompletionStage;
2222

23+
import org.neo4j.driver.AccessMode;
2324
import org.neo4j.driver.internal.BoltServerAddress;
2425
import org.neo4j.driver.internal.DatabaseName;
2526
import org.neo4j.driver.internal.RoutingErrorHandler;
@@ -29,7 +30,6 @@
2930
import org.neo4j.driver.internal.spi.Connection;
3031
import org.neo4j.driver.internal.spi.ResponseHandler;
3132
import org.neo4j.driver.internal.util.ServerVersion;
32-
import org.neo4j.driver.AccessMode;
3333

3434
/**
3535
* A connection used by the routing driver.
@@ -109,6 +109,12 @@ public void terminateAndRelease( String reason )
109109
delegate.terminateAndRelease( reason );
110110
}
111111

112+
@Override
113+
public String serverAgent()
114+
{
115+
return delegate.serverAgent();
116+
}
117+
112118
@Override
113119
public BoltServerAddress serverAddress()
114120
{

driver/src/main/java/org/neo4j/driver/internal/handlers/HelloResponseHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323

2424
import java.util.Map;
2525

26+
import org.neo4j.driver.Value;
2627
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
2728
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
2829
import org.neo4j.driver.internal.spi.ResponseHandler;
29-
import org.neo4j.driver.Value;
3030

3131
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setConnectionId;
32+
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerAgent;
3233
import static org.neo4j.driver.internal.async.connection.ChannelAttributes.setServerVersion;
3334
import static org.neo4j.driver.internal.util.MetadataExtractor.extractNeo4jServerVersion;
35+
import static org.neo4j.driver.internal.util.MetadataExtractor.extractServer;
3436
import static org.neo4j.driver.internal.util.ServerVersion.fromBoltProtocolVersion;
3537

3638
public class HelloResponseHandler implements ResponseHandler
@@ -53,6 +55,9 @@ public void onSuccess( Map<String,Value> metadata )
5355
{
5456
try
5557
{
58+
Value serverValue = extractServer( metadata );
59+
setServerAgent( channel, serverValue.asString() );
60+
5661
// From Server V4 extracting server from metadata in the success message is unreliable
5762
// so we fix the Server version against the Bolt Protocol version for Server V4 and above.
5863
if ( BoltProtocolV3.VERSION.equals( protocolVersion ) )

driver/src/main/java/org/neo4j/driver/internal/spi/Connection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public interface Connection
5151

5252
void terminateAndRelease( String reason );
5353

54+
String serverAgent();
55+
5456
BoltServerAddress serverAddress();
5557

5658
ServerVersion serverVersion();

driver/src/main/java/org/neo4j/driver/internal/summary/InternalServerInfo.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,29 @@
2121
import java.util.Objects;
2222

2323
import org.neo4j.driver.internal.BoltServerAddress;
24+
import org.neo4j.driver.internal.messaging.BoltProtocolVersion;
2425
import org.neo4j.driver.internal.util.ServerVersion;
2526
import org.neo4j.driver.summary.ServerInfo;
2627

2728
public class InternalServerInfo implements ServerInfo
2829
{
30+
private final String agent;
2931
private final String address;
3032
private final String version;
33+
private final String protocolVersion;
3134

32-
public InternalServerInfo( BoltServerAddress address, ServerVersion version )
35+
public InternalServerInfo( String agent, BoltServerAddress address, ServerVersion version, BoltProtocolVersion protocolVersion )
3336
{
37+
this.agent = agent;
3438
this.address = address.toString();
3539
this.version = version.toString();
40+
this.protocolVersion = protocolVersion.toString();
41+
}
42+
43+
@Override
44+
public String agent()
45+
{
46+
return agent;
3647
}
3748

3849
@Override
@@ -47,6 +58,12 @@ public String version()
4758
return version;
4859
}
4960

61+
@Override
62+
public String protocolVersion()
63+
{
64+
return protocolVersion;
65+
}
66+
5067
@Override
5168
public boolean equals( Object o )
5269
{

driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public long extractResultAvailableAfter( Map<String,Value> metadata )
100100

101101
public ResultSummary extractSummary(Query query, Connection connection, long resultAvailableAfter, Map<String,Value> metadata )
102102
{
103-
ServerInfo serverInfo = new InternalServerInfo( connection.serverAddress(), connection.serverVersion() );
103+
ServerInfo serverInfo =
104+
new InternalServerInfo( connection.serverAgent(), connection.serverAddress(), connection.serverVersion(), connection.protocol().version() );
104105
DatabaseInfo dbInfo = extractDatabaseInfo( metadata );
105106
return new InternalResultSummary(query, serverInfo, dbInfo, extractQueryType( metadata ), extractCounters( metadata ), extractPlan( metadata ),
106107
extractProfiledPlan( metadata ), extractNotifications( metadata ), resultAvailableAfter,
@@ -132,26 +133,29 @@ public static Bookmark extractBookmarks( Map<String,Value> metadata )
132133

133134
public static ServerVersion extractNeo4jServerVersion( Map<String,Value> metadata )
134135
{
135-
Value versionValue = metadata.get( "server" );
136-
if ( versionValue == null || versionValue.isNull() )
136+
Value serverValue = extractServer( metadata );
137+
ServerVersion server = ServerVersion.version( serverValue.asString() );
138+
if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) )
137139
{
138-
throw new UntrustedServerException( "Server provides no product identifier" );
140+
return server;
139141
}
140142
else
141143
{
142-
ServerVersion server = ServerVersion.version( versionValue.asString() );
143-
if ( ServerVersion.NEO4J_PRODUCT.equalsIgnoreCase( server.product() ) )
144-
{
145-
return server;
146-
}
147-
else
148-
{
149-
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" );
150-
}
144+
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance: '" + server.product() + "'" );
145+
}
146+
}
147+
148+
public static Value extractServer( Map<String,Value> metadata )
149+
{
150+
Value versionValue = metadata.get( "server" );
151+
if ( versionValue == null || versionValue.isNull() )
152+
{
153+
throw new UntrustedServerException( "Server provides no product identifier" );
151154
}
155+
return versionValue;
152156
}
153157

154-
private static QueryType extractQueryType(Map<String,Value> metadata )
158+
private static QueryType extractQueryType( Map<String,Value> metadata )
155159
{
156160
Value typeValue = metadata.get( "type" );
157161
if ( typeValue != null )

driver/src/main/java/org/neo4j/driver/summary/ServerInfo.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,27 @@ public interface ServerInfo
3131
String address();
3232

3333
/**
34-
* Returns a string telling which version of the server the query was executed.
35-
* Supported since neo4j 3.1.
34+
* Returns a string telling which version of the server the query was executed. Supported since neo4j 3.1.
35+
*
3636
* @return The server version.
37+
* @deprecated in 4.3, please use {@link ServerInfo#agent()}, {@link ServerInfo#protocolVersion()}, or call the <i>dbms.components</i> procedure instead.
38+
* <b>Method might be removed in the next major release.</b>
3739
*/
40+
@Deprecated
3841
String version();
42+
43+
/**
44+
* Returns Bolt protocol version with which the remote server communicates. This is returned as a string in format X.Y where X is the major version and Y is
45+
* the minor version.
46+
*
47+
* @return The Bolt protocol version.
48+
*/
49+
String protocolVersion();
50+
51+
/**
52+
* Returns server agent string by which the remote server identifies itself.
53+
*
54+
* @return The agent string.
55+
*/
56+
String agent();
3957
}

driver/src/test/java/org/neo4j/driver/internal/InternalResultTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.neo4j.driver.internal.handlers.PullResponseCompletionListener;
4040
import org.neo4j.driver.internal.handlers.RunResponseHandler;
4141
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
42+
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
4243
import org.neo4j.driver.internal.spi.Connection;
4344
import org.neo4j.driver.internal.value.NullValue;
4445
import org.neo4j.driver.util.Pair;
@@ -360,6 +361,8 @@ private Result createResult(int numberOfRecords )
360361
Connection connection = mock( Connection.class );
361362
when( connection.serverAddress() ).thenReturn( LOCAL_DEFAULT );
362363
when( connection.serverVersion() ).thenReturn( anyServerVersion() );
364+
when( connection.protocol() ).thenReturn( BoltProtocolV43.INSTANCE );
365+
when( connection.serverAgent() ).thenReturn( "Neo4j/4.2.5" );
363366
PullAllResponseHandler pullAllHandler =
364367
new LegacyPullAllResponseHandler( query, runHandler, connection, BoltProtocolV3.METADATA_EXTRACTOR,
365368
mock( PullResponseCompletionListener.class ) );

driver/src/test/java/org/neo4j/driver/internal/async/AsyncResultCursorImplTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.neo4j.driver.internal.handlers.PullAllResponseHandler;
3838
import org.neo4j.driver.internal.handlers.RunResponseHandler;
3939
import org.neo4j.driver.internal.messaging.v3.BoltProtocolV3;
40+
import org.neo4j.driver.internal.messaging.v43.BoltProtocolV43;
4041
import org.neo4j.driver.internal.summary.InternalResultSummary;
4142
import org.neo4j.driver.internal.summary.InternalServerInfo;
4243
import org.neo4j.driver.internal.summary.InternalSummaryCounters;
@@ -86,10 +87,13 @@ void shouldReturnSummary()
8687
{
8788
PullAllResponseHandler pullAllHandler = mock( PullAllResponseHandler.class );
8889

89-
ResultSummary summary = new InternalResultSummary( new Query( "RETURN 42" ),
90-
new InternalServerInfo( BoltServerAddress.LOCAL_DEFAULT, anyServerVersion() ), DEFAULT_DATABASE_INFO, QueryType.SCHEMA_WRITE,
90+
ResultSummary summary = new InternalResultSummary(
91+
new Query( "RETURN 42" ),
92+
new InternalServerInfo( "Neo4j/4.2.5", BoltServerAddress.LOCAL_DEFAULT, anyServerVersion(), BoltProtocolV43.VERSION ),
93+
DEFAULT_DATABASE_INFO, QueryType.SCHEMA_WRITE,
9194
new InternalSummaryCounters( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 ),
92-
null, null, emptyList(), 42, 42 );
95+
null, null, emptyList(), 42, 42
96+
);
9397
when( pullAllHandler.consumeAsync() ).thenReturn( completedFuture( summary ) );
9498

9599
AsyncResultCursorImpl cursor = newCursor( pullAllHandler );

driver/src/test/java/org/neo4j/driver/internal/async/NetworkConnectionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,31 @@ void shouldNotWriteAndFlushMultipleMessagesWhenTerminated()
348348
assertConnectionTerminatedError( failureCaptor.getValue() );
349349
}
350350

351+
@Test
352+
void shouldReturnServerAgentWhenCreated()
353+
{
354+
EmbeddedChannel channel = newChannel();
355+
String agent = "Neo4j/4.2.5";
356+
ChannelAttributes.setServerAgent( channel, agent );
357+
358+
NetworkConnection connection = newConnection( channel );
359+
360+
assertEquals( agent, connection.serverAgent() );
361+
}
362+
363+
@Test
364+
void shouldReturnServerAgentWhenReleased()
365+
{
366+
EmbeddedChannel channel = newChannel();
367+
String agent = "Neo4j/4.2.5";
368+
ChannelAttributes.setServerAgent( channel, agent );
369+
370+
NetworkConnection connection = newConnection( channel );
371+
connection.release();
372+
373+
assertEquals( agent, connection.serverAgent() );
374+
}
375+
351376
@Test
352377
void shouldReturnServerAddressWhenReleased()
353378
{

0 commit comments

Comments
 (0)