11/**
22 * Copyright (c) 2002-2016 "Neo Technology,"
33 * Network Engine for Objects in Lund AB [http://neotechnology.com]
4- *
4+ * <p>
55 * This file is part of Neo4j.
6- *
6+ * <p>
77 * Licensed under the Apache License, Version 2.0 (the "License");
88 * you may not use this file except in compliance with the License.
99 * 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>
1313 * Unless required by applicable law or agreed to in writing, software
1414 * distributed under the License is distributed on an "AS IS" BASIS,
1515 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,6 +40,7 @@ public class SocketClient
4040{
4141 private static final int MAGIC_PREAMBLE = 0x6060B017 ;
4242 private static final int VERSION1 = 1 ;
43+ private static final int HTTP = 1213486160 ;//== 0x48545450 == "HTTP"
4344 private static final int NO_VERSION = 0 ;
4445 private static final int [] SUPPORTED_VERSIONS = new int []{VERSION1 , NO_VERSION , NO_VERSION , NO_VERSION };
4546
@@ -127,7 +128,8 @@ public void receiveOne( SocketResponseHandler handler ) throws IOException
127128 reader .read ( handler );
128129
129130 // 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
131133 if ( handler .protocolViolationErrorOccurred () )
132134 {
133135 stop ();
@@ -139,7 +141,7 @@ public void stop()
139141 {
140142 try
141143 {
142- if ( channel != null )
144+ if ( channel != null )
143145 {
144146 logger .debug ( "~~ [CLOSE]" );
145147 channel .close ();
@@ -148,13 +150,13 @@ public void stop()
148150 }
149151 catch ( IOException e )
150152 {
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" ) )
152154 {
153155 // Swallow this exception as it is caused by connection already closed by server
154156 }
155157 else
156158 {
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 );
158160 }
159161 }
160162 }
@@ -192,11 +194,17 @@ private SocketProtocol negotiateProtocol() throws IOException
192194 case VERSION1 :
193195 logger .debug ( "~~ [HANDSHAKE] 1" );
194196 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 );
200208 }
201209 }
202210
@@ -236,7 +244,7 @@ public static ByteChannel create( String host, int port, Config config, Logger l
236244 throw new ClientException ( "Unknown TLS Level: " + config .encryptionLevel () );
237245 }
238246
239- if ( logger .isTraceEnabled () )
247+ if ( logger .isTraceEnabled () )
240248 {
241249 channel = new LoggingByteChannel ( channel , logger );
242250 }
0 commit comments