31
31
import com .github .shyiko .mysql .binlog .io .ByteArrayInputStream ;
32
32
import com .github .shyiko .mysql .binlog .jmx .BinaryLogClientMXBean ;
33
33
import com .github .shyiko .mysql .binlog .network .AuthenticationException ;
34
+ import com .github .shyiko .mysql .binlog .network .ServerException ;
34
35
import com .github .shyiko .mysql .binlog .network .SocketFactory ;
35
36
import com .github .shyiko .mysql .binlog .network .protocol .ErrorPacket ;
36
37
import com .github .shyiko .mysql .binlog .network .protocol .GreetingPacket ;
@@ -310,7 +311,8 @@ public void setThreadFactory(ThreadFactory threadFactory) {
310
311
311
312
/**
312
313
* Connect to the replication stream. Note that this method blocks until disconnected.
313
- * @throws AuthenticationException in case of failed authentication
314
+ * @throws AuthenticationException if authentication fails
315
+ * @throws ServerException if MySQL server responds with an error
314
316
* @throws IOException if anything goes wrong while trying to connect
315
317
*/
316
318
public void connect () throws IOException {
@@ -327,7 +329,7 @@ public void connect() throws IOException {
327
329
}
328
330
} catch (IOException e ) {
329
331
throw new IOException ("Failed to connect to MySQL on " + hostname + ":" + port +
330
- ". Please make sure it's running." , e );
332
+ ". Please make sure it's running." , e );
331
333
}
332
334
GreetingPacket greetingPacket = new GreetingPacket (channel .read ());
333
335
authenticate (greetingPacket .getScramble (), greetingPacket .getServerCollation ());
@@ -409,7 +411,9 @@ private void authenticate(String salt, int collation) throws IOException {
409
411
if (authenticationResult [0 ] != (byte ) 0x00 /* ok */ ) {
410
412
if (authenticationResult [0 ] == (byte ) 0xFF /* error */ ) {
411
413
byte [] bytes = Arrays .copyOfRange (authenticationResult , 1 , authenticationResult .length );
412
- throw new AuthenticationException (new ErrorPacket (bytes ).getErrorMessage ());
414
+ ErrorPacket errorPacket = new ErrorPacket (bytes );
415
+ throw new AuthenticationException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
416
+ errorPacket .getSqlState ());
413
417
}
414
418
throw new AuthenticationException ("Unexpected authentication result (" + authenticationResult [0 ] + ")" );
415
419
}
@@ -476,9 +480,10 @@ boolean isKeepAliveThreadRunning() {
476
480
/**
477
481
* Connect to the replication stream in a separate thread.
478
482
* @param timeoutInMilliseconds timeout in milliseconds
479
- * @throws AuthenticationException in case of failed authentication
483
+ * @throws AuthenticationException if authentication fails
484
+ * @throws ServerException if MySQL server responds with an error
480
485
* @throws IOException if anything goes wrong while trying to connect
481
- * @throws TimeoutException if client wasn't able to connect in the requested period of time
486
+ * @throws TimeoutException if client was unable to connect within given time limit
482
487
*/
483
488
public void connect (long timeoutInMilliseconds ) throws IOException , TimeoutException {
484
489
final CountDownLatch countDownLatch = new CountDownLatch (1 );
@@ -553,7 +558,9 @@ private void confirmSupportOfChecksum(ChecksumType checksumType) throws IOExcept
553
558
byte [] statementResult = channel .read ();
554
559
if (statementResult [0 ] == (byte ) 0xFF /* error */ ) {
555
560
byte [] bytes = Arrays .copyOfRange (statementResult , 1 , statementResult .length );
556
- throw new IOException (new ErrorPacket (bytes ).getErrorMessage ());
561
+ ErrorPacket errorPacket = new ErrorPacket (bytes );
562
+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
563
+ errorPacket .getSqlState ());
557
564
}
558
565
eventDeserializer .setChecksumType (checksumType );
559
566
}
@@ -567,7 +574,8 @@ private void listenForEventPackets() throws IOException {
567
574
int marker = inputStream .read ();
568
575
if (marker == 0xFF ) {
569
576
ErrorPacket errorPacket = new ErrorPacket (inputStream .read (packetLength - 1 ));
570
- throw new IOException (errorPacket .getErrorCode () + " - " + errorPacket .getErrorMessage ());
577
+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
578
+ errorPacket .getSqlState ());
571
579
}
572
580
Event event ;
573
581
try {
0 commit comments