Search in sources :

Example 1 with FullReadInputStream

use of com.mysql.cj.protocol.FullReadInputStream in project ABC by RuiPinto96274.

the class NativeProtocol method afterHandshake.

@Override
public void afterHandshake() {
    checkTransactionState();
    try {
        // 
        if (((this.serverSession.getCapabilities().getCapabilityFlags() & NativeServerSession.CLIENT_COMPRESS) != 0) && this.propertySet.getBooleanProperty(PropertyKey.useCompression).getValue() && !(this.socketConnection.getMysqlInput().getUnderlyingStream() instanceof CompressedInputStream)) {
            this.useCompression = true;
            this.socketConnection.setMysqlInput(new FullReadInputStream(new CompressedInputStream(this.socketConnection.getMysqlInput(), this.propertySet.getBooleanProperty(PropertyKey.traceProtocol), this.log)));
            this.compressedPacketSender = new CompressedPacketSender(this.socketConnection.getMysqlOutput());
            this.packetSender = this.compressedPacketSender;
        }
        applyPacketDecorators(this.packetSender, this.packetReader);
        this.socketConnection.getSocketFactory().afterHandshake();
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
    // Changing defaults for 8.0.3+ server: PNAME_useInformationSchema=true
    RuntimeProperty<Boolean> useInformationSchema = this.propertySet.<Boolean>getProperty(PropertyKey.useInformationSchema);
    if (versionMeetsMinimum(8, 0, 3) && !useInformationSchema.getValue() && !useInformationSchema.isExplicitlySet()) {
        useInformationSchema.setValue(true);
    }
    // listen for properties changes to allow decorators reconfiguration
    this.maintainTimeStats.addListener(this);
    this.propertySet.getBooleanProperty(PropertyKey.traceProtocol).addListener(this);
    this.propertySet.getBooleanProperty(PropertyKey.enablePacketDebug).addListener(this);
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) IOException(java.io.IOException)

Example 2 with FullReadInputStream

use of com.mysql.cj.protocol.FullReadInputStream in project ABC by RuiPinto96274.

the class NativeSocketConnection method performTlsHandshake.

@Override
public void performTlsHandshake(ServerSession serverSession, Log log) throws SSLParamsException, FeatureNotAvailableException, IOException {
    this.mysqlSocket = this.socketFactory.performTlsHandshake(this, serverSession, log);
    this.mysqlInput = new FullReadInputStream(this.propertySet.getBooleanProperty(PropertyKey.useUnbufferedInput).getValue() ? getMysqlSocket().getInputStream() : new BufferedInputStream(getMysqlSocket().getInputStream(), 16384));
    this.mysqlOutput = new BufferedOutputStream(getMysqlSocket().getOutputStream(), 16384);
    this.mysqlOutput.flush();
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with FullReadInputStream

use of com.mysql.cj.protocol.FullReadInputStream in project ABC by RuiPinto96274.

the class SyncMessageReaderTest method testSeveralMessages.

/**
 * This is a 'mini'-stress test that encompasses the check of <i>clearHeader()</i> being called correctly.
 *
 * @throws IOException
 */
@Test
public void testSeveralMessages() throws IOException {
    // construct the test message stream
    // message stream is: Error, Error, Error, Ok, Error, Ok, Error
    // if the header is not cleared properly, the second Error would be read incorrectly
    ByteArrayOutputStream x = new ByteArrayOutputStream();
    x.write(errMsgPacket);
    x.write(errMsgPacket);
    x.write(errMsgPacket);
    x.write(okMsgPacket);
    x.write(errMsgPacket);
    x.write(okMsgPacket);
    x.write(errMsgPacket);
    this.reader = new SyncMessageReader(new FullReadInputStream(new ByteArrayInputStream(x.toByteArray())), null);
    // read first three errors "unexpectedly" in a loop
    for (int i = 0; i < 3; ++i) {
        try {
            this.reader.readMessage(null, ServerMessages.Type.OK_VALUE);
        } catch (XProtocolError err) {
            assertEquals(5432, err.getErrorCode());
        }
    }
    // read remaining messages normally
    this.reader.readMessage(null, ServerMessages.Type.OK_VALUE);
    try {
        this.reader.readMessage(null, ServerMessages.Type.ERROR_VALUE);
    } catch (XProtocolError err) {
    // expected
    }
    this.reader.readMessage(null, ServerMessages.Type.OK_VALUE);
    try {
        this.reader.readMessage(null, ServerMessages.Type.ERROR_VALUE);
    } catch (XProtocolError err) {
    // expected
    }
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 4 with FullReadInputStream

use of com.mysql.cj.protocol.FullReadInputStream in project ABC by RuiPinto96274.

the class SyncMessageReaderTest method testReadKnownMessageType.

@Test
public void testReadKnownMessageType() {
    try {
        this.reader = new SyncMessageReader(new FullReadInputStream(new ByteArrayInputStream(okMsgPacket)), null);
        Ok msg = (Ok) this.reader.readMessage(null, ServerMessages.Type.OK_VALUE).getMessage();
        assertTrue(msg.isInitialized());
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Ok(com.mysql.cj.x.protobuf.Mysqlx.Ok) Test(org.junit.jupiter.api.Test)

Example 5 with FullReadInputStream

use of com.mysql.cj.protocol.FullReadInputStream in project ABC by RuiPinto96274.

the class SyncMessageReaderTest method testUnexpectedError.

@Test
public void testUnexpectedError() {
    this.reader = new SyncMessageReader(new FullReadInputStream(new ByteArrayInputStream(errMsgPacket)), null);
    try {
        // attempt to read an Ok packet
        this.reader.readMessage(null, ServerMessages.Type.OK_VALUE);
        fail("Should not be able to read the OK packet");
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    } catch (XProtocolError ex) {
        // check that the exception contains the error info from the server
        assertEquals("ERROR 5432 (12S34) oops", ex.getMessage());
        assertEquals("12S34", ex.getSQLState());
        assertEquals(5432, ex.getErrorCode());
    }
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

FullReadInputStream (com.mysql.cj.protocol.FullReadInputStream)24 ByteArrayInputStream (java.io.ByteArrayInputStream)15 IOException (java.io.IOException)15 Test (org.junit.jupiter.api.Test)15 BufferedInputStream (java.io.BufferedInputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)6 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)3 SSLParamsException (com.mysql.cj.exceptions.SSLParamsException)3 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)3 PacketSentTimeHolder (com.mysql.cj.protocol.PacketSentTimeHolder)3 ReadAheadInputStream (com.mysql.cj.protocol.ReadAheadInputStream)3 Error (com.mysql.cj.x.protobuf.Mysqlx.Error)3 Ok (com.mysql.cj.x.protobuf.Mysqlx.Ok)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3