Search in sources :

Example 1 with FeatureNotAvailableException

use of com.mysql.cj.exceptions.FeatureNotAvailableException in project ABC by RuiPinto96274.

the class NativeProtocol method negotiateSSLConnection.

/**
 * Negotiates the SSL communications channel used when connecting
 * to a MySQL server that understands SSL.
 */
@Override
public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), null);
    }
    long clientParam = this.serverSession.getClientParam();
    NativePacketPayload packet = new NativePacketPayload(SSL_REQUEST_LENGTH);
    packet.writeInteger(IntegerDataType.INT4, clientParam);
    packet.writeInteger(IntegerDataType.INT4, NativeConstants.MAX_PACKET_SIZE);
    packet.writeInteger(IntegerDataType.INT1, this.serverSession.getCharsetSettings().configurePreHandshake(false));
    // Set of bytes reserved for future use.
    packet.writeBytes(StringLengthDataType.STRING_FIXED, new byte[23]);
    send(packet, packet.getPosition());
    try {
        this.socketConnection.performTlsHandshake(this.serverSession, this.log);
        // i/o streams were replaced, build new packet sender/reader
        this.packetSender = new SimplePacketSender(this.socketConnection.getMysqlOutput());
        this.packetReader = new SimplePacketReader(this.socketConnection, this.maxAllowedPacket);
    } catch (FeatureNotAvailableException nae) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), nae);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
}
Also used : CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException)

Example 2 with FeatureNotAvailableException

use of com.mysql.cj.exceptions.FeatureNotAvailableException in project ABC by RuiPinto96274.

the class XProtocol method negotiateSSLConnection.

public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException();
    }
    if (!((XServerCapabilities) this.serverSession.getCapabilities()).hasCapability(XServerCapabilities.KEY_TLS)) {
        throw new CJCommunicationsException("A secure connection is required but the server is not configured with SSL.");
    }
    // the message reader is async and is always "reading". we need to stop it to use the socket for the TLS handshake
    this.reader.stopAfterNextMessage();
    Map<String, Object> tlsCapabilities = new HashMap<>();
    tlsCapabilities.put(XServerCapabilities.KEY_TLS, true);
    sendCapabilities(tlsCapabilities);
    try {
        this.socketConnection.performTlsHandshake(null, this.log);
    } catch (SSLParamsException | FeatureNotAvailableException | IOException e) {
        throw new CJCommunicationsException(e);
    }
    try {
        this.sender = new SyncMessageSender(this.socketConnection.getMysqlOutput());
        this.reader = new SyncMessageReader(this.socketConnection.getMysqlInput(), this);
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)

Example 3 with FeatureNotAvailableException

use of com.mysql.cj.exceptions.FeatureNotAvailableException in project ABC by RuiPinto96274.

the class CallableStatement method registerOutParameter.

@Override
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
    try {
        MysqlType mt = MysqlType.getByJdbcType(sqlType);
        registerOutParameter(parameterIndex, mt);
    } catch (FeatureNotAvailableException nae) {
        throw SQLError.createSQLFeatureNotSupportedException(Messages.getString("Statement.UnsupportedSQLType") + JDBCType.valueOf(sqlType), MysqlErrorNumbers.SQL_STATE_DRIVER_NOT_CAPABLE, getExceptionInterceptor());
    }
}
Also used : MysqlType(com.mysql.cj.MysqlType) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException)

Example 4 with FeatureNotAvailableException

use of com.mysql.cj.exceptions.FeatureNotAvailableException in project JavaSegundasQuintas by ecteruel.

the class NativeProtocol method negotiateSSLConnection.

/**
 * Negotiates the SSL communications channel used when connecting
 * to a MySQL server that understands SSL.
 */
@Override
public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), null);
    }
    long clientParam = this.serverSession.getClientParam();
    NativePacketPayload packet = new NativePacketPayload(SSL_REQUEST_LENGTH);
    packet.writeInteger(IntegerDataType.INT4, clientParam);
    packet.writeInteger(IntegerDataType.INT4, NativeConstants.MAX_PACKET_SIZE);
    packet.writeInteger(IntegerDataType.INT1, this.serverSession.getCharsetSettings().configurePreHandshake(false));
    // Set of bytes reserved for future use.
    packet.writeBytes(StringLengthDataType.STRING_FIXED, new byte[23]);
    send(packet, packet.getPosition());
    try {
        this.socketConnection.performTlsHandshake(this.serverSession, this.log);
        // i/o streams were replaced, build new packet sender/reader
        this.packetSender = new SimplePacketSender(this.socketConnection.getMysqlOutput());
        this.packetReader = new SimplePacketReader(this.socketConnection, this.maxAllowedPacket);
    } catch (FeatureNotAvailableException nae) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), nae);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
}
Also used : CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException)

Example 5 with FeatureNotAvailableException

use of com.mysql.cj.exceptions.FeatureNotAvailableException in project JavaSegundasQuintas by ecteruel.

the class SessionTest method sqlUpdate.

@Test
public void sqlUpdate() {
    SqlStatement stmt = this.session.sql("set @cjTestVar = 1");
    SqlResult res = stmt.execute();
    assertFalse(res.hasData());
    assertEquals(0, res.getAffectedItemsCount());
    assertEquals(null, res.getAutoIncrementValue());
    assertEquals(0, res.getWarningsCount());
    assertFalse(res.getWarnings().hasNext());
    // TODO SqlUpdateResult throws FeatureNotAvailableException("Not a multi-result");
    // res.nextResult();
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.fetchAll();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.next();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.hasNext();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.getColumnCount();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.getColumns();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.getColumnNames();
            return null;
        }
    });
    assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {

        public Void call() throws Exception {
            res.count();
            return null;
        }
    });
}
Also used : SqlStatement(com.mysql.cj.xdevapi.SqlStatement) SqlResult(com.mysql.cj.xdevapi.SqlResult) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) FileNotFoundException(java.io.FileNotFoundException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) ExecutionException(java.util.concurrent.ExecutionException) CJPacketTooBigException(com.mysql.cj.exceptions.CJPacketTooBigException) Test(org.junit.jupiter.api.Test)

Aggregations

FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)18 MysqlType (com.mysql.cj.MysqlType)9 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)6 CJConnectionFeatureNotAvailableException (com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)6 IOException (java.io.IOException)6 CJPacketTooBigException (com.mysql.cj.exceptions.CJPacketTooBigException)3 SSLParamsException (com.mysql.cj.exceptions.SSLParamsException)3 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)3 SqlResult (com.mysql.cj.xdevapi.SqlResult)3 SqlStatement (com.mysql.cj.xdevapi.SqlStatement)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.jupiter.api.Test)3