Search in sources :

Example 1 with UnknownCharsetException

use of com.alibaba.cobar.exception.UnknownCharsetException in project cobar by alibaba.

the class MySQLChannel method handshake.

private MySQLChannel handshake() throws IOException {
    // 读取握手数据包
    BinaryPacket initPacket = new BinaryPacket();
    initPacket.read(in);
    HandshakePacket hsp = new HandshakePacket();
    hsp.read(initPacket);
    // 设置通道参数
    this.threadId = hsp.threadId;
    int ci = hsp.serverCharsetIndex & 0xff;
    if ((dbCharset = CharsetUtil.getDbCharset(ci)) != null) {
        this.charsetIndex = ci;
        this.charset = CharsetUtil.getCharset(ci);
    } else {
        throw new UnknownCharsetException("charset:" + ci);
    }
    // 发送认证数据包
    BinaryPacket bin = null;
    try {
        bin = sendAuth411(hsp);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            afterSuccess();
            break;
        case ErrorPacket.FIELD_COUNT:
            ErrorPacket err = new ErrorPacket();
            err.read(bin);
            throw new ErrorPacketException(new String(err.message, charset));
        case EOFPacket.FIELD_COUNT:
            auth323(bin.packetId, hsp.seed);
            break;
        default:
            throw new UnknownPacketException(bin.toString());
    }
    return this;
}
Also used : HandshakePacket(com.alibaba.cobar.net.mysql.HandshakePacket) ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ErrorPacketException(com.alibaba.cobar.exception.ErrorPacketException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException) UnknownCharsetException(com.alibaba.cobar.exception.UnknownCharsetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Aggregations

ErrorPacketException (com.alibaba.cobar.exception.ErrorPacketException)1 UnknownCharsetException (com.alibaba.cobar.exception.UnknownCharsetException)1 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)1 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)1 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)1 HandshakePacket (com.alibaba.cobar.net.mysql.HandshakePacket)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1