Search in sources :

Example 1 with SSHTunnelImpl

use of org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl in project dbeaver by serge-rider.

the class SSHTunnelConfiguratorUI method testTunnelConnection.

private void testTunnelConnection() {
    DBWHandlerConfiguration configuration = new DBWHandlerConfiguration(savedConfiguration);
    configuration.setProperties(Collections.emptyMap());
    saveSettings(configuration);
    DBPDataSourceContainer dataSource = configuration.getDataSource();
    if (dataSource != null) {
        configuration.resolveDynamicVariables(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
    } else {
        configuration.resolveDynamicVariables(SystemVariablesResolver.INSTANCE);
    }
    try {
        final String[] tunnelVersions = new String[2];
        UIUtils.runInProgressDialog(monitor -> {
            monitor.beginTask("Instantiate SSH tunnel", 2);
            SSHTunnelImpl tunnel = new SSHTunnelImpl();
            DBPConnectionConfiguration connectionConfig = new DBPConnectionConfiguration();
            connectionConfig.setHostName("localhost");
            connectionConfig.setHostPort(configuration.getStringProperty(DBWHandlerConfiguration.PROP_PORT));
            try {
                monitor.subTask("Initialize tunnel");
                tunnel.initializeHandler(monitor, DBWorkbench.getPlatform(), configuration, connectionConfig);
                monitor.worked(1);
                // Get info
                tunnelVersions[0] = tunnel.getImplementation().getClientVersion();
                tunnelVersions[1] = tunnel.getImplementation().getServerVersion();
                // Close it
                monitor.subTask("Close tunnel");
                tunnel.closeTunnel(monitor);
                monitor.worked(1);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        });
        MessageDialog.openInformation(hostText.getShell(), ModelMessages.dialog_connection_wizard_start_connection_monitor_success, "Connected!\n\nClient version: " + tunnelVersions[0] + "\nServer version: " + tunnelVersions[1]);
    } catch (InvocationTargetException ex) {
        DBWorkbench.getPlatformUI().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SSHTunnelImpl(org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SSHTunnelImpl

use of org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl in project dbeaver by dbeaver.

the class SSHTunnelConfiguratorUI method testTunnelConnection.

private void testTunnelConnection() {
    DBWHandlerConfiguration configuration = new DBWHandlerConfiguration(savedConfiguration);
    configuration.setProperties(Collections.emptyMap());
    saveSettings(configuration);
    DBPDataSourceContainer dataSource = configuration.getDataSource();
    if (dataSource != null) {
        configuration.resolveDynamicVariables(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
    } else {
        configuration.resolveDynamicVariables(SystemVariablesResolver.INSTANCE);
    }
    try {
        final String[] tunnelVersions = new String[2];
        UIUtils.runInProgressDialog(monitor -> {
            monitor.beginTask("Instantiate SSH tunnel", 2);
            SSHTunnelImpl tunnel = new SSHTunnelImpl();
            DBPConnectionConfiguration connectionConfig = new DBPConnectionConfiguration();
            connectionConfig.setHostName("localhost");
            connectionConfig.setHostPort(configuration.getStringProperty(DBWHandlerConfiguration.PROP_PORT));
            try {
                monitor.subTask("Initialize tunnel");
                tunnel.initializeHandler(monitor, DBWorkbench.getPlatform(), configuration, connectionConfig);
                monitor.worked(1);
                // Get info
                tunnelVersions[0] = tunnel.getImplementation().getClientVersion();
                tunnelVersions[1] = tunnel.getImplementation().getServerVersion();
                // Close it
                monitor.subTask("Close tunnel");
                tunnel.closeTunnel(monitor);
                monitor.worked(1);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        });
        MessageDialog.openInformation(hostText.getShell(), ModelMessages.dialog_connection_wizard_start_connection_monitor_success, "Connected!\n\nClient version: " + tunnelVersions[0] + "\nServer version: " + tunnelVersions[1]);
    } catch (InvocationTargetException ex) {
        DBWorkbench.getPlatformUI().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SSHTunnelImpl(org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 DataSourceVariableResolver (org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)2 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)2 SSHTunnelImpl (org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl)2