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);
}
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();
}
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
}
}
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);
}
}
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());
}
}
Aggregations