1
1
/**
2
2
* Copyright (c) 2002-2016 "Neo Technology,"
3
3
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4
- *
4
+ * <p>
5
5
* This file is part of Neo4j.
6
- *
6
+ * <p>
7
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
8
* you may not use this file except in compliance with the License.
9
9
* You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
10
+ * <p>
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ * <p>
13
13
* Unless required by applicable law or agreed to in writing, software
14
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,6 +40,7 @@ public class SocketClient
40
40
{
41
41
private static final int MAGIC_PREAMBLE = 0x6060B017 ;
42
42
private static final int VERSION1 = 1 ;
43
+ private static final int HTTP = 1213486160 ;//== 0x48545450 == "HTTP"
43
44
private static final int NO_VERSION = 0 ;
44
45
private static final int [] SUPPORTED_VERSIONS = new int []{VERSION1 , NO_VERSION , NO_VERSION , NO_VERSION };
45
46
@@ -127,7 +128,8 @@ public void receiveOne( SocketResponseHandler handler ) throws IOException
127
128
reader .read ( handler );
128
129
129
130
// TODO: all the errors come from the following trace should result in the termination of this channel
130
- // https://github.com/neo4j/neo4j/blob/3.0/community/bolt/src/main/java/org/neo4j/bolt/v1/transport/BoltProtocolV1.java#L86
131
+ // https://github.com/neo4j/neo4j/blob/3
132
+ // .0/community/bolt/src/main/java/org/neo4j/bolt/v1/transport/BoltProtocolV1.java#L86
131
133
if ( handler .protocolViolationErrorOccurred () )
132
134
{
133
135
stop ();
@@ -139,7 +141,7 @@ public void stop()
139
141
{
140
142
try
141
143
{
142
- if ( channel != null )
144
+ if ( channel != null )
143
145
{
144
146
logger .debug ( "~~ [CLOSE]" );
145
147
channel .close ();
@@ -148,13 +150,13 @@ public void stop()
148
150
}
149
151
catch ( IOException e )
150
152
{
151
- if ( e .getMessage ().equals ( "An existing connection was forcibly closed by the remote host" ) )
153
+ if ( e .getMessage ().equals ( "An existing connection was forcibly closed by the remote host" ) )
152
154
{
153
155
// Swallow this exception as it is caused by connection already closed by server
154
156
}
155
157
else
156
158
{
157
- throw new ClientException ("Unable to close socket connection properly." + e .getMessage (), e );
159
+ throw new ClientException ( "Unable to close socket connection properly." + e .getMessage (), e );
158
160
}
159
161
}
160
162
}
@@ -192,11 +194,17 @@ private SocketProtocol negotiateProtocol() throws IOException
192
194
case VERSION1 :
193
195
logger .debug ( "~~ [HANDSHAKE] 1" );
194
196
return new SocketProtocolV1 ( channel );
195
- case NO_VERSION : throw new ClientException ( "The server does not support any of the protocol versions supported by " +
196
- "this driver. Ensure that you are using driver and server versions that " +
197
- "are compatible with one another." );
198
- default : throw new ClientException ( "Protocol error, server suggested unexpected protocol version: " +
199
- proposal );
197
+ case NO_VERSION :
198
+ throw new ClientException ( "The server does not support any of the protocol versions supported by " +
199
+ "this driver. Ensure that you are using driver and server versions that " +
200
+ "are compatible with one another." );
201
+ case HTTP :
202
+ throw new ClientException (
203
+ "Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
204
+ "(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)" );
205
+ default :
206
+ throw new ClientException ( "Protocol error, server suggested unexpected protocol version: " +
207
+ proposal );
200
208
}
201
209
}
202
210
@@ -236,7 +244,7 @@ public static ByteChannel create( String host, int port, Config config, Logger l
236
244
throw new ClientException ( "Unknown TLS Level: " + config .encryptionLevel () );
237
245
}
238
246
239
- if ( logger .isTraceEnabled () )
247
+ if ( logger .isTraceEnabled () )
240
248
{
241
249
channel = new LoggingByteChannel ( channel , logger );
242
250
}
0 commit comments